You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(ai): report cached prompt tokens for OpenAI-compatible providers - #3565
openaicompat.ParseOpenAIResponse now fills Usage.CacheReadTokens from usage.prompt_tokens_details.cached_tokens. It was hard-coded to 0.
New test TestParseOpenAIResponse_ReportsCachedPromptTokens.
CacheCreationTokens stays 0: the Chat Completions API reports cache reads only.
why
ParseOpenAIResponse is shared by the OpenAI, Grok, Ollama and Azure OpenAI providers (plus the other OpenAI-compatible ones that use it). With cached prompts the API returns cached_tokens, but atmos ai chat never showed a cache: count for these providers (the TUI prints it only when it is above zero), and the cached field of the executor's usage output stayed absent.
Gemini and Anthropic already report their cache reads through the same types.Usage fields. InputTokens is left as the full prompt_tokens, the way the Gemini provider reports PromptTokenCount.
references
go test ./pkg/ai/agent/base/openaicompat/ fails without the change (expected 64, got 0) and passes with it; go test of the other provider packages that use the helper (openai, azureopenai, grok, ollama, deepseek, github, openrouter, zai) passes. gofmt -l is clean.
Not run against a live OpenAI endpoint.
This change was made with Claude Code; the tests above were run before opening the PR.
Summary by CodeRabbit
Bug Fixes
Cached prompt tokens are now included in reported usage totals. Cache creation tokens continue to be reported as zero.
ParseOpenAIResponse hard-coded CacheReadTokens to 0, so atmos ai chat showed
"cache: 0" for OpenAI, Grok, Ollama and Azure OpenAI even when the API
reported prompt_tokens_details.cached_tokens. Read the value from the response.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Latest completed GitHub Actions runs for f24d723e8801.
PR wall-clock time: 12h 50m 24s
Aggregate runner time: 14h 01m 38s
Included: 13 workflows, 127 jobs (including matrix jobs)
Wall-clock time spans the earliest included workflow creation through the latest completion. Aggregate runner time adds each job's execution time, so concurrent jobs are counted separately.
Reviewing files that changed from the base of the PR and between 0762a1d and f24d723.
Files selected for processing: 2
pkg/ai/agent/base/openaicompat/convert.go
pkg/ai/agent/base/openaicompat/convert_test.go
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
Walkthrough
The OpenAI-compatible response parser now reports cached prompt tokens as cache-read tokens. A test checks the input, output, total, cached-token, and cache-creation counts.
The change reports cached prompt tokens while preserving existing usage counts. No actionable merge-blocking risk is identified.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: reporting cached prompt tokens for OpenAI-compatible providers.
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.
Finishing Touches: 💡 1
🧪 Generate unit tests (beta)
Create a new PR
🛠️ Fix failing CI checks: 💡
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
ast-grep (0.50.0)
Custom ast-grep rule coverage is incomplete: one or more packages are unavailable or not authorized for this review.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
0 unresolved review threads (outdated threads still count)
Fewer than 150 changed files
Passed
2 changed files; maximum 149
Benchmark results
Passed
No benchmark report processing error recorded for this head
🤖 Next steps for this PR
PR: https://github.com/cloudposse/atmos/pull/3565
Head: f24d723e880170718ca38296c0873b18a3c6f724
1. All CI checks and workflows
Problem: 1 CI results are unsuccessful; 0 are still pending.
Next: Open the logs for the unsuccessful results listed below. Fix the reported cause and rerun those jobs; for cancelled or infrastructure-failed jobs, verify the cause before retrying.
Observed results (quoted data):
- "workflow: .github/workflows/quality-report.yml": "cancelled"
Evidence: https://github.com/cloudposse/atmos/pull/3565/checks
Atmos performance
No significant regressions detected against the newest compatible snapshot.
<!-- release-pr-comment:428551177 -->
These changes were released in [v1.234.0-nightly.40981497086](https://github.com/cloudposse/atmos/releases/tag/v1.234.0-nightly.40981497086).
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
patchA minor, backward compatible changequality:not-readyOne or more Quality Gate requirements are pending or failingsize/sSmall size PR
2 participants
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.
what
openaicompat.ParseOpenAIResponsenow fillsUsage.CacheReadTokensfromusage.prompt_tokens_details.cached_tokens. It was hard-coded to0.TestParseOpenAIResponse_ReportsCachedPromptTokens.CacheCreationTokensstays0: the Chat Completions API reports cache reads only.why
ParseOpenAIResponseis shared by the OpenAI, Grok, Ollama and Azure OpenAI providers (plus the other OpenAI-compatible ones that use it). With cached prompts the API returnscached_tokens, butatmos ai chatnever showed acache:count for these providers (the TUI prints it only when it is above zero), and thecachedfield of the executor's usage output stayed absent.types.Usagefields.InputTokensis left as the fullprompt_tokens, the way the Gemini provider reportsPromptTokenCount.references
go test ./pkg/ai/agent/base/openaicompat/fails without the change (expected 64, got 0) and passes with it;go testof the other provider packages that use the helper (openai, azureopenai, grok, ollama, deepseek, github, openrouter, zai) passes.gofmt -lis clean.This change was made with Claude Code; the tests above were run before opening the PR.
Summary by CodeRabbit