Summary
The Anthropic-compatible /v1/messages endpoint silently ignores prompt caching. A request with cache_control returns the exact same response id and usage.input_tokens as the same request without it, and cache_creation_input_tokens / cache_read_input_tokens are always 0. Adding the anthropic-beta: prompt-caching-2024-07-31 header changes nothing.
Steps to reproduce
- Send a
/v1/messages request without cache_control; record the response id and usage.
- Send the same request with
cache_control on system; record the response.
- Compare
id, usage.input_tokens, cache_creation_input_tokens, cache_read_input_tokens.
# with cache_control
curl https://apihub.agnes-ai.com/v1/messages \
-H "x-api-key: $AGNES_PAY_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model":"agnes-2.0-flash","max_tokens":20,
"system":[{"type":"text","text":"You are terse.","cache_control":{"type":"ephemeral"}}],
"messages":[{"role":"user","content":"say ok"}]
}'
Expected behavior
Per Anthropic's prompt caching docs, marking a cache breakpoint should cause cache_creation_input_tokens > 0 on first write (and cache_read_input_tokens > 0 on a subsequent cached read). The response usage should reflect cache state.
Actual behavior
id and usage.input_tokens are identical with and without cache_control — the field is dropped and the request is treated as a plain request.
cache_creation_input_tokens and cache_read_input_tokens are always 0.
- The
anthropic-beta: prompt-caching-2024-07-31 header has no effect.
Impact
Anthropic clients (e.g. Claude Code) attach cache_control to large system/tools blocks. With caching a no-op, every turn re-sends the full prefix → large token-cost and latency overhead, and clients that key off usage to decide cache hits break.
Environment
- Model:
agnes-2.0-flash
- Endpoint:
POST /v1/messages
- Client: curl (also reproducible via Claude Code pointed at the Anthropic-compatible base URL)
- API base:
https://apihub.agnes-ai.com/v1
Related observation
/v1/messages returns the same id as the underlying OpenAI chat completion (a fixed hex id), and different request shapes can share the same id. If Anthropic-semantics dedup/caching is planned, an independent id namespace would avoid collisions.
Summary
The Anthropic-compatible
/v1/messagesendpoint silently ignores prompt caching. A request withcache_controlreturns the exact same responseidandusage.input_tokensas the same request without it, andcache_creation_input_tokens/cache_read_input_tokensare always0. Adding theanthropic-beta: prompt-caching-2024-07-31header changes nothing.Steps to reproduce
/v1/messagesrequest withoutcache_control; record the responseidandusage.cache_controlonsystem; record the response.id,usage.input_tokens,cache_creation_input_tokens,cache_read_input_tokens.Expected behavior
Per Anthropic's prompt caching docs, marking a cache breakpoint should cause
cache_creation_input_tokens> 0 on first write (andcache_read_input_tokens> 0 on a subsequent cached read). The responseusageshould reflect cache state.Actual behavior
idandusage.input_tokensare identical with and withoutcache_control— the field is dropped and the request is treated as a plain request.cache_creation_input_tokensandcache_read_input_tokensare always0.anthropic-beta: prompt-caching-2024-07-31header has no effect.Impact
Anthropic clients (e.g. Claude Code) attach
cache_controlto largesystem/toolsblocks. With caching a no-op, every turn re-sends the full prefix → large token-cost and latency overhead, and clients that key offusageto decide cache hits break.Environment
agnes-2.0-flashPOST /v1/messageshttps://apihub.agnes-ai.com/v1Related observation
/v1/messagesreturns the sameidas the underlying OpenAI chat completion (a fixed hex id), and different request shapes can share the sameid. If Anthropic-semantics dedup/caching is planned, an independent id namespace would avoid collisions.