-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
The current documentation (in the cookbook ) https://github.com/anthropics/anthropic-cookbook/blob/main/misc/prompt_caching.ipynb still includes the following line when demonstrating prompt caching:
extra_headers = {"anthropic-beta": "prompt-caching-2024-07-31"}
However, as of now, this header is no longer required. Prompt caching is fully supported through the standard API by just using the cache_control field directly inside the prompt.
For example, the following works fine without any extra headers:
response = client.messages.create(
model="claude-opus-4-20250514",
max_tokens=1024,
system=[
{
"type": "text",
"text": "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n",
},
{
"type": "text",
"text": "<the entire contents of 'Pride and Prejudice'>",
"cache_control": {"type": "ephemeral"}
}
],
messages=[{"role": "user", "content": "Analyze the major themes in 'Pride and Prejudice'."}],
)
It would be great to update the examples and remove the obsolete beta header to prevent confusion for users using the latest SDK.
Metadata
Metadata
Assignees
Labels
No labels