feat: add Anthropic and OpenAI cost history#100672
Conversation
|
Land-ready proof for
Known gap: authenticated successful Admin API proof was not run because no approved live Anthropic/OpenAI Admin key was available. Successful pagination and aggregation paths are covered with mocked provider responses; real endpoint discovery/auth failure routing is live-proven. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3c2c01c9d
ℹ️ 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".
| const oauth = await ctx.resolveOAuthToken(); | ||
| if (oauth) { | ||
| return oauth; |
There was a problem hiding this comment.
Check stored OpenAI admin keys before OAuth
When a user has an existing ChatGPT/Codex OAuth profile and then stores an OpenAI Admin API key in an auth profile or SecretRef, this returns the OAuth token before the stored key candidates are inspected, so fetchOpenAIUsage takes the Codex quota path and the new Admin cost history never appears. The Anthropic path already classifies stored admin candidates before OAuth; OpenAI should similarly select a stored sk-admin-... candidate before falling back to OAuth.
Useful? React with 👍 / 👎.
|
Codex review: found issues before merge. Reviewed July 6, 2026, 6:54 AM ET / 10:54 UTC. Summary Reproducibility: not applicable. this is a feature PR; source inspection confirms current main lacks provider costHistory and Admin API history collection. Review metrics: 3 noteworthy metrics.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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: Fix the usage-credential boundary and OpenAI currency handling before merge, then keep the Admin history feature behind the provider-owned plugin contract with maintainer-approved docs and tests. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a feature PR; source inspection confirms current main lacks provider costHistory and Admin API history collection. Is this the best way to solve the issue? No: the owner-boundary design is plausible, but the current implementation is not the best merge state until usage-only env vars cannot become inference markers and OpenAI currency is preserved. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cbf9acff374c. Label changesLabel changes:
Label justifications:
Evidence reviewedSecurity concerns:
Acceptance criteria:
What 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 (4 earlier review cycles)
|
a07c864 to
e6ae727
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e6ae7278f8
ℹ️ 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".
| const cacheWriteTokens = | ||
| nonNegativeInteger(cacheCreation?.ephemeral_1h_input_tokens) + | ||
| nonNegativeInteger(cacheCreation?.ephemeral_5m_input_tokens); |
There was a problem hiding this comment.
Read Anthropic cache-write totals from top-level fields
When the Admin Usage API returns prompt-cache creation usage, Anthropic's Usage Report schema exposes the write counts as top-level cache_creation_5m_input_tokens and cache_creation_1h_input_tokens fields, not as result.cache_creation.ephemeral_*. In any report with cache writes this keeps cacheWriteTokens at zero and undercounts totalTokens/model totals in the new cost-history card even though the provider returned the data; the current unit test mocks the non-API shape, so it does not catch the regression.
Useful? React with 👍 / 👎.
e6ae727 to
5d6bb1c
Compare
|
@clawsweeper re-review The prior finding reviewed Proof: 57 provider auth/docs/manifest tests passed on Testbox |
|
🦞🧹 I asked ClawSweeper to review this item again. |
5d6bb1c to
94e5244
Compare
0ee7145 to
96a5d94
Compare
be55a7a to
bdbc957
Compare
3e9c50d to
f0cdcd3
Compare
f0cdcd3 to
caea6bd
Compare
|
Merged via squash.
|
* feat(providers): add admin cost history * fix(ui): sync cron raw-copy baseline * fix(usage): harden provider cost credentials * fix(ui): refresh raw-copy baseline * docs: refresh documentation map * fix(ci): sync provider usage baselines * fix(ui): hide zero-cost history bars * docs(changelog): defer provider cost note
* feat(providers): add admin cost history * fix(ui): sync cron raw-copy baseline * fix(usage): harden provider cost credentials * fix(ui): refresh raw-copy baseline * docs: refresh documentation map * fix(ci): sync provider usage baselines * fix(ui): hide zero-cost history bars * docs(changelog): defer provider cost note
What Problem This Solves
OpenClaw could show quota, credits, or balances for several providers, but it did not expose provider-reported daily spend history for Anthropic or OpenAI. That left the Usage page materially behind CodexBar for the two main coding providers and made model/cache/category cost analysis unavailable inside OpenClaw.
Closes #100608.
Why This Change Was Made
This brings the provider API surface to CodexBar parity. It intentionally does not import local session logs from other applications; OpenClaw's existing transcript estimates remain a separate local view.
User Impact
Users with Anthropic Admin credentials or a dedicated
OPENAI_ADMIN_KEYcan see actual provider-billed USD history in OpenClaw's Usage page. Existing Claude and Codex OAuth users keep their current plan/quota cards. OpenAI inference credentials are never forwarded to organization APIs because they may belong to custom, Azure, or agent-local endpoints. Other providers continue to report their existing balance, budget, credits, or quota data unchanged.Evidence
tbx_01kwtw19xh4t51hehrep3wpwf4(quick-crab)pnpm check:changed: passed on the full touched surfacepnpm build: passed after the final SecretRef-aware auth change, including SDK export and production Control UI bundle checksAdmin API key requiredfor dummy credentials, proving automatic discovery, provider routing, and error selection without exposing credential materialtbx_01kwv5sg25xc1dg84q1zc0pdsk; enabled-vs-disabled plugin trust regression: 29 tests passed ontbx_01kwv6ddxvrdj1m274j8tgphfrtbx_01kwv6fhhkz65ss4tj0k91gk1tAuthenticated successful Admin API proof was not run because no approved live Anthropic/OpenAI Admin key was available in the configured credential stores. The real endpoint failure path and fully mocked success path are both covered.
Before / After
Proof asset release