Skip to content

Incorrect token count and pricing calculation for DeepSeek models #27458

Closed

Description

@HUANGzc83

Problem

When using DeepSeek models (deepseek-v4-flash / deepseek-v4-pro) via OpenCode, both token counting and cost estimation are inaccurate.

Root Cause Analysis

  1. 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.

  2. Stale hardcoded model info — The context window, pricing per token (input/output), and tokenizer selection are compiled into the binary. For DeepSeek V4:

Expected Behavior

  • Token counts should match what DeepSeek's API reports (or at minimum use the correct tokenizer)
  • Pricing should reflect current DeepSeek API pricing: https://api-docs.deepseek.com/quick_start/pricing
  • Context window should be 1M for V4 models (not 262K)

Environment

  • OpenCode version: 1.14.50
  • Model(s): opencode/deepseek-v4-flash-free, deepseek-v4-pro
  • 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)

Activity

  1. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions