Add ai& spend provider#2256
Conversation
|
Codex review: found issues before merge. Reviewed July 17, 2026, 3:00 PM ET / 19:00 UTC. Summary Reproducibility: not applicable. as a bug reproduction. The contributor nevertheless supplied a high-signal redacted terminal run against a funded ai& organization, plus an invalid-key runtime path. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: If the repository owner wants ai& supported in core, retain the default-disabled API-key-only design, move registration to the current macro path, and correct the future-dated narrative before merging. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction. The contributor nevertheless supplied a high-signal redacted terminal run against a funded ai& organization, plus an invalid-key runtime path. Is this the best way to solve the issue? Unclear until product direction is confirmed. The API-key-only, default-disabled design is a narrow implementation path, but core inclusion itself needs explicit owner approval and the registration path must follow current architecture. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 863241aa5a29. Label changesLabel justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
Review history (9 earlier review cycles; latest 8 shown)
|
844afa9 to
58d55b4
Compare
58d55b4 to
927697e
Compare
927697e to
0cc7904
Compare
Sum 30-day organization spend from ai&'s documented request-log API with an org-scoped API key (AIAND_API_KEY or ~/.codexbar/config.json), parsing per-request cost strings as exact decimals in the org's billing currency and following dual-cursor pagination capped at 10 pages (capped totals are labeled partial, never silently truncated). ai& is prepaid with no quota windows, so the snapshot carries only the cost figure and no rate windows. Covers descriptor, fetcher, settings reader/store, registries, widget and CLI switches, provider icon, and fixture-based tests.
Route the uncapped ai& cost snapshot through the generic API-spend menu section (spend-only providers with limit 0 are otherwise hidden), register the icon slug in the resource test, and cover the menu card rendering.
Add docs/aiand.md, list ai& in the provider table and sections, mention AIAND_API_KEY in configuration docs, and record the change in the changelog.
0cc7904 to
4c2d47e
Compare
Live funded-account proof (redacted)Run on 2026-07-18 against a real, funded ai& organization (billing currency JPY), key redacted, on this PR's head. What live testing found first: the initial implementation followed the documented $ export AIAND_API_KEY=sk-REDACTED
$ codexbar usage --provider aiand --json
[{"provider":"aiand","usage":{"dataConfidence":"exact","providerCost":{"used":1183.622885,
"currencyCode":"JPY","updatedAt":"2026-07-17T17:04:00Z","period":"Last 30 days","limit":0},
"primary":null,"secondary":null,"tertiary":null,"updatedAt":"2026-07-17T17:04:00Z"},"source":"api"}]
$ codexbar usage --provider aiand
== ai& (api) ==
Cost: 1183.6 / 0.0
$ echo $?
0
$ AIAND_API_KEY=sk-WRONG codexbar usage --provider aiand
Error: ai& rejected the API key. Create a new key at console.aiand.com and update Settings.
$ echo $?
1The org's 391 requests over the window (4 log pages) sum to ¥1,183.62. The menu app renders this through the shared API-spend card with proper JPY formatting (locked in by a unit test asserting the |
|
Merged as Verification:
Thank you @jethac for the provider implementation and live funded-account proof. |
Adds ai& (aiand.com) as a spend-only provider.
Why this provider fits CodexBar
ai& is an OpenAI/Anthropic-compatible inference gateway that positions itself as a backend for coding agents — its docs ship dedicated integration guides for Claude Code, Codex CLI, and opencode. Measured against the provider bar articulated in #1997 and #1367:
GET https://api.aiand.com/analytics/summary?range=30daysis a public, documented endpoint (docs) described as the billing-grade aggregate. No scraping, no undocumented endpoints.sk-API key, sent only as anAuthorization: Bearerheader (asserted in tests). No cookies, no JWT/session import, no browser access. Key stored via the standard CodexBar config-file /AIAND_API_KEYpath.ProviderHTTPTransportStubthroughout; no live calls in the suite.What it shows
Last-30-days organization spend, in the organization's own billing currency (ai& bills in USD or JPY per org). Spend is summed from the documented request-log endpoint (
GET /logs) with dual-cursor pagination andDecimalmoney arithmetic, because — as live testing with a funded account revealed — the/analytics/summaryendpoint's documentedcost_usdfield does not exist in the live API, and/analytics/metricshas no cost series either;/logsmatches its documentation exactly and is the only public source of cost. The fetch is capped at 10 pages (1,000 newest requests); if an org exceeds that, the row is labeled "Last 30 days (partial)" with downgraded data confidence — no silent truncation. A window with zero priced rows shows the provider's no-data path rather than a zero in a guessed currency, since the billing currency is only observable from the account's own log rows. ai& is prepaid with no quota windows, so no rate windows are synthesized — same rule LiteLLM applies when no budget exists. The credit balance is console-only (no public API), so it is deliberately not shown rather than guessed at.Commits
AiAndProviderTests(17 tests: real-shape log fixtures with JPY as the primary currency, dual-cursor pagination, page-cap partial labeling, mixed-currency and no-currency edge cases, exactDecimalsummation, bearer-only credential, 401/402/429 mapping, parse failures, registry presence).MenuCardView+Costs), icon-resource test slug, menu-card rendering test. Without the membership line a spend-only provider is silently invisible in the menu — the new test locks the rendering in.docs/aiand.md(auth, data source, 120 s server-side cache caveat, org-scoped key note, troubleshooting), providers.md row + section, configuration.md, CHANGELOG.Verification
4c2d47ec): https://github.com/steipete/CodexBar/actions/runs/29598984940 — lint, both Linux CLI builds, both macOS test shards, aggregate check, GitGuardian all pass.make checkclean (SwiftFormat 0 changes, SwiftLint 0 violations in 1520 files).make test: 691 selections, 58/58 groups green, 0 failures.swift test --filter AiAndProviderTests: 17/17.CodexBarCLI config providerslistsaiand: disabled (ai&);usage --provider aiand(and aliasesai&/ai-and) exits with the standard "No available fetch strategy" error — identical to ZenMux's no-key path.Updates since first review
Rebased onto current main (only conflict: the generated Codex parser hash, regenerated via
Scripts/regenerate-codex-parser-hash.sh).Adopted the new curated confetti palette introduced on main: the deprecated 3-arg
ProviderBrandinginit's[color, color]fallback failsProviderRegistryTestson current main, so the descriptor now provides a 3-color palette (base0xE25C2B, tint0xF2A17E, dark neutral0x33231C).Addressed the review finding on the settings subtitle: now path-neutral ("Stored in CodexBar's config file") instead of naming only the legacy
~/.codexbar/config.json— new installs resolve~/.config/codexbar/config.json. (ZenMux's subtitle has the same staleness on main; happy to fix that in a follow-up if wanted.)Rebased over the Neuralwatt provider landing (Add Neuralwatt provider #2220): union-merged the shared registration lists, regenerated the vendored-parser hash, and corrected the advertised provider count to 62 — both branches had bumped it to the same "61", so git merged the count strings silently while the registry gained two providers;
make check's count assertions caught it.Live-key verification drove a fetcher rework (2026-07-18): the documented
/analytics/summarycost_usdfield turned out not to exist in the live API, so spend now comes from the documented/logsendpoint (per-request decimal cost + per-org currency). See the live-proof comment below for the redacted transcript.docs/aiand.mdrecords the docs-vs-API discrepancy.Notes for review
currentColor, stroke conventions matching LiteLLM/Bedrock). Happy to swap in a traced ai& brand asset if preferred.&isn't a valid Swift identifier, so the slug isaiand(enum case, CLI name, config key, asset name) withai&/ai-andas CLI aliases; the display name staysai&.🤖 Generated with Claude Code