fix: Correct xAI cache field name (input_tokens_details) - #73
Merged
Conversation
…okens_details xAI returns cached_tokens under input_tokens_details, not prompt_tokens_details. Debug logging confirmed the actual field name. Cache was working but we weren't reading the metrics. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
finml-sage
approved these changes
Mar 29, 2026
finml-sage
left a comment
Collaborator
There was a problem hiding this comment.
Approved. input_tokens_details not prompt_tokens_details — xAI diverges from OpenAI naming. Cache confirmed working (1,216/84,054 cached). +3/-3.
nexus-marbell
added a commit
that referenced
this pull request
Apr 20, 2026
The bridge migrated from Chat Completions to the xAI Responses API in PRs #55, #56, #57, #58 (issue #51). The README still described the legacy wire format throughout, so a new reader landed on documentation that did not match the code. This brings the README back in sync with what is actually deployed on main. Changes - Architecture diagram now shows translation targeting the Responses API - "Responses API as the Default" subsection added, referencing the migration PRs - Protocol Translation table rewritten for Anthropic <-> Responses mappings (input/output, function_call / function_call_output, max_output_tokens, reasoning.effort, cached_tokens via input_tokens_details) - "How It Works" module list includes responses_forward/reverse/streaming, model_routing, shared, enrichment_folding, and the handlers/ package; legacy Chat Completions modules are listed and labeled as such - Project Structure tree updated to match the current repo layout (handlers/, bridge/, enrichment_folding.py, shared.py, structure_loader.py) - Configuration table adds XAI_USE_CHAT_COMPLETIONS, IDENTITY_ENABLED, LOG_LEVEL, DUMP_REQUESTS, DUMP_DIR, sourced from .env.example - GROK_MODEL default corrected to grok-4.20-reasoning-latest (TranslationConfig.default_model in translation/config.py) - New "Prompt Caching" subsection documents the x-grok-conv-id affinity header, 90% cached-token discount, and cached_tokens telemetry (PRs #71, #73, cache diagnostics on main) - Test count corrected from 235+/490+ to 713 (pytest --collect-only) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
xAI returns
cached_tokensunderinput_tokens_details, notprompt_tokens_details. Debug log from #72 confirmed:{"input_tokens": 84054, "input_tokens_details": {"cached_tokens": 1216}, ...}Three locations fixed. Cache metrics will now surface correctly in logs and Anthropic usage response.
Note: cache hit rate is low (~1.4%) because xAI prefix caching only matches the exact start of the request. The system prompt (~1216 tokens) caches, but tool definitions and conversation history change each turn, breaking the prefix match early. This is expected behavior per xAI docs.
🤖 Generated with Claude Code