Skip to content

fix: normalize BYOK responses usage - #20

Merged
OnlyTerp merged 1 commit into
sybil-solutions:mainfrom
tharuxpert:fix/byok-cache-usage
May 28, 2026
Merged

fix: normalize BYOK responses usage#20
OnlyTerp merged 1 commit into
sybil-solutions:mainfrom
tharuxpert:fix/byok-cache-usage

Conversation

@tharuxpert

Copy link
Copy Markdown
Contributor

Summary

  • Normalize Chat Completions usage into Responses-style input_tokens, output_tokens, and total_tokens for BYOK routes.
  • Preserve cache/accounting details under input_tokens_details / output_tokens_details when upstreams provide them.
  • Capture Anthropic message_start.usage so stream cache usage is not dropped.
  • Ignore local codedb.snapshot inspection artifacts.

Why this matters

Some OpenAI-compatible BYOK providers return Chat-style usage (prompt_tokens / completion_tokens). Codex expects Responses-style usage on response.completed; when the shape is wrong, a successful model response can still make Codex reject the turn and retry the request. This fix keeps BYOK agent loops usable and preserves token/cache accounting for compaction and cost visibility.

Verification

  • python3 -m pytest tests/ -q
  • python3 -m compileall codex_shim/ -q
  • codex-cli 0.134.0 through codex-shim to mimo-v2.5-pro: turn completed successfully with cache usage reported (input_tokens: 25728, cached_input_tokens: 25664).

Security review

Diff-scoped codex-security review completed. No exploitable issue found in the changed code path.

@OnlyTerp
OnlyTerp merged commit a098b16 into sybil-solutions:main May 28, 2026
2 checks passed
jomangbp pushed a commit to jomangbp/codex-shim that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants