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

# Prompt caching: pay at least 10× less for repeated context

> How prompt caching works on RuAPI: Claude over the native Anthropic API and the OpenAI-compatible format (cache_control), automatic caching for GPT and DeepSeek, pricing, and how to check cache hits.

Coding agents and chatbots send the model the same context over and over: the system prompt, project files, the conversation history. In agent workloads that's typically 80–97% of all input tokens. Prompt caching means you no longer pay full price for that repeated context: the model remembers the start of the request it has already processed, and reading it back from the cache costs at least 10× less than regular input.

## What RuAPI gives you

* **Claude over the native Anthropic API — just like Anthropic.** Requests to `https://www.ruapi.ai/v1/messages` are passed through with their `cache_control` markers unchanged, `ttl` included. Claude Code, the Anthropic SDK and agents set to the Anthropic provider get caching with no extra setup.
* **Claude over the OpenAI-compatible format — cached too.** RuAPI passes `cache_control` markers on message blocks through to Claude and understands a single top-level marker (automatic caching), using the same syntax as OpenRouter. Anthropic's own OpenAI-compatible layer doesn't support caching.
* **GPT and DeepSeek — automatic.** The cache kicks in by itself when the start of a request repeats; there's nothing to configure.
* **Transparent usage.** The API response shows how many tokens were read from and written to the cache, and the console shows the same for every request.
* **No VPN, no foreign-issued card.** RuAPI is reachable from Russia directly, and you top up in USDT.

## Pricing

| What | Price |
| - | - |
| Cache read (Claude) | at least 10× cheaper than regular input |
| 5-minute cache write (Claude) | 1.25 × the input price |
| 1-hour cache write (Claude) | 2 × the input price |
| Output | regular price: output isn't cached |

See the exact rates for every model on the [pricing page](https://www.ruapi.ai/pricing?lng=en\&utm_source=docs\&utm_campaign=en-prompt-caching). A cache write costs a little more than regular input, so caching pays off as soon as the same context is sent a second time within the cache lifetime. Every hit extends the cache by another 5 minutes (or an hour).

## Claude: how to turn caching on

### Which format are you using?

One RuAPI key works with Claude in two formats: the native Anthropic format and the OpenAI-compatible format. How caching is turned on depends on which one you use. If you're not sure, check any of these:

| Where to look | OpenAI-compatible format | Native Anthropic format |
| - | - | - |
| Console **Usage Logs**: open an entry and look at "Request path" | `/v1/chat/completions` | `/v1/messages` |
| The provider picked in your tool | OpenAI, OpenAI Compatible or Custom OpenAI | Anthropic or Claude |
| Your own code | the `openai` library | the `anthropic` library |

Claude Code always uses the native Anthropic format and sets the cache markers itself, so there's nothing to check. In the OpenAI-compatible format, caching only works when the request carries `cache_control` markers. For all the differences between the two formats, see [OpenAI or Anthropic format](/en/openai-vs-anthropic-format).

### Claude Code and coding agents

| Tool | What to do |
| - | - |
| [Claude Code](/en/integrations/claude-code) | Nothing: Claude Code sets the cache markers itself |
| [Cline](/en/integrations/cline), [Roo Code](/en/integrations/roo-code) | Pick the **Anthropic** provider with `https://www.ruapi.ai` |
| [Kilo Code](/en/integrations/kilo-code) | The **Anthropic Messages** provider with `https://www.ruapi.ai/v1` |
| [Continue](/en/integrations/continue) | `provider: anthropic` and `promptCaching: true` |
| [OpenCode](/en/integrations/opencode) | The built-in `anthropic` provider with `https://www.ruapi.ai/v1` |

<Tip>
  If an agent uses the **OpenAI Compatible** provider for Claude, caching only works when the agent itself sets `cache_control` markers. Most agents don't in that mode, so the Anthropic provider is the safer choice for Claude.
</Tip>

### Your own app: Anthropic SDK

Put a `cache_control` marker on the last block of the part of the request that doesn't change — for example, a long system prompt. Everything before the marker goes into the cache.

```python theme={null}
import anthropic

client = anthropic.Anthropic(base_url="https://www.ruapi.ai", api_key="sk-...")

response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": LONG_SYSTEM_PROMPT,  # instructions, docs, project code
            "cache_control": {"type": "ephemeral"},
        }
    ],
    messages=[{"role": "user", "content": "Your question"}],
)
print(response.usage.cache_read_input_tokens, response.usage.cache_creation_input_tokens)
```

To keep the cache for an hour instead of 5 minutes, use `"cache_control": {"type": "ephemeral", "ttl": "1h"}`.

### Your own app: OpenAI SDK

In the OpenAI-compatible format the marker goes on a block in `content`, so a message that carries a marker has to send its content as a list of blocks rather than a string.

```python theme={null}
from openai import OpenAI

client = OpenAI(base_url="https://www.ruapi.ai/v1", api_key="sk-...")

response = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[
        {
            "role": "system",
            "content": [
                {
                    "type": "text",
                    "text": LONG_SYSTEM_PROMPT,
                    "cache_control": {"type": "ephemeral"},
                }
            ],
        },
        {"role": "user", "content": "Your question"},
    ],
)
print(response.usage.prompt_tokens_details.cached_tokens)
```

You can also get by with a single top-level `cache_control` marker — Anthropic calls this automatic caching. In that case RuAPI places the marker on the last block of the last message itself, just as Anthropic does, so this option works on all of our Claude channels. With each new message the marker moves forward, and the whole earlier conversation lands in the cache.

<Note>
  A request can carry at most 4 markers. A request start that's too short isn't cached; the minimum length depends on the model — for example, 512 tokens for Claude Sonnet 5.5 and Claude Opus 5.5.
</Note>

## GPT and DeepSeek: caching is automatic

* **GPT.** If the first 1,024 or more tokens of a request match a recent request, the matching part is read from the cache. No markers needed.
* **DeepSeek.** Caching is always on: a repeated request start is billed at the cache-hit price.

To get more cache hits, keep the part that doesn't change — the system prompt, instructions, tool definitions — at the start of the request, and everything that changes at the end.

## How to check that the cache worked

| Format | Read from cache | Written to cache |
| - | - | - |
| Anthropic (`/v1/messages`) | `usage.cache_read_input_tokens` | `usage.cache_creation_input_tokens` |
| OpenAI (`/v1/chat/completions`) | `usage.prompt_tokens_details.cached_tokens` | `usage.prompt_tokens_details.cached_creation_tokens` (Claude) |

In the OpenAI format, `prompt_tokens` already includes the cached tokens, just as with OpenAI. The console shows the same for every request: **Usage Logs** → open an entry.

## Comparison

| | RuAPI | Anthropic directly | OpenRouter |
| - | - | - | - |
| Access from Russia without a VPN | Yes | No: Russia isn't a supported country | No: 403 error from Russian IPs |
| Claude caching over the native Anthropic API | Yes | Yes | Yes |
| Claude caching over the OpenAI-compatible format | Yes: `cache_control` markers on blocks and at the top level | No: the OpenAI-compatible layer doesn't support caching | Yes: markers on blocks; top-level only when routed to Anthropic itself |
| Payment | USDT, foreign-issued cards | Card | Card, USDC |

Information about other services is based on the [Anthropic](https://docs.anthropic.com/en/api/openai-sdk) and [OpenRouter](https://openrouter.ai/docs/features/prompt-caching) documentation (checked Oct 15, 2026); the OpenRouter 403 error is from our own check on Sep 30, 2026.

## FAQ

<AccordionGroup>
  <Accordion title="Why isn't the cache working?">
    * The start of the request changed. Even one character before the marker — the current time, a random ID — means a new prefix and a new cache write.
    * The start of the request is too short for this model.
    * More than 5 minutes passed without requests (or an hour with `"ttl": "1h"`).
    * Claude is called in the OpenAI-compatible format without `cache_control` markers.
  </Accordion>

  <Accordion title="Claude is draining my balance fast — what should I check?">
    Most likely the cache isn't working, so the whole repeated context is billed at full price every time.

    1. Find out which format you use: open a Claude entry in the console's **Usage Logs** and look at "Request path". `/v1/messages` is the native Anthropic format: caching works just as with Anthropic (Claude Code sets the markers itself), and the usual reasons for misses are in the previous question. `/v1/chat/completions` is the OpenAI-compatible format: go through the steps below. Other ways to tell the format are in "Which format are you using?" above.
    2. Check whether the cache works: if the entry details show a "Cache Tokens" line, the cache was hit; if repeated requests never show it, caching isn't working. In your own code, the same number is in `usage.prompt_tokens_details.cached_tokens` in the API response.
    3. Check whether your client sets `cache_control` markers: without them Claude doesn't cache anything. Many agents don't set markers in **OpenAI Compatible** mode, so pick the Anthropic provider there. In your own code, a single top-level `cache_control` marker is enough.
    4. If you go through another gateway, check its documentation for Claude caching in the OpenAI-compatible format specifically. Not every gateway has it: Anthropic's own OpenAI-compatible layer doesn't support caching, and APIYI's documentation, for example, says the Claude cache discount only applies in the native Anthropic format (checked Oct 15, 2026). On RuAPI, Claude caching works in both formats.
  </Accordion>

  <Accordion title="Does caching cost extra?">
    A cache write costs 1.25× the regular input price (2× for the one-hour cache), but every read after that is at least 10× cheaper. If the context is sent at least twice, you're already saving.
  </Accordion>

  <Accordion title="Do I need to turn anything on in the RuAPI console?">
    No. Caching works for any key: for Claude, `cache_control` markers are enough (Claude Code sets them itself), and for GPT and DeepSeek the cache is automatic.
  </Accordion>
</AccordionGroup>

## Next steps

* [Claude Code](/en/integrations/claude-code): set it up with caching out of the box.
* [Pricing](/en/pricing): how caching affects what you pay.
* [DeepSeek vs Claude: what one day of work actually costs](/en/deepseek-vs-claude): a real bill with caching, broken down.
* [How to cut your Claude Code and Cline bill](/en/claude-code-cline-costs): what breaks the cache and how to keep the context short.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.