Skip to content

Prompt caching with Batch API ? #553

Description

@clonecorp

Hey there,

I see I get a system.0.cache_control: Extra inputs are not permitted or messages.0.cache_control: Extra inputs are not permitted when trying to use the cache_control with the Batch API. Is this by design? Looking at the docs I should be able to: https://docs.anthropic.com/en/docs/build-with-claude/message-batches#can-i-use-the-message-batches-api-in-conjunction-with-other-betas

My code:

await anthropic.beta.messages.batches.create({
  requests: [
    {
      custom_id: some_id,
      params: {
        betas: ['prompt-caching-2024-07-31', 'message-batches-2024-09-24'],
        model: 'claude-3-5-sonnet-20240620',
        max_tokens: 100,
        system: [
          {
            text: very_long_text,
            type: 'text',
            cache_control: {
              type: 'ephemeral'
            }
          }
        ],
        messages: [
          {
            role: 'user',
            content: 'What is this very long text?',
          }
        ]
      }
    },
  ]
})

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