Skip to content

fix(agents): avoid API key billing copy for OAuth - #80895

Closed
TurboTheTurtle wants to merge 2 commits into
openclaw:mainfrom
TurboTheTurtle:fix/anthropic-oauth-billing-message
Closed

TurboTheTurtle wants to merge 2 commits into
openclaw:mainfrom
TurboTheTurtle:fix/anthropic-oauth-billing-message

Conversation

@TurboTheTurtle

@TurboTheTurtle TurboTheTurtle commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Make billing error copy auth-mode aware so OAuth/token-backed Anthropic routes do not tell users to top up an API key.
  • Thread the active auth profile mode through assistant error formatting, failover error creation, lifecycle terminal formatting, and final payload synthesis.
  • Preserve the existing API-key billing/top-up message for API-key and legacy/default callers.

Root Cause

Billing-shaped errors were formatted without knowing whether the active Anthropic credential was an API key, OAuth, or token. Once a Claude CLI/Max OAuth error was classified as billing-shaped, it reused API-key top-up wording even though there was no API key to top up.

Real behavior proof

  • Behavior or issue addressed: Anthropic OAuth/Claude Max billing-shaped usage errors now produce neutral recovery copy and do not tell users to top up an API key.
  • Real environment tested: Local OpenClaw checkout on branch fix/anthropic-oauth-billing-message, running production error-formatting modules through node --import tsx.
  • Exact steps or command run after this patch: Ran a live Node command that imports formatAssistantErrorText, formats the same Anthropic usage-cap-shaped error once with authProfileMode: "oauth" and once with authProfileMode: "api_key", and prints the observed user-facing text checks.
  • Evidence after fix: Terminal output:
{
  "oauth": "⚠️ Anthropic (claude-sonnet-4-6) returned a temporary account or usage-limit error while using OAuth credentials. OpenClaw will retry when the provider recovers; please try again in a minute.",
  "oauthMentionsApiKey": false,
  "oauthMentionsTopUp": false,
  "apiKeyMentionsApiKey": true
}
  • Observed result after fix: The real formatter returned OAuth recovery wording for the OAuth path, oauthMentionsApiKey was false, oauthMentionsTopUp was false, and the API-key path still retained API-key billing copy.
  • What was not tested: I did not run against a live Anthropic Max account or Telegram channel; the live proof exercises OpenClaw’s production formatter path with the reported billing-shaped OAuth metadata.

Validation

  • pnpm test src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-runner/run/assistant-failover.test.ts -- --reporter=verbose
  • pnpm test src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -- --reporter=verbose
  • pnpm check:changed -- --base upstream/main
  • git diff --check

Attribution

If this PR is squashed or reworked, please preserve author attribution or include:

Co-authored-by: Andy Ye <[email protected]>

Closes #80877

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 12, 2026
@clawsweeper

clawsweeper Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR makes Anthropic billing-shaped error formatting auth-mode aware and threads the active auth profile mode through assistant error, failover, lifecycle, subscription, and payload paths.

Reproducibility: yes. Source inspection shows current main always emits API-key/top-up billing copy and lacks credential mode at the formatter boundary, while the linked issue gives a concrete Anthropic Max OAuth path.

Real behavior proof
Sufficient (terminal): The PR body includes after-fix terminal output from the production formatter path showing OAuth text avoids API-key/top-up wording while API-key text remains unchanged.

Next step before merge
No automated repair is needed; the PR needs normal maintainer review, CI/mergeability judgment, and landing handling.

Security
Cleared: The diff only changes typed error-formatting plumbing and tests; it does not alter secrets handling, dependencies, CI, install scripts, or code-loading paths.

Review details

Best possible solution:

Land this narrow formatter/context propagation fix after ordinary maintainer review, keeping API-key billing copy unchanged while using neutral recovery copy for OAuth/token-backed credentials.

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

Yes. Source inspection shows current main always emits API-key/top-up billing copy and lacks credential mode at the formatter boundary, while the linked issue gives a concrete Anthropic Max OAuth path.

Is this the best way to solve the issue?

Yes. Passing the already-known auth profile mode into the central formatter and downstream synthesis points is the narrowest maintainable fix, and it avoids changing billing classification semantics for API-key callers.

Acceptance criteria:

  • pnpm test src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-runner/run/assistant-failover.test.ts -- --reporter=verbose
  • pnpm test src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -- --reporter=verbose
  • pnpm check:changed -- --base upstream/main
  • git diff --check

What I checked:

Likely related people:

  • @steipete: Blame and recent commits show repeated work across the current billing formatter, assistant error formatting, failover, and payload synthesis surfaces touched by this PR. (role: recent area contributor; confidence: high; commits: 0eb50f9f8d00, 9180173f9a79, 936c02e22c98; files: src/agents/pi-embedded-helpers/sanitize-user-facing-text.ts, src/agents/pi-embedded-helpers/errors.ts, src/agents/pi-embedded-runner/run/assistant-failover.ts)
  • @vincentkoc: History shows related work extracting the user-facing text sanitizer and adding adjacent agent error-copy behavior in the same helper surface. (role: feature-history contributor; confidence: medium; commits: 35664d5447a4, f1ad5e27e035, f718ba66018a; files: src/agents/pi-embedded-helpers/sanitize-user-facing-text.ts, src/agents/pi-embedded-helpers/errors.ts)
  • @shakkernerd: Recent history shows auth profile rotation work adjacent to the assistant failover path where this PR threads credential mode. (role: adjacent auth/failover contributor; confidence: medium; commits: efa8c83200ab; files: src/agents/pi-embedded-runner/run/assistant-failover.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against a978f0fe3671.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@TurboTheTurtle

Copy link
Copy Markdown
Contributor Author

Closing this out to reduce the older open PR queue. It had sufficient proof and green checks, but it has been sitting without much maintainer movement and lacks the newer ready-for-maintainer-look/automerge signals. Happy to reopen or re-spin if maintainers want this direction later.

@TurboTheTurtle
TurboTheTurtle deleted the fix/anthropic-oauth-billing-message branch May 20, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatBillingErrorMessage misfires for Anthropic Max OAuth — broadcasts "top up your API key" when there is no API key

1 participant