Description
The nano-gpt integration loses cache-write usage and recomputes an estimated cost even when NanoGPT returns the settled USD charge. The OpenAI-compatible SDK does not map usage.cache_creation_input_tokens into its normalized usage, and OpenCode does not consume x_nanogpt_pricing.
This can display zero cache writes and a cost that differs from the charge when cache-write rates, long-context pricing, or discounts apply. Cache writes should remain distinct from cache reads. A valid reported USD cost should take precedence over the estimate, including an explicit zero; otherwise the existing estimate should remain.
OpenCode version
Reported in desktop v1.18.30; reproduced through the SDK and session accounting tests on dev commit 193de13.
Steps to reproduce
Use the nano-gpt provider with @ai-sdk/openai-compatible. Feed its SDK a synthetic completion with:
{
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 20,
"total_tokens": 1020,
"cache_creation_input_tokens": 800,
"prompt_tokens_details": { "cached_tokens": 100 }
},
"x_nanogpt_pricing": { "amount": 0.0123, "currency": "USD" }
}
Observe session accounting: the cache-write count is lost and the cost uses catalog rates. Expected: 100 ordinary input tokens, 100 cache-read tokens, 800 cache-write tokens, and cost $0.0123. The same issue affects streaming usage frames.
Local regression tests and a fix are in #48477. No live inference is required for the reproduction.
Description
The
nano-gptintegration loses cache-write usage and recomputes an estimated cost even when NanoGPT returns the settled USD charge. The OpenAI-compatible SDK does not mapusage.cache_creation_input_tokensinto its normalized usage, and OpenCode does not consumex_nanogpt_pricing.This can display zero cache writes and a cost that differs from the charge when cache-write rates, long-context pricing, or discounts apply. Cache writes should remain distinct from cache reads. A valid reported USD cost should take precedence over the estimate, including an explicit zero; otherwise the existing estimate should remain.
OpenCode version
Reported in desktop v1.18.30; reproduced through the SDK and session accounting tests on dev commit 193de13.
Steps to reproduce
Use the
nano-gptprovider with@ai-sdk/openai-compatible. Feed its SDK a synthetic completion with:{ "usage": { "prompt_tokens": 1000, "completion_tokens": 20, "total_tokens": 1020, "cache_creation_input_tokens": 800, "prompt_tokens_details": { "cached_tokens": 100 } }, "x_nanogpt_pricing": { "amount": 0.0123, "currency": "USD" } }Observe session accounting: the cache-write count is lost and the cost uses catalog rates. Expected: 100 ordinary input tokens, 100 cache-read tokens, 800 cache-write tokens, and cost $0.0123. The same issue affects streaming usage frames.
Local regression tests and a fix are in #48477. No live inference is required for the reproduction.