+
Skip to content

README includes outdated anthropic-beta header for prompt caching #175

@gulbaki

Description

@gulbaki

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载