feat(quota): report A6API credit usage - #693
Conversation
Co-authored-by: OpenAI Codex <codex@openai.com>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughChangesA6API key-auth providers now query canonical billing endpoints, validate usage totals, calculate USD credit utilization, and emit a custom quota window. Cache entries include the active key identity. Tests and localized documentation cover routing, validation, request security, and configuration. A6API Quota Support
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant maybeFetchProviderQuota
participant fetchA6apiQuota
participant A6API
participant ProviderQuotaReport
maybeFetchProviderQuota->>fetchA6apiQuota: route canonical key-auth configuration
fetchA6apiQuota->>A6API: request subscription and token usage
A6API-->>fetchA6apiQuota: return billing and usage payloads
fetchA6apiQuota->>ProviderQuotaReport: calculate and return credit quota report
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/providers/quota.ts`:
- Around line 162-167: Update the quota validation guard in the reporting
function around limitUsd, grantedUnits, usedUnits, and availableUnits to reject
negative usedUnits or availableUnits before calculating usdPerUnit and reporting
results. Preserve the existing null behavior for invalid inputs, and add a
regression case covering negative usage quantities, including negative available
units.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2e72700a-69ab-4bda-9fbc-4e9a9ba526b8
📒 Files selected for processing (2)
src/providers/quota.tstests/provider-quota.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c299ed7c10
ℹ️ 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".
Co-authored-by: OpenAI Codex <codex@openai.com>
|
@codex review |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/providers/quota.ts`:
- Around line 167-179: Update the validation guard in the quota calculation
before deriving usdPerUnit to reject payloads where usedUnits plus
availableUnits exceeds grantedUnits, returning null like other malformed inputs.
Add a regression test for totals such as grantedUnits=100, usedUnits=80, and
availableUnits=80, ensuring no report is produced.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b7fc2718-80e2-4411-bb5e-bc1c3fa07350
📒 Files selected for processing (2)
src/providers/quota.tstests/provider-quota.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2903177e9b
ℹ️ 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".
Co-authored-by: OpenAI Codex <codex@openai.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/providers/quota.ts (1)
169-180: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winReject under-accounted A6API totals in
src/providers/quota.ts:169-180.total_grantedshould reconcile withtotal_used + total_available; the current guard only rejects over-accounting, so a deficit still renders a misleading credits bar and remaining amount. Fail closed on mismatch (or allow a documented fractional tolerance) and add a regression test for the under-accounted case.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/providers/quota.ts` around lines 169 - 180, Update the validation guard in the A6API quota calculation before usdPerUnit is computed to reject totals whenever grantedUnits does not reconcile with usedUnits plus availableUnits, including under-accounted deficits; use only a documented fractional tolerance if the existing data contract requires it. Preserve the current null return behavior and add a regression test covering a granted total greater than used plus available.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs-site/src/content/docs/guides/providers.md`:
- Around line 224-248: Sync the new A6API credit-quota section from the English
providers guide into the Japanese, Korean, Russian, and Simplified Chinese
provider guides. Preserve the canonical HTTPS endpoints, openai-chat/authMode
key requirements, quota conversion and display behavior, token-expiration note,
active-key-only probing, redirect rejection, and invalid billing-total handling;
place each section alongside the generic OpenAI-compatible endpoint content.
In `@tests/provider-quota.test.ts`:
- Around line 325-341: The test “A6API quota accepts equivalent canonical HTTPS
URLs only” currently covers only /v1 URL variants; add a table-driven case
covering the documented root URL https://api.a6api.com alongside the existing
canonical forms, and assert it is accepted with the expected quota report while
credentialed URLs remain rejected.
---
Outside diff comments:
In `@src/providers/quota.ts`:
- Around line 169-180: Update the validation guard in the A6API quota
calculation before usdPerUnit is computed to reject totals whenever grantedUnits
does not reconcile with usedUnits plus availableUnits, including under-accounted
deficits; use only a documented fractional tolerance if the existing data
contract requires it. Preserve the current null return behavior and add a
regression test covering a granted total greater than used plus available.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 16cacd64-7281-47cd-80cf-9a2f64c094e8
📒 Files selected for processing (3)
docs-site/src/content/docs/guides/providers.mdsrc/providers/quota.tstests/provider-quota.test.ts
Co-authored-by: OpenAI Codex <codex@openai.com>
|
Addressed the outside-diff A6API reconciliation finding in 16e9b75. Used and available units must now match granted units within a documented relative floating-point tolerance of 1e-9; both over-accounted and under-accounted payloads fail closed, with regression coverage. |
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs-site/src/content/docs/ja/guides/providers.md`:
- Around line 157-162: Update the A6API usage paragraphs in
docs-site/src/content/docs/ja/guides/providers.md:157-162,
docs-site/src/content/docs/ko/guides/providers.md:157-162,
docs-site/src/content/docs/ru/guides/providers.md:168-174, and
docs-site/src/content/docs/zh-cn/guides/providers.md:148-152 to state that token
units are converted to USD using the account’s hard credit limit, keeping the
translated guides synchronized with the English guide.
In `@src/providers/quota.ts`:
- Around line 172-179: Update the reconciliationTolerance calculation in the
quota validation flow to use strictly relative scaling: multiply
Math.abs(grantedUnits) directly by 1e-9 without flooring the scale at 1. Add a
regression test covering a sub-unit grantedUnits value such as 0.1 with a
reconciled total whose relative error exceeds the tolerance, and verify it
returns null.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 58ceb15f-14a5-421b-9d79-cd161cd964cc
📒 Files selected for processing (7)
docs-site/src/content/docs/guides/providers.mddocs-site/src/content/docs/ja/guides/providers.mddocs-site/src/content/docs/ko/guides/providers.mddocs-site/src/content/docs/ru/guides/providers.mddocs-site/src/content/docs/zh-cn/guides/providers.mdsrc/providers/quota.tstests/provider-quota.test.ts
Co-authored-by: OpenAI Codex <codex@openai.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/providers/quota.ts (1)
927-929: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftSuppress stale A6API reports when validation fails.
fetchA6apiQuotareturnsnullfor malformed, inconsistent, zero-limit, or non-success responses, butfetchProviderQuotaReportsatsrc/providers/quota.tsLines 936-981 treats every null result as a transient probe failure and restores the previous report. After one valid refresh, a later invalid A6API payload can therefore continue displaying stale credit usage instead of emitting no report, contradicting the fail-closed contract.Make A6API terminal failures distinguishable from transient failures (or explicitly evict/suppress that provider’s previous row), and add a regression that performs a valid refresh followed by a malformed refresh with the same cache key and expects no A6API report.
As per path instructions, malformed or internally inconsistent A6API billing totals must not produce a quota report.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/providers/quota.ts` around lines 927 - 929, Update fetchProviderQuotaReports and the fetchA6apiQuota path so malformed, inconsistent, zero-limit, and non-success A6API responses are distinguished from transient probe failures and do not restore or retain a previous cached report. Ensure a valid refresh followed by a malformed refresh with the same cache key produces no A6API report, and add the requested regression test.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/providers/quota.ts`:
- Around line 927-929: Update fetchProviderQuotaReports and the fetchA6apiQuota
path so malformed, inconsistent, zero-limit, and non-success A6API responses are
distinguished from transient probe failures and do not restore or retain a
previous cached report. Ensure a valid refresh followed by a malformed refresh
with the same cache key produces no A6API report, and add the requested
regression test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: be773c5a-5600-436e-b657-bdf451622ddf
📒 Files selected for processing (6)
docs-site/src/content/docs/ja/guides/providers.mddocs-site/src/content/docs/ko/guides/providers.mddocs-site/src/content/docs/ru/guides/providers.mddocs-site/src/content/docs/zh-cn/guides/providers.mdsrc/providers/quota.tstests/provider-quota.test.ts
Summary
a6apikey providers.Verification
bun test tests/provider-quota.test.ts(27 passed)bun run typecheckbun run privacy:scanbun test tests/quota-bars-rows.test.ts tests/provider-workspace-rail.test.ts(19 passed)bun run test: 5,883 passed; the initial clean-clone run had 2 module-resolution errors because GUI dependencies were not yet installed. Aftergui/bun install --frozen-lockfile, both affected suites passed.Checklist
Summary by CodeRabbit