API reference
Prompt caching
Abliterator caches repeated prompt prefixes automatically and bills cached input at the cached price. How to structure prompts for cache hits and check cached tokens.
Caching is automatic: no flags, no breakpoints, no write surcharge. When a request starts with the same tokens as a recent one, those tokens bill at the cached price ($0.40 or $0.10 per 1M). Keep stable content at the start of the prompt.
How it works
The serving engine keeps recently processed prompt prefixes. When a new request starts with the same tokens as a cached prefix, the engine reuses them instead of processing them again. Those input tokens are billed at the cached price:
| Model | Input | Cached input |
|---|---|---|
| kimi-k3.1-pro-abliterated | $4.00 per 1M | $0.40 per 1M |
| deepseek-v4.1-flash-abliterated | $1.00 per 1M | $0.10 per 1M |
- Nothing to turn on. It works for Chat Completions and Messages, streaming or not.
- No cache-write surcharge. Tokens that are not cached bill at the normal input price.
- Hits are best-effort. A cached prefix can be evicted, so do not depend on a hit for correctness or exact cost.
- Matching is on the exact token prefix. One changed character early in the prompt ends the match at that point.
Check your cache hits
| API | Field |
|---|---|
| Chat Completions | usage.prompt_tokens_details.cached_tokens |
| Messages | usage.cache_read_input_tokens |
| Any request | cached_tokens in GET /api/v1/generation |
Send the same long prefix twice and compare:
import os
from openai import OpenAI
client = OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])
POLICY = "You review pull requests for security issues. " + ("Follow the secure coding checklist strictly. " * 400)
for question in ["Review: eval(request.args['expr'])", "Review: subprocess.run(cmd, shell=True)"]:
response = client.chat.completions.create(
model="deepseek-v4.1-flash-abliterated",
max_tokens=1024,
reasoning_effort="none",
messages=[{"role": "system", "content": POLICY}, {"role": "user", "content": question}],
)
usage = response.usage
print(usage.prompt_tokens, "prompt tokens,", usage.prompt_tokens_details.cached_tokens, "cached, cost", usage.cost)
The second request should report most of its prompt as cached and cost less.
Structure prompts for cache hits
Order the prompt from most stable to least stable:
- System prompt
- Tool definitions
- Reference documents, few-shot examples, code context
- Conversation history, appended in order
- The new user message
Then:
- Keep the start byte-identical. Do not put timestamps, request IDs, random example orders or a user's name at the top of the system prompt. Put per-request values in the last message instead.
- Keep tools stable. Same tools, same order, same descriptions on every request.
- Append, do not rewrite. In a multi-turn conversation, add new messages at the end. Editing or summarizing earlier turns changes the prefix and misses the cache from that point on.
- Batch similar work together. Run requests that share a long prefix close together in time, for example all eval prompts that share one rubric.
- Reuse images in the same position. An image early in a stable prefix is cached like text.
Long-running agents such as Claude Code, Cline and OpenCode already follow this pattern, which is why cached tokens are usually a large share of their input.
Conversation affinity
A cache lives on the server that processed the prompt. Abliterator keeps each conversation on the same serving endpoint so its cache stays warm:
- Send an
X-Session-Idheader (orX-Abl-Session) with a stable value per conversation, such as your own conversation ID, to make this explicit. - Without the header, Abliterator derives a conversation key from your API key and the first two messages (plus the system prompt in the Messages API).
- A conversation stays bound to its endpoint for 10 minutes after each successful request, unless that endpoint becomes unhealthy.
Each model has one serving endpoint today, so affinity mostly matters for future capacity. Sending X-Session-Id costs nothing and keeps your cache hit rate stable as capacity grows.
Anthropic cache_control
Anthropic clients sometimes add cache_control breakpoints. You do not need them. Abliterator passes them to the model unchanged; any cache_creation_input_tokens the model reports bill at the normal input price, and cache_read_input_tokens bill at the cached price.
Frequently asked questions
Do I need cache_control breakpoints?
No. Caching is automatic for both APIs. If an Anthropic client sends cache_control, Abliterator passes it along and it does no harm, but you do not need it.
How long do cached prefixes last?
Abliterator does not publish a cache lifetime, and hits are not guaranteed. Prefixes reused within a few minutes are the most likely to hit.