[Bug] Wrong tokenizer fallback for GPT-6-* in Claude Code /context via Codex OAuth

Open Beginner friendly
#8,683 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 8 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
80/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
api, backend

Research direction

Read internal/runtime/executor/codex_executor_tokens.go, especially tokenizerForCodexModel and its existing GPT-5, GPT-4.1/GPT-4o, and legacy GPT-4 mappings. Reproduce the reported /v1/messages/count_tokens comparison for gpt-6.2-sol and gpt-5.6-sol, then check the relevant tokenizer tests. Done when GPT-6 uses the proposed o200k_base estimate and the existing mappings still pass.

Written by the indexing model from the issue text.

Description

Fixed

Is it a request payload issue?

  • Yes, this is a request payload issue. I am using a client/cURL to send a request payload, but I received an unexpected error.
  • No, it's another issue.

Describe the bug

When Claude Code accesses a Codex subscription through CPA using gpt-6.2-sol, /context reports incorrect token estimates.

CPA handles /v1/messages/count_tokens locally. Its Codex tokenizer selection has no GPT-6 rule and incorrectly falls back to the legacy cl100k_base estimator. o200k_base is the better-supported estimation fallback (see Potential fix).

The existing explicit mappings for GPT-5, GPT-4.1/GPT-4o, and legacy GPT-4 appear correct and should be preserved.

CLI Type

(Subscription Type)

Codex (ChatGPT subscription/OAuth route).

Model Name

gpt-6.2-sol (comparison: gpt-5.6-sol).

LLM Client

Claude Code (/context); token-count endpoint reproduced with cURL.

Request Information

Reproduced against a running CPA deployment:

curl -sS http://127.0.0.1:8317/v1/messages/count_tokens \
  -H "Authorization: Bearer $CPA_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model":"gpt-6.2-sol",
    "messages":[
      {"role":"user","content":"你好,世界!这是一个用于测试分词器的中文句子。"}
    ]
  }'

Response:

{"input_tokens":24}

Repeating the request with only model changed gives:

Model Returned input_tokens Selected local encoding
gpt-6.2-sol 24 cl100k_base
gpt-5.6-sol 16 o200k_base

Source inspection and an offline executor reproduction confirm the selected encodings. For this text, cl100k_base counts 24 tokens and o200k_base counts 16.

Expected behavior

Use o200k_base as the better-supported local estimation fallback for GPT-6, so /context does not receive counts based on the legacy fallback. Preserve the existing GPT-5 (o200k_base), GPT-4.1/GPT-4o (o200k_base), and legacy GPT-4 (cl100k_base) mappings.

OS Type

  • OS: Ubuntu 26.04.1 LTS
  • Version: v8.1.11

Additional context

Source analysis at dev commit dfeb3a86: tokenizerForCodexModel has no GPT-6 match and falls back to cl100k_base. The existing explicit mappings listed above agree with official tiktoken. Related PR #7538 included a modern fallback but was closed without merging.

Potential fix

Dominant language
Go
Stars
59.8k
Forks
9.2k
Avg merge
7h 42m
Merged PRs (30d)
46

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from router-for-me/CLIProxyAPI

All issues in router-for-me/CLIProxyAPI

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.