Skip to content
Guides

Reasoning & Prompt Caching ​

Unlock frontier multi-step reasoning (gpt-5, o3, Claude Extended Thinking, Gemini 2.5 Thinking, DeepSeek-R1) while keeping long-context agent bills predictable with prompt caching.

Controlling Reasoning Depth ​

bash
curl https://api.vanix.io/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $VANIX_API_KEY" \
  -d '{
    "model": "o3-mini",
    "reasoning_effort": "medium",
    "max_completion_tokens": 2048,
    "messages": [{"role": "user", "content": "Design a lock-free token bucket rate limiter in Go."}]
  }'
bash
curl https://api.vanix.io/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: $VANIX_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 8000,
    "thinking": {"type": "enabled", "budget_tokens": 4096},
    "messages": [{"role": "user", "content": "Audit this SQL migration for zero-downtime lock hazards."}]
  }'

Prompt Caching ​

Repeated static prefixes—such as long system instructions, tool schemas, repository context, or RAG policy documents—can be cached upstream for 50%–90% lower input token costs and dramatically faster TTFT.

ProviderCaching ModeMinimum PrefixTelemetry Field
OpenAIAutomatic on identical prefixes1,024 tokensusage.prompt_tokens_details.cached_tokens
AnthropicExplicit cache_control: {"type": "ephemeral"}1,024–2,048 tokensusage.cache_creation_input_tokens & cache_read_input_tokens
Google GeminiImplicit / Context CachingModel-dependentusageMetadata.cachedContentTokenCount

Anthropic Explicit Cache Breakpoint Example ​

json
{
  "model": "claude-sonnet-4-5",
  "max_tokens": 1024,
  "system": [
    {
      "type": "text",
      "text": "<large static codebase rules and API specification exceeding 1,024 tokens>",
      "cache_control": { "type": "ephemeral" }
    }
  ],
  "messages": [
    { "role": "user", "content": "Review middleware/rate-limit.go for race conditions." }
  ]
}

Three Rules for High Cache Hit Rates ​

  1. Keep prefixes byte-identical: Place timestamps, user IDs, and dynamic RAG snippets at the end of the prompt—never inside the static system block.
  2. Stabilize tool definitions: Sort tools[] deterministically so schema order never churns between turns.
  3. Preserve channel affinity: Follow our Channel Affinity Guide so consecutive agent turns route to the same upstream provider cache.

Vanix AI Unified Model Gateway · https://api.vanix.io