IonWarpbotexample reviewconst res = await client.chat.completions.create({ model, messages });const stream = await client.chat.completions.create({ model, messages, stream: true });for await (const chunk of stream) yield chunk.choices[0]?.delta?.content ?? "";
The switch to streaming never asks for usage (`stream_options: { include_usage: true }`), so every chat turn now writes 0 tokens and $0 to the ledger the budget reads. Request usage and record the final chunk's usage with the served model.
P2Reasoning repair measures the gap against raw input, re-billing cached input as completion for additive-cache providers · Cost Review
When an additive-cache provider (Anthropic/Bedrock — providers NOT in SUBSET_PROVIDERS, whose `input_tokens` excludes the cached tokens) reports `total_tokens` that includes the cached prompt tokens, `resolveCompletionTokens` returns `total - input = output + cache`, so the cached tokens are charged at the completion rate in addition to the cache read/write rate that `spendStructuredTokens`/`prepareStructuredTokenSpend` already bills from the same entry. The repo itself proves cache is separate from `input_tokens` for these providers: the additive branch computes `totalInput: rawInput + cacheCreation + cacheRead`, yet the new gap check uses raw `usage.input_tokens` only. Example entry that mis-bills: `{ input_tokens: 100, output_tokens: 50, total_tokens: 190, cache_read_input_tokens: 40, provider: 'anthropic' }` → completion 90 instead of 50, with the 40 cache tokens billed twice. For the subset providers the same line is harmless because `input_tokens` already contains the cache, which is why the new tests (all OpenAI/Vertex) pass.