Skip to content

Fix: Update prompt caching to use standard API endpoint#178

Open
jun229 wants to merge 6 commits into
anthropics:mainfrom
jun229:fix-prompt-caching-api
Open

Fix: Update prompt caching to use standard API endpoint#178
jun229 wants to merge 6 commits into
anthropics:mainfrom
jun229:fix-prompt-caching-api

Conversation

@jun229

@jun229 jun229 commented Jul 17, 2025

Copy link
Copy Markdown

Problem

The prompt caching example in [contextual-embeddings/guide.ipynb] uses deprecated API syntax that causes errors:

# This fails with AttributeError: 'Beta' object has no attribute 'prompt_caching'
client.beta.prompt_caching.messages.create(...)

Solution

Updated to use the current standard API endpoint for prompt caching:

client.messages.create(
    ...,
    extra_headers={"anthropic-beta": "prompt-caching-2024-07-31"}
)

Changes Made

  • Replaced client.beta.prompt_caching.messages.create() with client.messages.create()
  • Kept the required extra_headers for prompt caching functionality

@PedramNavid

Copy link
Copy Markdown
Collaborator

Hi @jun229, thanks for contributing! You will also need to remove the extra_headers={"anthropic-beta": "prompt-caching-2024-07-31"} which as been deprecated. Would you be open to doing that and resubmitting? There are also some merge conflicts in this PR.

@PedramNavid PedramNavid added the pending Pending response from submitter label Oct 21, 2025
PedramNavid
PedramNavid previously approved these changes Oct 27, 2025
@PedramNavid

Copy link
Copy Markdown
Collaborator

hi @jun229 thanks for the PR. Looks like there are some conflicts before I can merge this one.

@jun229

jun229 commented Oct 27, 2025

Copy link
Copy Markdown
Author

Hi @PedramNavid, all merge conflicts have been resolved, and the deprecated extra_headers have been removed.

The PR should now be ready for review. Thanks again for your time!

@nidhishgajjar

Copy link
Copy Markdown

Orb Code Review (powered by GLM 5.1 on Orb Cloud)

Straightforward removal of the deprecated anthropic-beta: prompt-caching-2024-07-31 header from the contextual embeddings guide.

Analysis

Prompt caching is now generally available, so the beta header is no longer needed. The removal is done in both places where the header was used, and the surrounding code structure is preserved correctly.

Summary

Clean removal of a deprecated beta header. No issues.

Assessment: approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending Pending response from submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants