[Bug] Wrong tokenizer fallback for GPT-6-* in Claude Code /context via Codex OAuth
Maintainers usually reply within 8 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 80/100
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
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
- Consider
o200k_basefor unmatched Codex models, preserving explicit legacy mappings, as in LiteLLM's fallback change. William Liu's 31-fixture comparison found identical input counts for GPT-6 Astra/Sol/Luna and GPT-5.5. This supports an estimate, but does not establish tokenizer identity or cover GPT-6.1/6.2; official tiktoken has no GPT-6 mapping. - A server-side alternative is OpenAI's
POST /v1/responses/input_tokens, where credentials support it. It can also validate candidate encodings for GPT-6.1/6.2. Subscription OAuth access cannot be assumed: an existing report documents a missing-scope 401.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from router-for-me/CLIProxyAPI
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
router-for-me/CLIProxyAPI#8667 ·
Maintainers usually reply within 8 days
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
router-for-me/CLIProxyAPI#5289 · 1 reaction ·
Maintainers usually reply within 8 days
-
mac下正确的快速开始May be free again A pull request for this issue was closed without being merged. Openlampoon
Difficulty 2/5 Half a day Newbie friendliness 68/100
router-for-me/CLIProxyAPI#2064 · 14 comments · 17 reactions ·
Maintainers usually reply within 8 days
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
router-for-me/CLIProxyAPI#8691 ·
Maintainers usually reply within 8 days
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
router-for-me/CLIProxyAPI#8688 ·
Maintainers usually reply within 8 days
All issues in router-for-me/CLIProxyAPI
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
kind/feature needs-triage priority/unprioritized
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NVIDIA/k8s-test-infra#1504 ·
Maintainers usually reply within 1 day
-
Area/Infrastructure Aspect/Infra Resources Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wso2/agent-manager#2717 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
open-policy-agent/opa#9685 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
aliyun/elastic-compute-control-cli#191 · 3 comments ·
Maintainers usually reply within 1 day