> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompt Caching on Bedrock

Prompt caching on Amazon Bedrock lets you cache specific portions of your requests for repeated use. This feature significantly reduces inference response latency and input token costs by allowing the model to skip recomputation of previously processed content.

With Prisma AIRS AI Gateway, you can easily implement Amazon Bedrock's prompt caching through our OpenAI-compliant unified API and prompt templates.

## Model Support

Amazon Bedrock prompt caching is generally available with the following models:

<Info>
  **Currently Supported Models:**

  * Claude Opus 4.6
  * Claude Opus 4.5
  * Claude Opus 4
  * Claude Sonnet 4.6
  * Claude Sonnet 4.5
  * Claude Haiku 4.5
  * Claude 3.5 Haiku
  * Claude 3.7 Sonnet
  * Claude 3.5 Sonnet v2 (Preview)
  * Amazon Nova Micro, Lite, Pro (automatic caching)
</Info>

## How Bedrock Prompt Caching Works

When using prompt caching, you define **cache checkpoints** - markers that indicate parts of your prompt to cache. These cached sections must be static between requests; any alterations will result in a cache miss.

<Note>
  You can also use Bedrock Prompt Caching Feature with the AI Gateway's Prompt Templates.
</Note>

## Implementation Examples

Here's how to implement prompt caching with the AI Gateway:

<CodeGroup>
  ```sh REST API theme={"system"}
  curl https://aigw.portkey.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "x-portkey-provider: $BEDROCK_PROVIDER" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -d '{
      "model": "anthropic.claude-3-7-sonnet-20250219-v1:0",
      "messages": [
          { "role": "system", "content": [
              {
                  "type":"text","text":"You are a helpful assistant"
              },
              {
                  "type":"text","text":"This is a large document I want to cache...",
                  "cache_control": {"type": "ephemeral"}
              }
          ]},
          { "role": "user", "content": "Summarize the above document for me in 20 words" }
      ]
    }'
  ```

  ```javascript OpenAI NodeJS theme={"system"}
  import OpenAI from "openai";

  const openai = new OpenAI({
      apiKey: "PORTKEY_API_KEY",
      baseURL: "https://aigw.portkey.ai/v1",
  });

  const chatCompletion = await openai.chat.completions.create({
      messages: [
          { "role": 'system', "content": [
              {
                  "type":"text","text":"You are a helpful assistant"
              },
              {
                  "type":"text","text":"This is a large document I want to cache...",
                  "cache_control": {"type": "ephemeral"}
              }
          ]},
          { "role": 'user', "content": 'Summarize the above document for me in 20 words' }
      ],
      model: '@bedrock/anthropic.claude-3-7-sonnet-20250219-v1:0',
  });

  console.log(chatCompletion.choices[0].message.content);
  ```

  ```python OpenAI Python theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      api_key="PORTKEY_API_KEY",
      base_url="https://aigw.portkey.ai/v1",
  )

  chat_completion = client.chat.completions.create(
      messages= [
          { "role": 'system', "content": [
              {
                  "type":"text","text":"You are a helpful assistant"
              },
              {
                  "type":"text","text":"This is a large document I want to cache...",
                  "cache_control": {"type": "ephemeral"}
              }
          ]},
          { "role": 'user', "content": 'Summarize the above document in 20 words' }
      ],
      model= '@bedrock/anthropic.claude-3-7-sonnet-20250219-v1:0',
  )

  print(chat_completion.choices[0].message.content)
  ```
</CodeGroup>

## Cache TTL Options

By default, cache checkpoints use the standard TTL. You can optionally specify a TTL by adding the `ttl` field to `cache_control`:

```json theme={"system"}
{
  "cache_control": { "type": "ephemeral", "ttl": "1h" }
}
```

Supported TTL values are `"5m"` (5 minutes) and `"1h"` (1 hour). The TTL is forwarded to Bedrock's `cachePoint` configuration.

## Supported Features and Limitations

<Info>
  **Supported Features**

  * Text prompts and images embedded within text prompts
  * Multiple cache checkpoints per request
  * Caching in system prompts, messages, and tools fields (model-dependent)
  * Configurable TTL (`5m` or `1h`) per cache checkpoint
</Info>

### Supported Models and Limits

Below is a detailed table of supported models, their minimum token requirements, maximum cache checkpoints, and fields that support caching:

| Model                | Model ID                                  | Min tokens | Max checkpoints | Supported TTL | Cacheable fields        |
| -------------------- | ----------------------------------------- | ---------- | --------------- | ------------- | ----------------------- |
| Claude Opus 4.6      | anthropic.claude-opus-4-6-v1              | 4,096      | 4               | 5 min         | system, messages, tools |
| Claude Opus 4.5      | anthropic.claude-opus-4-5-20251101-v1:0   | 4,096      | 4               | 5 min, 1 hour | system, messages, tools |
| Claude Opus 4        | anthropic.claude-opus-4-20250514-v1:0     | 1,024      | 4               | 5 min         | system, messages, tools |
| Claude Sonnet 4.6    | anthropic.claude-sonnet-4-6               | 1,024      | 4               | 5 min         | system, messages, tools |
| Claude Sonnet 4.5    | anthropic.claude-sonnet-4-5-20250929-v1:0 | 4,096      | 4               | 5 min, 1 hour | system, messages, tools |
| Claude Haiku 4.5     | anthropic.claude-haiku-4-5-20251001-v1:0  | 4,096      | 4               | 5 min, 1 hour | system, messages, tools |
| Claude 3.5 Haiku     | anthropic.claude-3-5-haiku-20241022-v1:0  | 2,048      | 4               | 5 min         | system, messages, tools |
| Claude 3.7 Sonnet    | anthropic.claude-3-7-sonnet-20250219-v1:0 | 1,024      | 4               | 5 min         | system, messages, tools |
| Claude 3.5 Sonnet v2 | anthropic.claude-3-5-sonnet-20241022-v2:0 | 1,024      | 4               | 5 min         | system, messages, tools |
| Amazon Nova Micro    | amazon.nova-micro-v1:0                    | 1,000      | 4               | 5 min         | system, messages        |
| Amazon Nova Lite     | amazon.nova-lite-v1:0                     | 1,000      | 4               | 5 min         | system, messages        |
| Amazon Nova Pro      | amazon.nova-pro-v1:0                      | 1,000      | 4               | 5 min         | system, messages        |

<Note>
  * **Extended TTL:** Claude Opus 4.5, Claude Sonnet 4.5, and Claude Haiku 4.5 support both 5-minute and 1-hour TTL options.
  * The Amazon Nova models support a maximum of 20K tokens for prompt caching. Prompt caching is primarily for text prompts. They also support automatic prompt caching for all text prompts without explicit configuration.
  * For Claude models, tools caching is fully supported.
  * Tools caching is not supported for Amazon Nova models.
  * Claude 3.5 Sonnet v2 is in Preview status.
</Note>

## Understanding Token Counts and Pricing

The AI Gateway automatically calculates correct pricing for prompt caching requests. In the logs, you'll see cache-related token counts in the `usage` object:

* `cache_creation_input_tokens`: Number of tokens written to the cache when creating a new entry.
* `cache_read_input_tokens`: Number of tokens retrieved from the cache for this request.

<Info>
  **Token Format Normalization**

  The AI Gateway normalizes responses to the OpenAI format. In this format, `prompt_tokens` **includes** the cached tokens:

  ```
  prompt_tokens = inputTokens + cache_read_input_tokens + cache_creation_input_tokens
  ```

  This differs from native provider formats where input tokens may exclude cached tokens. The AI Gateway's pricing calculation accounts for this by:

  1. Subtracting cached tokens from `prompt_tokens` to get the base input token count
  2. Applying the standard input token rate to base tokens
  3. Applying the discounted cache read rate to `cache_read_input_tokens`
  4. Applying the cache write rate to `cache_creation_input_tokens`

  This ensures accurate cost calculation even though the token format is normalized.
</Info>

## Related Resources

<Card title="AWS Bedrock Prompt Caching Docs" href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html">
  For more detailed information on Bedrock prompt caching, refer to:
</Card>


## Related topics

- [Enterprise Gateway](/docs/aigw/changelog/enterprise.md)
- [Prompt Caching](/docs/aigw/integrations/llms/anthropic/prompt-caching.md)
- [AWS Bedrock](/docs/aigw/integrations/llms/bedrock/aws-bedrock.md)
- [Anthropic](/docs/aigw/integrations/llms/anthropic.md)
