Repository navigation
Gateway: a provider's refusal of the key stops the task at once and says why at the top - #808
Merged
Merged
Conversation
… call passes, stops the task at once and says why at the top
A task whose provider refused its key looked like any other failed task. Its reason was the runner's
reading of what the agent printed ("The model provider refused the request (403: Forbidden.)"), named
the provider by its wiring's id ("Your tokenrouter key"), and said nothing of what to do; an agent that
retried, stopped quietly or answered in its own words left less.
- The broker reads the provider's own error body on a model call's 400/401/402/403/404/429 and records,
for the task, a refusal no retry can change: the key refused, no credit or quota left (402, or an
empty account's code on 400/403/429), or the model refused for the key. A rate limit is not recorded.
The provider's words are kept without any part of the key. The agent still gets the answer as it came.
The record lives in the process and in the control store (both backings), so any process's turn sees it.
- The turn stops on it at once (the runner told to cancel) when it is the turn's own model on its own
connection, made after the turn started. An agent that ended first, failed in its own words or
"completed" with nothing from the model, still fails with it; one that answered is left as it was.
- The message names the provider as Bring Your Own Key does ("TokenRouter") and says the next step;
error.detail adds provider, status, model and connection to reason and retryable; the stream's
error event carries the detail too.
- The runner's line is read better: 402, "credit balance is too low", and a credit code in the body
under a refusal's first line are no credit, not a refused key or a rate limit.
- Protocol: Errors §3.4 describes these detail fields (additive, no new code), the retry table says a
failed task with retryable false is not worth retrying, Streaming lists detail on the error event.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
richard-epsilla
previously approved these changes
Dec 2, 2026
richard-epsilla
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed: same change as the hosted gateway release b135bc2cb (read back on production 12-02: a refused own key fails at once as provider_key_refused with the next step; the key never appears in the error, the stream or the log). Suite: same 19 ffmpeg-dependent failures as main; 38 new tests pass.
# Conflicts: # protocol/CHANGELOG.md
richard-epsilla
approved these changes
Dec 2, 2026
richard-epsilla
left a comment
Collaborator
There was a problem hiding this comment.
Re-approved after merging main (one CHANGELOG conflict: both new entries kept). All required checks and CodeQL pass on 9d0363d.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
When a model provider refuses the key a task runs on, the task now stops at once and says why at the top of the response, with the next step.
Before this, such a task looked like any other failed task. Its reason was the agent's own report of the error (for example "The model provider refused the request (403: Forbidden.)"). It named the provider by an internal id ("Your tokenrouter key") and said nothing about what to do.
Read at the model call. The gateway reads the provider's own error body on a model call that answers 400/401/402/403/404/429. It records a refusal that no retry can change:
A rate limit is not recorded. The provider's words are kept without any part of the key. The agent still gets the answer as it came. The record lives in the process and in the control store (both backings), so any process's turn sees it.
The turn stops on it. This happens only when the refusal is for the turn's own model on its own connection and came after the turn started. A turn that ended first, failed in its own words, or "completed" with nothing from the model still fails with the refusal. A turn that answered is left as it was.
The message names the provider as Bring Your Own Key does ("TokenRouter") and says the next step.
error.detailaddsprovider,status,modelandconnectiontoreasonandretryable. The stream'serrorevent carries the samedetail.Better reading of the runner's line. 402, "credit balance is too low", and a credit code in the body under a refusal's first line now mean no credit, not a refused key or a rate limit.
Protocol docs. Errors §3.4 describes the detail fields (additive, no new code). The retry table says a failed task with
retryable: falseis not worth retrying. Streaming listsdetailon the error event.Tests
gateway/tests/test_relay_refusal.pyis new, with 38 tests:🤖 Generated with Claude Code