Skip to content

fix(anthropic): move oversized OAuth system prompt to user prefix - #13609

Closed
0xyg3n wants to merge 1 commit into
NousResearch:mainfrom
0xyg3n:fix/oauth-system-prompt-overflow
Closed

fix(anthropic): move oversized OAuth system prompt to user prefix#13609
0xyg3n wants to merge 1 commit into
NousResearch:mainfrom
0xyg3n:fix/oauth-system-prompt-overflow

Conversation

@0xyg3n

@0xyg3n 0xyg3n commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Problem

OAuth / Claude Code subscription requests via anthropic_messages fail with a 400 when the system field contains custom content beyond the CC identity block:

400 invalid_request_error: You're out of extra usage.
Add more at claude.ai/settings/usage and keep going.

The error wording points at quota, but the account actually has usage available — the same payload sent directly with a pay-per-token API key returns 200. The check is specific to the OAuth / subscription route and is triggered by the size/content of system once it goes beyond the basic CC identity string.

This breaks any downstream that ships a non-trivial system prompt (custom agents, SOUL-style personas, extended tool guides) while using a Claude Code subscription token.

Fix

Keep only the CC identity block in system and fold any additional system blocks into a [CONTEXT]...[/CONTEXT] user-message prefix followed by an assistant Understood. acknowledgement. Content is preserved verbatim — only the transport slot changes.

The change is inside the existing if is_oauth: branch in build_anthropic_kwargs, so it only affects OAuth code paths. Non-OAuth requests (x-api-key, Bedrock, third-party Anthropic-compat endpoints) are untouched.

Test

Reproduced and verified against the Anthropic API on the latest main (b2111a2b):

  • Before: large system via OAuth → 400 invalid_request_error with the quota text.
  • After: same content, CC identity in system + rest in [CONTEXT] user prefix → 200, response text identical, latency unchanged.

Integration tested in a production Hermes 0.10.0 deployment running Opus 4.7 via OAuth with a ~3k-token SOUL-style system prompt: 400 errors cleared, message flow back to normal (4 api_calls / 36s on a cold session with tools).

No changes to non-OAuth paths. No behavioural change expected for users with system containing only the CC identity block.

OAuth subscription requests (Claude Code route) fail with 400
'You're out of extra usage. Add more at claude.ai/settings/usage'
when the system field contains large custom content beyond the CC
identity block. The same payload succeeds with a pay-per-token API
key, so the check is subscription-route specific and orthogonal to
quota.

Fix: keep only the CC identity block in system and fold any extra
system blocks into a [CONTEXT]...[/CONTEXT] user-message prefix
followed by an assistant 'Understood.' acknowledgement. Content is
preserved verbatim; only the transport slot changes.

Tested on 0.10.0 (commit b2111a2) with Opus 4.7 OAuth and a
SOUL-style ~3k-token system prompt: 400 -> 200 with response
latency unchanged.
@0xyg3n
0xyg3n force-pushed the fix/oauth-system-prompt-overflow branch from 7d89325 to cefb31b Compare April 21, 2026 16:37
@0xyg3n

0xyg3n commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Closing to re-open from a clean branch after commit metadata fix. Replacement PR incoming.

@0xyg3n 0xyg3n closed this Apr 21, 2026
@0xyg3n
0xyg3n deleted the fix/oauth-system-prompt-overflow branch April 21, 2026 16:38
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API labels Apr 21, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #13611 — same fix (OAuth system prompt to user prefix), #13609 is closed while #13611 is open.

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants