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
Incorrect token count and pricing calculation for DeepSeek models #27458
When using DeepSeek models (deepseek-v4-flash / deepseek-v4-pro) via OpenCode, both token counting and cost estimation are inaccurate.
Root Cause Analysis
Tokenizer mismatch — OpenCode uses a different tokenizer (likely tiktoken for OpenAI) to count tokens locally, which produces different counts than DeepSeek's official byte-level BPE tokenizer. The DeepSeek API response includes usage.prompt_tokens / usage.completion_tokens in its own encoding, but OpenCode displays its own locally-computed counts instead of (or in addition to) the API-reported values.
Stale hardcoded model info — The context window, pricing per token (input/output), and tokenizer selection are compiled into the binary. For DeepSeek V4:
Provider: DeepSeek (via OpenCode Zen / direct API)
OS: Windows
Suggested Fix
Update the internal model registry for DeepSeek V4 models with correct tokenizer, context window (1M), and pricing
Consider using tiktoken with the cl100k_base encoding as a closer approximation, or better yet, respect the usage field returned by DeepSeek's API response
Add a configuration override mechanism so users can supply custom pricing/tokenizer info for provider models (future-proofing)
Reacted by Peter Buyukliev, 半颗白菜, Michael DeRazon and AlexanderMlr
If your issue is specifically about the tokenizer mismatch and pricing rates rather than context window size, it may still be worth keeping as a separate report — but please review the above issues to avoid duplication.
Activity
github-actions commentedon May 14, 2026
This issue might be a duplicate of existing issues. Please check:
If your issue is specifically about the tokenizer mismatch and pricing rates rather than context window size, it may still be worth keeping as a separate report — but please review the above issues to avoid duplication.