You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cache-Aware Price Routing for AI Coding Agents (August 2026)
#52
Coding agents are changing how API costs show up in production. A chatbot may send one compact prompt and wait for one answer. An agent reads repository context, sends tool schemas, retries failed edits, streams partial output, and often sends the same project facts again and again. That makes cache awareness more important than the headline price of any single model.
I rechecked provider pricing during this run on August 7, 2026. DeepSeek's official API docs list deepseek-v4-flash at $0.0028 per 1M cache-hit input tokens, $0.14 per 1M cache-miss input tokens, and $0.28 per 1M output tokens. The same page lists deepseek-v4-pro at $0.003625 cache-hit input, $0.435 cache-miss input, and $0.87 output per 1M tokens. Z.AI's official pricing page lists GLM-5.2 at $1.40 input, $0.26 cached input, and $4.40 output per 1M tokens, while GLM-4.5-Air is $0.20 input, $0.03 cached input, and $1.10 output.
Those numbers point to a practical routing rule: do not choose a model only by "best" or "cheapest." Choose by task shape. A coding-agent request with 200,000 repeated repository tokens and 2,000 new instruction tokens is a different workload from a short compliance rewrite or a one-off architecture question. If repeated context is likely to hit cache, a long-context route can be cheap. If every prompt is new, the cache-hit row is irrelevant.
In an AIWave-style gateway, I would store four fields beside every completion request:
The exact thresholds should come from your own latency, quality, and cache-hit telemetry. The important part is separating model identity, source-checked price, cache expectation, and customer-facing estimate. When those fields are separate, you can update prices without rewriting application logic, and you can explain cost variance to finance or customers without guessing.
There is one implementation detail that matters in real systems: the ledger should record both the predicted route and the observed bill. The predicted route is what the gateway believed before sending the request: repeated prefix size, estimated output cap, tool schema size, customer policy, and fallback budget. The observed bill is what came back after the provider returned usage. If the two drift, you have a useful signal. Maybe the agent kept retrying a patch. Maybe the tool schema grew from 8 KB to 70 KB. Maybe cache reuse was expected but the prefix changed because a timestamp or randomly ordered file list was embedded near the top of the prompt.
For Python SDK users, this can stay simple. Add a metadata dictionary to each request, keep the OpenAI-compatible call unchanged, and emit a structured event when the response finishes. That event should include prompt_tokens, completion_tokens, cache_hit_tokens when available, retry count, elapsed milliseconds, and selected route. The application developer still writes normal chat-completions code, while the platform team gets enough data to improve defaults.
For SDK users, this also argues for small API ergonomics: expose model, base_url, timeout, stream, and a request metadata hook. The model call stays OpenAI-compatible, but your cost ledger gets the operational details it needs.
What routing metadata are you logging for coding-agent workloads today? Are you treating cache hits as a first-class billing signal, or only looking at total tokens after the request finishes?
Sources checked: DeepSeek API pricing, Z.AI pricing, Alibaba Cloud Model Studio model list, DEV statuspage.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Coding agents are changing how API costs show up in production. A chatbot may send one compact prompt and wait for one answer. An agent reads repository context, sends tool schemas, retries failed edits, streams partial output, and often sends the same project facts again and again. That makes cache awareness more important than the headline price of any single model.
I rechecked provider pricing during this run on August 7, 2026. DeepSeek's official API docs list
deepseek-v4-flashat$0.0028per 1M cache-hit input tokens,$0.14per 1M cache-miss input tokens, and$0.28per 1M output tokens. The same page listsdeepseek-v4-proat$0.003625cache-hit input,$0.435cache-miss input, and$0.87output per 1M tokens. Z.AI's official pricing page listsGLM-5.2at$1.40input,$0.26cached input, and$4.40output per 1M tokens, whileGLM-4.5-Airis$0.20input,$0.03cached input, and$1.10output.Those numbers point to a practical routing rule: do not choose a model only by "best" or "cheapest." Choose by task shape. A coding-agent request with 200,000 repeated repository tokens and 2,000 new instruction tokens is a different workload from a short compliance rewrite or a one-off architecture question. If repeated context is likely to hit cache, a long-context route can be cheap. If every prompt is new, the cache-hit row is irrelevant.
In an AIWave-style gateway, I would store four fields beside every completion request:
{ "model": "deepseek-v4-flash", "cache_policy": "expected_repeated_prefix", "price_checked_at": "2026-08-07", "source": "provider_official_pricing_page" }Then I would make the router explicit:
The exact thresholds should come from your own latency, quality, and cache-hit telemetry. The important part is separating model identity, source-checked price, cache expectation, and customer-facing estimate. When those fields are separate, you can update prices without rewriting application logic, and you can explain cost variance to finance or customers without guessing.
There is one implementation detail that matters in real systems: the ledger should record both the predicted route and the observed bill. The predicted route is what the gateway believed before sending the request: repeated prefix size, estimated output cap, tool schema size, customer policy, and fallback budget. The observed bill is what came back after the provider returned usage. If the two drift, you have a useful signal. Maybe the agent kept retrying a patch. Maybe the tool schema grew from 8 KB to 70 KB. Maybe cache reuse was expected but the prefix changed because a timestamp or randomly ordered file list was embedded near the top of the prompt.
For Python SDK users, this can stay simple. Add a
metadatadictionary to each request, keep the OpenAI-compatible call unchanged, and emit a structured event when the response finishes. That event should includeprompt_tokens,completion_tokens,cache_hit_tokenswhen available, retry count, elapsed milliseconds, and selected route. The application developer still writes normal chat-completions code, while the platform team gets enough data to improve defaults.For SDK users, this also argues for small API ergonomics: expose
model,base_url,timeout,stream, and a request metadata hook. The model call stays OpenAI-compatible, but your cost ledger gets the operational details it needs.What routing metadata are you logging for coding-agent workloads today? Are you treating cache hits as a first-class billing signal, or only looking at total tokens after the request finishes?
Sources checked: DeepSeek API pricing, Z.AI pricing, Alibaba Cloud Model Studio model list, DEV statuspage.
All reactions