ai-sdk: DeepSeek's cache-hit token fields are never parsed, so cached tokens always report zero #1221

Closed
opened 2026-10-27 13:39:30 +00:00 by sam · 0 comments
Owner

Cross-repo reporting defect. archie-core displays and logs each agent step as 'N tokens (fresh + cached)' and logs cached_tokens/cache_creation_tokens per step, but every step reports zero cached tokens for DeepSeek. The cause is the field shape the ai-sdk OpenAI-compatible provider parses: it reads cached_tokens (the OpenAI and Anthropic usage shapes), while DeepSeek reports its cache accounting under different field names (prompt_cache_hit_tokens / prompt_cache_miss_tokens) that nothing in the provider reads. The consequence is not just cosmetic: cost and cache-effectiveness reporting overstates fresh input for every DeepSeek turn, which is the provider archie-core runs tasks on, so an operator reading usage cannot tell whether prompt caching is working at all. Fix: parse the provider's own cache field names in the OpenAI-compatible usage mapping and map them onto the existing cached-tokens field, keeping the OpenAI shape working.

Acceptance criteria

a DeepSeek response carrying its cache-hit field reports a non-zero cached-token count through the same usage path the logs and UI read, and an OpenAI-shaped response still maps its cached_tokens field

Close reason

Moved to ai-sdk; tracked and fixed there.


Imported from beads archie-core-ais4 · GitHub #1380 · type bug · priority P3 · created 2026-10-02 · closed 2026-10-05

Cross-repo reporting defect. archie-core displays and logs each agent step as 'N tokens (fresh + cached)' and logs cached_tokens/cache_creation_tokens per step, but every step reports zero cached tokens for DeepSeek. The cause is the field shape the ai-sdk OpenAI-compatible provider parses: it reads cached_tokens (the OpenAI and Anthropic usage shapes), while DeepSeek reports its cache accounting under different field names (prompt_cache_hit_tokens / prompt_cache_miss_tokens) that nothing in the provider reads. The consequence is not just cosmetic: cost and cache-effectiveness reporting overstates fresh input for every DeepSeek turn, which is the provider archie-core runs tasks on, so an operator reading usage cannot tell whether prompt caching is working at all. Fix: parse the provider's own cache field names in the OpenAI-compatible usage mapping and map them onto the existing cached-tokens field, keeping the OpenAI shape working. ### Acceptance criteria a DeepSeek response carrying its cache-hit field reports a non-zero cached-token count through the same usage path the logs and UI read, and an OpenAI-shaped response still maps its cached_tokens field ### Close reason Moved to ai-sdk; tracked and fixed there. --- _Imported from beads `archie-core-ais4` · GitHub #1380 · type bug · priority P3 · created 2026-10-02 · closed 2026-10-05_
sam added the lowbug labels 2026-10-27 13:39:30 +00:00
sam self-assigned this 2026-10-27 13:39:30 +00:00
sam closed this issue 2026-10-27 13:39:30 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1221