Repository navigation
fix(quota): read the Ollama Cloud quota from /api/balance - #6786
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ READY
Hygiene✅ Deterministic PR hygiene checks passed. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 20 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (11)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe PR adds balance-first Ollama Cloud quota reporting with usage fallback, updates its tests and documentation, and adds planning documents for two carry PRs. The ChatGPT OAuth hardening document describes planned work; it does not implement that work. ChangesOllama Cloud quota reporting
Carry PR planning
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant QuotaProbe as Ollama Cloud quota probe
participant BalanceAPI as /api/balance
participant BalanceParser as parseOllamaCloudBalance
participant UsageAPI as /api/usage
participant UsageParser as parseOllamaCloudQuota
QuotaProbe->>BalanceAPI: Request balance
BalanceAPI-->>QuotaProbe: Return response
QuotaProbe->>BalanceParser: Parse successful balance body
BalanceParser-->>QuotaProbe: Return quota or null
alt No balance quota
QuotaProbe->>UsageAPI: Request usage
UsageAPI-->>QuotaProbe: Return response
QuotaProbe->>UsageParser: Parse successful usage body
UsageParser-->>QuotaProbe: Return quota or null
end
Merge Risk: ⚪ Minimal · up to The quota change has no identified merge-blocking issue; complete the usual checks before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)Full details: Docstring CoverageExplanation Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d88dea7c3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2a7a811 to
175e1e3
Compare
Ollama replaced the /api/usage quota payload with request-count data. Read /api/balance first, retaining /api/usage for older deployments. Handle transport failures per endpoint and retain terminal verdicts from review. Carries #6739. Co-authored-by: xingqi-gif <[email protected]>
Purchased credit is not part of creditsUsd, so an exhausted included allowance vetoes routing only when purchased balance is known to be zero. Co-authored-by: xingqi-gif <[email protected]>
175e1e3 to
3014954
Compare
Summary
Ollama changed the payload of
GET https://ollama.com/api/usageto a request-count timeseries, soparseOllamaCloudQuotafinds nolimitsand the Ollama Cloud row silently disappears from the quota dashboard. This carries #6739 by @xingqi-gif onto currentdevand adds the failure-handling fixes found in review.GET https://ollama.com/api/balancefirst (shipped upstream in server: proxy cloud usage and balance APIs ollama/ollama#18829, tracked in Cloud API: expose credit balance & true spend after pay-as-you-go migration ollama/ollama#18653) and keep/api/usageas a fallback for older deployments.included.{session,weekly,monthly}map to the 5-hour/weekly/monthly windows; allowance plans mapincluded.{allowance_usd,balance_usd,period.until}tocreditsUsd. Purchased credit is ignored, socreditsUsddescribes the included allowance only. For routing, an exhausted included allowance vetoes Ollama Cloud only whenpurchased.balance_usdis known to be zero or negative; with positive or unknown purchased credit the credits stay display-only, so a paid balance is never blocked./api/provider-quotasresponse./api/balancebody still stops without spending a second request.tests/providers/provider-quota-ollama-cloud.test.ts(registered in both layout files) soprovider-quota.test.tsstays under its ratchet cap.structure/providers-and-adapters.mdand a short paragraph to the Providers guide.Carries #6739. Plan and review record:
devlog/_plan/261009_L5-auth-quota/.Co-authored-by: xingqi-gif [email protected]
Verification
bun test tests/providers/provider-quota-ollama-cloud.test.ts tests/providers/provider-quota.test.ts tests/providers/provider-api-keys.test.ts tests/server/bounded-body.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts→ 304 pass, 0 fail at 4d88dea; after the review fix the quota/key/layout/ratchet subset reran at 237 pass, 0 fail.resets_at, allowance expiry, mixed windows + credits, percent clamping, Ollama missing-key/disabled/non-key exclusion, URL-specific legacy mocks with endpoint-sequence assertions, and combo-routing cases for exhausted included credit with positive / unknown / empty purchased credit (the first two fail without the routing projection fix).bun run typecheck,bun run privacy:scan,bun run structure:check→ pass.bun run testand the docs-site build were not run locally (lane runs minimal local tests by instruction; several lanes share this machine). Both are left to exact-head hosted CI, including thedocs site buildjob./api/balanceshape relies on the upstream PR, third-party SDK documentation, and the original author's live check with a Pro key.Checklist
https://ollama.comthrough the existingquotaFetchguard: Bearer,redirect: "error", request timeout.)Summary by CodeRabbit
New Features
Documentation