# Prompt caching

Page: https://galatea.co/api/docs/prompt-caching

Repeated prompt prefixes are served from the cache of the host that answers, and billed at the cached input price.

The host that answers keeps the attention state of prompts it has seen. When a new request starts with the same tokens, those tokens are a cache hit: they are not recomputed, and they are billed at the cached input price, which is lower than the uncached input price.

## How to get cache hits

- Put the stable part first: the system prompt, tool definitions and any fixed examples.
- Put the part that changes last: the user's question or the new document.
- Send the same prefix again within the cache's lifetime. Cache entries expire when the host needs the memory.
- Keep the prefix byte-for-byte identical. A changed timestamp at the top of a system prompt breaks every hit after it.

```python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.galatea.co/v1", api_key=os.environ["GALATEA_API_KEY"])
system = "You are a support agent for a solar company. " * 200  # the stable prefix goes first
for question in ["What is the warranty?", "How do I reset the inverter?"]:
    reply = client.chat.completions.create(
        model="deepseek-v4.1-flash-1017-uncensored",
        messages=[{"role": "system", "content": system}, {"role": "user", "content": question}],
        max_tokens=64,
    )
    usage = reply.usage
    print("prompt", usage.prompt_tokens, "cached", usage.prompt_tokens_details.cached_tokens)
```

## How to read them

Every usage block shows prompt_tokens and prompt_tokens_details.cached_tokens. The cached count is the part of the prompt that was a hit. The Activity page shows the cached input tokens for each request, next to its cost.

Cached input tokens are a separate line on your bill, at the cached price listed on the model page. Cache hits are the reason the cached price is lower; the work is done once.
