Endpoints
Prompt caching
Cut the cost of long repeated prompts with automatic prompt caching and cache_control breakpoints, and check cache hits in the usage response.
Try it in the playgroundPrompt caching reuses the processed prefix of a long prompt, such as a system prompt, documents or tool definitions, across requests. Cache reads cost much less than normal input tokens. api14 passes the provider's cache pricing straight through: input_cache_read and input_cache_write are listed for each model in Models.
Automatic caching
These providers cache on their own. You don't need to change anything:
| Provider | Minimum prompt | Cache read price | Cache write price |
|---|---|---|---|
| OpenAI | 1,024 tokens | ~0.25–0.5× input | free |
| DeepSeek | automatic | ~0.1× input | ~1× input |
| Grok, Moonshot, Groq | automatic | discounted | free |
| Google Gemini 2.5 | implicit, model-dependent | ~0.25× input | free |
Put the parts that don't change at the start of the prompt and the parts that change at the end, so the prefix matches between requests.
Explicit caching with cache_control
Anthropic Claude (and Gemini explicit caching) need breakpoints. Add cache_control to a text content part:
{
"model": "anthropic/claude-sonnet-4.5",
"messages": [
{
"role": "system",
"content": [
{ "type": "text", "text": "You are a contracts assistant." },
{
"type": "text",
"text": "<the full 40-page agreement text>",
"cache_control": { "type": "ephemeral" }
}
]
},
{ "role": "user", "content": "Which clause covers termination?" }
]
}
- Anthropic allows up to 4 breakpoints. The cache lives for about 5 minutes and is refreshed on each hit. Use
"ttl": "1h"for a longer cache, which costs more to write. - Cache writes on Anthropic cost about 1.25× input, and reads about 0.1×.
- To keep hitting the same provider's cache, add
provider: { "order": ["Anthropic"], "allow_fallbacks": false }if you need it.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api14.com/api/v1",
apiKey: process.env.API14_API_KEY,
});
const result = await client.chat.completions.create({
"model": "anthropic/claude-sonnet-4.5",
"messages": [
{
"role": "user",
"content": "Explain vector databases in two sentences."
}
]
});
console.log(result.choices[0].message.content);
Reading cache usage
The usage object shows cached tokens, and cost already includes the discount:
{
"usage": {
"prompt_tokens": 10450,
"completion_tokens": 120,
"total_tokens": 10570,
"prompt_tokens_details": { "cached_tokens": 10200 },
"cost": 0.004863
}
}
cached_tokens also appears in your usage logs in the dashboard. Generation lookup shows the full breakdown, including cache_discount.
Errors
Caching never causes errors of its own. A malformed cache_control is ignored or rejected by the provider with a 400. See Errors.