Skip to content

feat: add xAI platform billing provider - #2472

Merged
steipete merged 5 commits into
steipete:mainfrom
SilentKnight87:feat/xai-platform-provider
Jul 29, 2026
Merged

feat: add xAI platform billing provider#2472
steipete merged 5 commits into
steipete:mainfrom
SilentKnight87:feat/xai-platform-provider

Conversation

@SilentKnight87

@SilentKnight87 SilentKnight87 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a separate xai provider for xAI developer-platform billing, closing the gap described in #1712: prepaid credit balance plus a 30-day daily USD spend dashboard, sourced exclusively from xAI's documented Management API (management-api.x.ai) with an explicit Management key + team ID. No Grok coupling: the existing Grok provider keeps consumer Grok/SuperGrok quota, and identity/credentials are never shared between the two surfaces.

  • Auth/settings: Management key (secure field) + team ID (plain field), following the Deepgram two-field pattern; ProviderConfig.apiKey/workspaceID map to XAI_MANAGEMENT_API_KEY/XAI_TEAM_ID. Inference API keys are rejected by the Management API and the docs/error copy say so.
  • Balance: GET /v1/billing/teams/{team_id}/prepaid/balance. The documented example records a $10 top-up as total.val = "-1000" (string USD cents, inverted ledger), so remaining balance = -cents/100. A 200 body without a parseable total is a hard parse error, never $0.00. Rendered as "Balance: $X.XX" via the same menu-card seam ZenMux/Neuralwatt use.
  • History: POST /v1/billing/teams/{team_id}/usage with the documented analyticsRequest (last 30 days UTC, TIME_UNIT_DAY, usd/AGGREGATION_SUM). Daily buckets render through the shared provider-cost-history inline dashboard (same path as Groq/OpenAI). History is best-effort: its failure keeps the balance (auth failures and cancellation still escalate). limitReached marks the snapshot estimated and labels the window "Last 30 days (partial)" instead of presenting truncated totals as exact.
  • Wiring: descriptor + implementation registries, config env projection + validation allowlist, CLI diagnose, widget switches, template SVG icon (distinct from Grok's, guarded by a new icon-distinctness test), docs page + provider tables + counts, CHANGELOG.
  • Moved ProviderIdentitySnapshot/UsageDataConfidence into their own file to keep UsageFetcher.swift under the file-length lint limit.

Commands run

  • swift build
  • swift test --filter XAIProviderTests (27 tests: request shape incl. exact analytics body, sign/unit mapping, malformed-200 guards, team-ID path-encoding + traversal rejection, error taxonomy 401/403/404/429/5xx, partial-success, limitReached, projections, Codable round-trip, registry, config projection, menu-card render)
  • make test — the only failing suites (SpendDashboardControllerTests, SpendDashboardTokenProvenanceTests, 13 issues) reproduce identically on a pristine main checkout at cc8da27c in the same environment, so they are pre-existing and unrelated; CodexAccountScopedRefreshTests is load-sensitive locally and passes clean (~3s) uncontended on both trees.
  • make check (SwiftFormat + SwiftLint strict — 0 violations)
  • node scripts/check-documentation-links.mjs, make docs-list
  • ./Scripts/regenerate-codex-parser-hash.sh write (CostUsageScanner case list touched)

Live behavior proof

End-to-end on a real account: @mitchins built this branch and ran CodexBarCLI usage --provider xai against their live account (capture with screenshot) — output renders Balance: $13.92 / Last 30 days: $6.67 exactly as implemented. They also verified both raw endpoints earlier (comment): the prepaid balance is a negative total.val numeric string in minor USD units (the inverted-ledger mapping implemented here), and the usage response matches the implemented contract (timeSeries, group/groupLabels, daily dataPoints with numeric USD values, boolean limitReached).

One semantic learned from live data and now documented in docs/xai.md: the balance endpoint reports the posted ledger — spend posts at billing-cycle close, so mid-cycle the ledger balance exceeds the Console's live remaining credit by the cycle's unposted spend. The live capture also surfaced a cosmetic plan-badge mangling ("Management Api"), fixed in a follow-up commit.

Closes #1712.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a85baf3e19

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +61 to +63
providerCost: ProviderCostSnapshot(
used: self.balanceUSD,
limit: 0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Render xAI prepaid credits as a balance in CLI text

When an xAI fetch succeeds, this creates a snapshot with no rate-limit windows and a providerCost whose used value is actually the prepaid balance and whose limit is 0. In CLI text mode, CLIRenderer.appendPrimaryLines falls back for any no-window providerCost to Cost: <used> / <limit>, so codexbar --provider xai will show a misleading Cost: $balance / 0.0-style line instead of the prepaid balance; xAI needs a CLI-specific balance line or should avoid the generic cost fallback shape.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in 3c0bdc0: xAI's balance-shaped providerCost is excluded from the generic no-window cost fallback, and the CLI text/card renderers now emit a dedicated Balance: $X.XX line plus the 30-day spend line (same pattern as the Devin/MiMo balance lines), covered by a new renderer test.

SilentKnight87 added a commit to SilentKnight87/CodexBar that referenced this pull request Jul 28, 2026
The generic no-window providerCost fallback printed the prepaid balance
as "Cost: 7.4 / 0.0", presenting money remaining as spend against a
zero budget. Exclude xAI's balance-shaped providerCost from that
fallback and add a dedicated Balance + spend-window line to the CLI
text, card body, and card extras renderers, matching the Devin/MiMo
balance-line pattern. Flagged by Codex review on steipete#2472.
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 5:23 PM ET / 21:23 UTC.

ClawSweeper review

What this changes

This PR adds an optional xAI Management API provider that reads a team’s prepaid balance and 30-day daily platform spend, then exposes it through CodexBar settings, CLI output, menus, dashboards, diagnostics, tests, and documentation.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep this PR open for maintainer acceptance rather than cleanup closure. It has credible live-account proof, focused provider coverage, and no supported correctness finding, but it deliberately adds a new optional credential-backed billing surface that needs an explicit product and support-boundary decision.

Priority: P2
Reviewed head: 1a302e74363c08814e7ce89cb2aaad3eb114a53f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) This is a well-supported provider implementation with strong real behavior proof and no concrete code finding; its remaining gate is maintainer product acceptance of the credential-backed provider surface.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): A redacted real-account run of the PR branch shows the xAI CLI provider returning the implemented balance and 30-day spend output, with a screenshot and separate live endpoint-contract confirmation; no additional contributor proof is needed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): A redacted real-account run of the PR branch shows the xAI CLI provider returning the implemented balance and 30-day spend output, with a screenshot and separate live endpoint-contract confirmation; no additional contributor proof is needed.
Evidence reviewed 5 items Live after-fix behavior proof: A real-account run of the PR branch showed CodexBarCLI usage --provider xai rendering a prepaid balance and 30-day spend; the accompanying screenshot and redacted raw-contract confirmation support the implemented response mapping.
Provider boundary and configuration: The added xAI descriptor, settings reader, environment projection, and fetcher use a distinct Management API key plus team ID, while the PR documentation explicitly separates xAI platform billing from Grok consumer quota.
Credential and response safeguards: The proposed fetcher defines distinct errors for missing configuration, invalid team IDs, authentication rejection, rate limits, API failures, and parse failures; the supplied focused test suite covers endpoint shape, malformed successful responses, traversal rejection, and HTTP error taxonomy.
Findings None None.
Security None None.

How this fits together

CodexBar collects usage data from configured AI providers and turns each provider snapshot into menu-bar, CLI, dashboard, and diagnostic output. The new xAI path accepts a Management API key and team ID, requests billing data from xAI, and renders prepaid-credit and spend-history information separately from the existing Grok consumer-subscription provider.

flowchart LR
A[xAI Management key and team ID] --> B[Provider configuration]
B --> C[xAI Management API]
C --> D[Balance and daily spend snapshot]
D --> E[CLI and menu output]
D --> F[Cost-history dashboard]
D --> G[Diagnostics and docs]
Loading

Decision needed

Question Recommendation
Should CodexBar accept and support an optional xAI Management API provider that persists a Management key and team ID to show developer-platform prepaid balance and spend separately from Grok consumer quota? Accept the provider boundary: Merge the optional xAI Management API provider with its separate credential, partial-history, and posted-ledger semantics.

Why: The implementation and live proof support the proposed behavior, but only maintainers can choose whether this new credential-backed provider and its ongoing API/support obligation belong in the product.

Before merge

  • Resolve merge risk (P1) - Merging creates a new persisted xAI Management API key and team-ID setup path; maintainers should explicitly accept the credential-handling and user-support boundary even though the provider is disabled by default.
  • Resolve merge risk (P1) - The balance endpoint is documented and proven to represent a posted ledger rather than necessarily the Console’s live remaining credit mid-cycle; the UI/docs must continue to make that semantic distinction clear.
  • Resolve merge risk (P1) - The change spans 36 files across core snapshots, configuration, UI/CLI rendering, widgets, and provider inventories, so future provider-registry changes must preserve the new xAI cases consistently.
  • Complete next step (P2) - The patch is ready for ordinary maintainer product review; no narrow mechanical defect remains for a repair worker to address.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Change surface 36 files affected; 1,504 added and 129 removed The provider is integrated across fetching, configuration, rendering, diagnostics, widgets, tests, and documentation rather than being an isolated API client.
Focused regression coverage 1 new provider test file with 570 added lines The PR supplies targeted coverage for request shape, parsing, errors, configuration projection, registries, and rendered output.

Merge-risk options

Maintainer options:

  1. Accept the documented provider contract (recommended)
    Merge after explicitly accepting the Management-key/team-ID support boundary and the documented posted-ledger balance semantics.
  2. Pause for product scope
    Defer the PR if maintainers do not want to own a separate xAI billing credential flow alongside the existing Grok consumer-quota integration.

Technical review

Best possible solution:

Accept the provider only if maintainers want CodexBar to support xAI developer-platform billing as a distinct optional surface, retaining its separate credentials, partial-history labeling, posted-ledger documentation, and focused regression coverage.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR adds a new optional provider rather than repairing an established failing behavior. Its intended live behavior is nevertheless demonstrated by a redacted real-account CLI capture and endpoint-contract confirmation.

Is this the best way to solve the issue?

Yes, conditionally: a distinct xAI Management API provider is the narrowest maintainable design because it avoids coupling platform billing credentials and identity with the existing Grok consumer-quota provider. Maintainer approval is still required for the new product and credential surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ab31038ed8cf.

Labels

Label justifications:

  • P2: This is a useful optional provider capability with bounded impact, not an urgent regression in an existing user workflow.
  • merge-risk: 🚨 auth-provider: The PR adds a Management API credential and team identifier to settings and environment projection, creating a new authentication and support path.
  • merge-risk: 🚨 compatibility: Existing users must not confuse the new developer-platform xAI billing source with the separate Grok consumer-subscription provider or its credential model.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): A redacted real-account run of the PR branch shows the xAI CLI provider returning the implemented balance and 30-day spend output, with a screenshot and separate live endpoint-contract confirmation; no additional contributor proof is needed.
  • proof: sufficient: Contributor real behavior proof is sufficient. A redacted real-account run of the PR branch shows the xAI CLI provider returning the implemented balance and 30-day spend output, with a screenshot and separate live endpoint-contract confirmation; no additional contributor proof is needed.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. A redacted real-account run of the PR branch shows the xAI CLI provider returning the implemented balance and 30-day spend output, with a screenshot and separate live endpoint-contract confirmation; no additional contributor proof is needed.

Evidence

What I checked:

  • Live after-fix behavior proof: A real-account run of the PR branch showed CodexBarCLI usage --provider xai rendering a prepaid balance and 30-day spend; the accompanying screenshot and redacted raw-contract confirmation support the implemented response mapping. (1a302e74363c)
  • Provider boundary and configuration: The added xAI descriptor, settings reader, environment projection, and fetcher use a distinct Management API key plus team ID, while the PR documentation explicitly separates xAI platform billing from Grok consumer quota. (Sources/CodexBarCore/Providers/XAI/XAIProviderDescriptor.swift:1, 1a302e74363c)
  • Credential and response safeguards: The proposed fetcher defines distinct errors for missing configuration, invalid team IDs, authentication rejection, rate limits, API failures, and parse failures; the supplied focused test suite covers endpoint shape, malformed successful responses, traversal rejection, and HTTP error taxonomy. (Sources/CodexBarCore/Providers/XAI/XAIBillingFetcher.swift:1, 1a302e74363c)
  • Current review continuity: The prior completed review cycles reported no unresolved code findings. The latest head incorporates the maintainer-authored rebase/hash update, and the prior bot review correctly left the remaining decision as whether to accept this new provider surface. (Sources/CodexBarCore/Generated/CodexParserHash.generated.swift:1, 1a302e74363c)
  • Repository policy application: The repository policy requires provider data to remain siloed and treats the release changelog as release-owned. This PR’s stated separation of xAI and Grok credentials is aligned with the former, and the maintainer already removed the contributor changelog entry in the current branch history. (AGENTS.md:1, ab31038ed8cf)

Likely related people:

  • steipete: The current PR head includes a steipete-authored merge/rebase update, and accepting an optional persisted provider credential plus its support semantics is a repository product decision rather than a mechanical contributor fix. (role: recent branch integrator and likely product decision owner; confidence: medium; commits: c4313cac2ef1, 1a302e74363c; files: Sources/CodexBarCore/Providers/Providers.swift, Sources/CodexBarCore/Config/ProviderConfigEnvironment.swift, docs/xai.md)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record maintainer acceptance or deferral of the xAI Management API credential and support boundary.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-28T02:43:10.608Z sha 3c0bdc0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-28T12:34:54.415Z sha 3c0bdc0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-28T14:58:46.764Z sha 589a419 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T13:54:05.662Z sha dc21474 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T16:11:20.517Z sha c4313ca :: needs maintainer review before merge. :: none

@mitchins

Copy link
Copy Markdown

Verified against the Management API with a management key (raw responses withheld). The prepaid-balance response represents remaining prepaid credit as a negative total.val numeric string in minor USD units; I omitted the complete transaction-history array and all identifiers. The current value no longer exactly matches the earlier Console snapshot, so I’m deliberately not asserting that old amount.

The usage response has timeSeries (one series), group/groupLabels, seven daily dataPoints, each with a timestamp and numeric USD values, plus a boolean limitReached. For privacy I have redacted timestamps and rounded amounts. This confirms the documented inverted-ledger balance mapping and the usage response contract on live data.

@clawsweeper re-review

@SilentKnight87

Copy link
Copy Markdown
Contributor Author

Thanks @mitchins — that closes the live-contract question: inverted-ledger balance (negative cent-string total.val = remaining credit) and the timeSeries/dataPoints/limitReached usage shape both confirmed on a real account, exactly as implemented. PR body updated with the proof reference.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 28, 2026
@SilentKnight87

Copy link
Copy Markdown
Contributor Author

Status for the maintainer: the API contract is now confirmed on live data (thanks again @mitchins), and patch quality shows no findings across both review passes. The remaining bot gate is an end-to-end capture — this PR's build rendering a real account — which by nature needs an account holder:

gh repo clone SilentKnight87/CodexBar -- --branch feat/xai-platform-provider --depth 1
cd CodexBar
swift build -c release --product CodexBarCLI
XAI_MANAGEMENT_API_KEY="" XAI_TEAM_ID="" ./.build/release/CodexBarCLI usage --provider xai

The only account-derived lines in that output are Balance: $X.XX and Last 30 days: $Y.YY — no identifiers are printed, and rounding the amounts before posting is fine. @mitchins no obligation at all (the curl verification was already a big help), but if this is easy for you it would close the last gate. Alternatively @steipete can accept contract-plus-fixture validation per the review's own maintainer options — happy to go whichever way you prefer.

@mitchins

mitchins commented Jul 28, 2026

Copy link
Copy Markdown

Direct output on my current account:

== xAI (api) ==
Balance: $13.92
Last 30 days: $6.67
Plan: Management Api
clipboard

This is a bit weird, but not unexpected.
Balance includes your total spend in the last 30 days plus the current balance.

Which is probably the most sensible thing here.

SilentKnight87 added a commit to SilentKnight87/CodexBar that referenced this pull request Jul 28, 2026
Route xAI through cleanPlanName so the CLI plan badge shows
"Management API" instead of the .capitalized mangling "Management Api"
seen in live verification on steipete#2472. Document that the balance is the
posted prepaid ledger: spend posts at billing-cycle close, so mid-cycle
the ledger balance exceeds the Console's live remaining credit by the
cycle's unposted spend, as confirmed on a real account.
@SilentKnight87

Copy link
Copy Markdown
Contributor Author

Huge thanks @mitchins — that's the full end-to-end proof, and your balance observation was a genuinely useful catch. It matches the ledger schema: entries are keyed by billing period (spendBpKeyYear/spendBpKeyMonth), so spend posts at cycle close and the mid-cycle posted balance = live remaining + the cycle's unposted spend — which is what your numbers show. I've documented that in docs/xai.md and fixed the "Management Api" plan-badge casing your capture surfaced (589a419). PR body updated with the runtime proof.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 28, 2026
@SilentKnight87
SilentKnight87 force-pushed the feat/xai-platform-provider branch from 589a419 to 8c57b07 Compare July 28, 2026 21:03
SilentKnight87 added a commit to SilentKnight87/CodexBar that referenced this pull request Jul 28, 2026
The generic no-window providerCost fallback printed the prepaid balance
as "Cost: 7.4 / 0.0", presenting money remaining as spend against a
zero budget. Exclude xAI's balance-shaped providerCost from that
fallback and add a dedicated Balance + spend-window line to the CLI
text, card body, and card extras renderers, matching the Devin/MiMo
balance-line pattern. Flagged by Codex review on steipete#2472.
SilentKnight87 added a commit to SilentKnight87/CodexBar that referenced this pull request Jul 28, 2026
Route xAI through cleanPlanName so the CLI plan badge shows
"Management API" instead of the .capitalized mangling "Management Api"
seen in live verification on steipete#2472. Document that the balance is the
posted prepaid ledger: spend posts at billing-cycle close, so mid-cycle
the ledger balance exceeds the Console's live remaining credit by the
cycle's unposted spend, as confirmed on a real account.
@SilentKnight87

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (02b4ba27) per the review's refresh ask — clean rebase, no conflicts, no provider-surface drift (main's 50 commits added no providers and didn't touch the vendored scanner). Re-verified on the new base: swift build clean, all 28 xAI provider tests plus the CLI output suites green, make check at 0 violations. The full local suite's only failing groups (Kiro probe/race and a Codex refresh-coalescing test) are load-sensitive and pass standalone; they're untouched by this branch. Head is now 8c57b071.

@SilentKnight87
SilentKnight87 force-pushed the feat/xai-platform-provider branch from 8c57b07 to dc21474 Compare July 29, 2026 12:34
SilentKnight87 added a commit to SilentKnight87/CodexBar that referenced this pull request Jul 29, 2026
The generic no-window providerCost fallback printed the prepaid balance
as "Cost: 7.4 / 0.0", presenting money remaining as spend against a
zero budget. Exclude xAI's balance-shaped providerCost from that
fallback and add a dedicated Balance + spend-window line to the CLI
text, card body, and card extras renderers, matching the Devin/MiMo
balance-line pattern. Flagged by Codex review on steipete#2472.
SilentKnight87 added a commit to SilentKnight87/CodexBar that referenced this pull request Jul 29, 2026
Route xAI through cleanPlanName so the CLI plan badge shows
"Management API" instead of the .capitalized mangling "Management Api"
seen in live verification on steipete#2472. Document that the balance is the
posted prepaid ledger: spend posts at billing-cycle close, so mid-cycle
the ledger balance exceeds the Console's live remaining credit by the
cycle's unposted spend, as confirmed on a real account.
@SilentKnight87

Copy link
Copy Markdown
Contributor Author

Rebased again onto current main (fcf75fb8) — the conflicts came from the new qwencloud/zoommate providers landing upstream; xai now sits after zoommate at the enum tail and all provider counts/docs lists reflect 66. One merge note: upstream added a Claude prepaid-balance CLI line in the same renderer spots as xAI's — both features are kept side by side. Verified on the new base: swift build clean, registry/docs-order/icon gate suites plus the xAI and CLI suites green (93 tests), make check 0 violations, and the full make test suite passes with zero failing groups. Head is dc21474f, PR is mergeable again.

SilentKnight87 and others added 4 commits July 29, 2026 09:01
Add a separate xai provider for xAI developer-platform billing from the
documented Management API (management key + team ID): prepaid credit
balance from /prepaid/balance (inverted ledger in string USD cents; a
200 without a parseable total is an error, never $0.00) and a 30-day
daily USD spend dashboard from /usage via the shared cost-history seam.
History is best-effort enrichment - its failure keeps the balance while
auth failures and cancellation escalate - and limitReached marks the
window "(partial)" with estimated confidence instead of exact. No
coupling to the Grok subscription provider. Covers descriptor, fetcher,
settings reader/store, registries, config projection, widget and CLI
switches, template icon with a Grok-distinctness test, docs, and
fixture-based tests on stubbed transports. Moves ProviderIdentitySnapshot
to its own file to hold the UsageFetcher length limit. (steipete#1712)
The generic no-window providerCost fallback printed the prepaid balance
as "Cost: 7.4 / 0.0", presenting money remaining as spend against a
zero budget. Exclude xAI's balance-shaped providerCost from that
fallback and add a dedicated Balance + spend-window line to the CLI
text, card body, and card extras renderers, matching the Devin/MiMo
balance-line pattern. Flagged by Codex review on steipete#2472.
Route xAI through cleanPlanName so the CLI plan badge shows
"Management API" instead of the .capitalized mangling "Management Api"
seen in live verification on steipete#2472. Document that the balance is the
posted prepaid ledger: spend posts at billing-cycle close, so mid-cycle
the ledger balance exceeds the Console's live remaining credit by the
cycle's unposted spend, as confirmed on a real account.
@steipete
steipete force-pushed the feat/xai-platform-provider branch from dc21474 to c4313ca Compare July 29, 2026 16:07
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. label Jul 29, 2026
@steipete
steipete merged commit c801317 into steipete:main Jul 29, 2026
9 checks passed
@steipete

Copy link
Copy Markdown
Owner

Merged after full verification — owner-approved (Peter) as a first-class provider.

xAI platform billing now surfaces prepaid ledger balance and 30-day spend from the xAI Management API, with credentials siloed from the Grok provider (verified during review that billing credentials can never be read from or attributed to Grok), sound team validation, error taxonomy, and honest partial-data semantics rather than a fabricated zero balance.

Maintainer changes: removed the contributor CHANGELOG edit (maintainer adds changelog on merge), rebased through the recent provider landings, and regenerated CodexParserHash.generated.swift after the merge conflict. 28 focused tests; exact-head CI green. Thanks @SilentKnight87 for the implementation and @mitchins for the independent real-account verification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: XAI Platform

3 participants