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

# Caching and savings

> See provider cache reads, writes and their net saving.

Provider prompt caching reuses a prompt prefix at the model provider. A cache hit
still makes a model call and generates a new answer. Atlaso records the provider's
reported cache reads and writes along with ordinary input and output usage.

Model-call costs are billed by your provider, with no Atlaso markup, and never
use Atlaso credit. [Credits pay only for Atlaso learning](https://docs.atlaso.ai/account/credits-and-learning.md),
the AI clean-up of saved messages from Gateway calls and the Plugin.

## Claude: only when reuse is likely

Atlaso's automatic Claude cache rule is **only when reuse is likely**. Atlaso adds
a cache marker when the conversation has earlier turns, or the same Atlaso key
sent the same long prefix in the last 5 minutes. The prefix must
also meet the model's cache minimum. A first, one-off long request should not get
an Atlaso-added cache write just because it is long.

If you supply explicit `cache_control`, Atlaso respects those settings instead of
adding its own marker. On Claude, `cache_control` takes `ttl` `5m` (the default)
or `1h`. A request can carry at most 4 cache breakpoints, a top-level
`cache_control` included, and every `1h` breakpoint must come before every `5m`
one. Cache markers sit before the changing memory note where possible. Actual
cache hits still depend on the provider.

For the `openai` adapter, memory is inserted after leading system or developer
messages. That changing note can affect prefix reuse; Atlaso does not
promise memory can never increase a bill.

## OpenAI cache lifetimes

For supported OpenAI models on `/v1/responses`, set `prompt_cache_options.ttl`
to `30m` or `12h`. Individual `prompt_cache_breakpoint.ttl` settings can override
the request default. Atlaso prices each reported write count at its own rate.
If a request asks for 12 hours and the provider omits the split, all writes use
the higher 12-hour price. Missing write counts on an estimated call are treated
as 12-hour writes for all non-read prompt tokens. Activity shows the split.

Use Chat Completions with the default 30-minute lifetime, or switch to Responses
for 12-hour writes. Extended writes on Azure and Bedrock are refused until their
own prices are verified. On OpenAI models, the older `prompt_cache_retention`
field accepts only `in_memory` or `24h`, and `24h` is always refused because
the catalog has no separate 24-hour write rate. On GPT-5.5, GPT-5.6 and GPT-6
models, and on models with a 12-hour rate, any `prompt_cache_retention` is
refused: remove it and use `prompt_cache_options.ttl`. These refusals cost
\$0.00 and name the field to change. See
[Cache lifetime errors](https://docs.atlaso.ai/gateway/errors.md#cache_retention_not_available).

## Where the saving appears

Overview shows **Cache saved**. It is the reduction from cached reads minus the
extra cost of cache writes, using catalog prices. Writes at every priced
lifetime are included. When writes cost at least half a cent more than reads
saved, Overview says **Cache cost $X more than it saved** instead; a smaller net
cost shows as **Cache saved $0.00**. Unknown catalog prices cannot
establish a saving.

Memory adds input tokens. Cache saved measures the cache's net effect, not a
controlled comparison of the same call with memory off. Call costs are calculated
from reported usage when available; missing usage and estimates are distinguished.

## Per-call cost and cache

Every Chat Completions and Responses reply names the call and what it cost, using the same catalog prices
as Activity:

| Header | Meaning |
| - | - |
| `x-atlaso-call-id` | The call's ID, the same one Activity shows. |
| `x-atlaso-provider` | The API hostname of the host that answered, such as `api.together.ai`. It is not a host slug for `provider.order`. `none` before any provider answered. |
| `x-atlaso-model` | The catalog ID of the row that served the call, after aliases and host routing (for a model several hosts serve, the answering host's row, such as `groq/gpt-oss-120b`). On a non-streaming reply it can name another row of the same provider that the provider reported answering. `none` before a provider answers. |
| `x-atlaso-cost-usd` | List price of the call in US dollars, six decimal places. |
| `x-atlaso-cache` | `read=N; write=N`: cached tokens read and written. |
| `x-atlaso-reason` | A short code when the call was refused or failed. |
| `x-atlaso-ignored-params` | Settings you sent that had no effect on this call, comma-separated (for example `temperature,top_p`). Settings the model accepts but ignores were sent as given. The labels `user`, `safety_identifier` and `metadata` are listed when the provider has no such field; they were left out of the provider request. Present only when something was ignored. |

On `/v1/responses`, a Gemini model on Google's own API (not Vertex AI) refuses
such a setting with a 400 instead of ignoring it.

A call refused before reaching a provider costs `0.000000`. When the provider
did not report usage, cost and cache say `unknown`; that is never a zero bill.
Some early refusals (a bad key, body or model, or a rate limit) carry a call ID
but get no Activity row. These figures are catalog list prices, not your provider's invoice.

Streams send the call ID, provider and model as headers. A Chat Completions
stream carries cost and cache only when you ask for usage with
`stream_options: {"include_usage": true}`. Atlaso then adds an `atlaso` field
(`call_id`, `provider`, `model`, `cost_usd`, `cache`, `tokens`, `estimated`,
`reason`) to the usage chunk, the one with empty `choices` just before `[DONE]`.
If the provider sent no usage, Atlaso sends that chunk itself, with `usage` set
to `null`. Missing values are `null`.

Without `include_usage`, Atlaso adds nothing to the stream, and the call's cost
is in Activity.

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

client = OpenAI(base_url=os.environ["ATLASO_BASE_URL"], api_key=os.environ["ATLASO_KEY"])
stream = client.chat.completions.create(
    model="openai/gpt-6.1-terra",
    messages=[{"role": "user", "content": "Say hello."}],
    stream=True,
    stream_options={"include_usage": True},
    extra_headers={"x-atlaso-user": "demo-user-42"},
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="")
    else:
        atlaso = getattr(chunk, "atlaso", None) or {}
        print("\ncost_usd:", atlaso.get("cost_usd"))
```

Streaming headers go out before the body, so `x-atlaso-model` names the routed
catalog row. The provider stream's own `model` field names the served model.

Responses streams carry the same accounting in `response.atlaso` on the final
completed, incomplete or failed event, or in `atlaso` on a bare error event.
Both entrances expose the metadata and retry headers to browser clients.
For routed calls, the reply cost covers the final attempt. Each earlier attempt
has its own record and cost; see [Errors](https://docs.atlaso.ai/gateway/errors.md).


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