Prerequisites
- An Arbytra API key
- Python 3.10+ with the OpenAI SDK (
pip install openai) or the arbytra SDK (pip install arbytra)- OR Node.js 18+ with the OpenAI SDK (
npm install openai) or@arbytra/sdk(npm install @arbytra/sdk)
- OR Node.js 18+ with the OpenAI SDK (
How it works
Arbytra optimizes caching for each provider when your request includes reusable prompt content. On subsequent requests sharing the same prompt prefix, the provider serves cached tokens at reduced cost and lower latency. Arbytra accounts for each provider’s caching economics (token thresholds, discount depths, and read/write prices) when choosing where to route. Over time, the system learns your usage patterns to improve estimation accuracy. Create separate workspaces for different use cases to get better predictions. Arbytra is a zero data retention proxy. Your prompts, responses, and content are never read, logged, or stored. Pattern calibration uses usage metadata only. Read the Privacy Policy for details.Send a cached request
Send a request with a reusable system prompt:Override caching per provider
Arbytra handles caching automatically for supported providers. For explicit control, each provider accepts specific fields. When you supply one, Arbytra skips automatic injection and uses your value.When you provide any of these fields, Arbytra skips automatic cache injection for that provider.
Anthropic — cache_control
Add cache_control to content blocks to mark specific content for caching:
"ephemeral". This follows the provider’s default retention behavior. cache_control applies to Anthropic models only. For other providers, automatic optimization handles caching.
OpenAI — prompt_cache_key and prompt_cache_retention
prompt_cache_key improves cache hit rate for repeated conversations. prompt_cache_retention: "24h" extends the cache lifetime to 24 hours.
prompt_cache_retention is supported on gpt-4.1+ and gpt-5+ models only. It isn’t compatible with ZDR data policy. Omit it if your workspace uses ZDR.
Fireworks — user
On Fireworks, requests with the same user value benefit from improved cache reuse across conversation turns.
Check cache usage
For/v1/chat/completions responses, cache hit information appears in usage.prompt_tokens_details:
cached_tokens shows how many prompt tokens were served from cache. Arbytra normalizes this field across all providers in the OpenAI-format response.
cache_write_tokens indicates how many tokens were written to prompt cache on this request. Present when the provider reports cache-write accounting.
For /v1/messages responses, cache tokens appear as top-level usage fields:
input_tokens represents only the non-cached portion. Total input tokens = input_tokens + cache_read_input_tokens + cache_creation_input_tokens.
For /v1/responses requests, cache token counts appear in usage.input_tokens_details:
cache_write_tokens indicates how many tokens were written to prompt cache. Present when the provider reports cache-write accounting.
Check cache savings
Cache savings appear inrouting_metadata.cost when savings are greater than zero:
cache_savings_percent is an integer (0-100) showing the percentage saved compared to uncached cost. cache_savings_usd shows the dollar amount saved.
Check cache usage in streams
Cache metrics appear in the final streaming chunk alongsideusage and routing_metadata. See Streaming for details on consuming trailing chunks.
Improve cache hits
You can improve cache hit rates by structuring your requests for reuse.- Long, stable system prompts: Place reusable instructions in the system message. The prompt prefix is what providers cache.
- Few-shot examples: Static example blocks are reused across requests.
- Static before dynamic: Put content that doesn’t change before content that does.
- Multi-turn conversations: Shared prompt prefixes get better cache reuse across requests.
- Steady request cadence: Providers expire cached tokens after inactivity. Steady flow keeps entries warm.
Look up cache pricing
The model directory exposes cache pricing for every supported provider. Query it to seecache_read_price, cache_write_price, and supports_prompt_caching per model:
Troubleshoot
Resources
- Cost optimization — cache economics in routing
- Streaming — cache metrics in streaming responses
- Model directory — cache pricing and support per model
- Response metadata —
routing_metadata.costfields