Skip to content

Bug: Auto can pick a provider that is out of credit, and the turn fails instead of using the other one #5339

Closed

Description

@yannickmonney

Summary

With the composer on Auto and two direct provider credentials active, one of which has run out of credit (an OpenRouter key whose usage limit is spent), a message can fail with the provider's 402 even though the other provider could have answered. Auto picks a model without any knowledge of whether the credential behind it can still pay, and the turn does not retry on another candidate when the provider refuses.

What was reported

Chat, model set to Auto, one message sent. The turn ended with:

The model provider answered 402: {"error":{"message":"This request requires more credits, or fewer max_tokens. You requested up to 64000 tokens, but can only afford 272. …","code":402,"metadata":{"limit_source":"openrouter_key_limit","remedy_hint":"Raise or remove this API key's usage limit …"}}}

The organization has two providers active; one is out of credit, the other is not. The pick that Auto made ([chat-model] resolved … log line) was not captured, so which of the two it chose is inferred from the 402 body (openrouter_key_limit), not observed.

What the code does today (main at 039e421)

  • services/platform/backend/core/chat/turn_action.ts:1308-1329 resolves Auto first, into one concrete (provider, model) pair, and refuses the turn if nothing resolves ("never a silent fallback").
  • services/platform/backend/core/lib/providers/resolve_chat_model.ts:81-91 reads the active direct credentials (api-key / env) and walks their catalogs. The only facts it has about a credential are that it is active and what its catalog lists. There is no input for remaining credit, a recent 402/429, or a key limit.
  • resolve_chat_model.ts:165 then calls chooseChatModel (services/platform/lib/chat/model-choice.ts): the curated per-band preferred list first, lowest output price otherwise. A credential that cannot pay is indistinguishable from one that can.
  • turn_action.ts:~804 turns a non-OK provider response into an error carrying status; the turn ends there. The providerStrict / "falls back to another connector" wording at turn_action.ts:844-846 concerns which connector serves a named model id at resolution time, not a retry after the provider refuses.
  • The user sees the provider's raw 402 text. OpenRouter's body names the key limit and a dashboard URL, so it reaches the chat as written.

Observed vs. not examined

  • Observed: the 402 text above, from the reporter's chat.
  • Not examined: which provider and model Auto chose; whether the same message succeeds when the other provider's model is picked by hand (expected, not tried); whether the 402 also appears for a non-Auto send to the same model (expected); how other credentials fail when out of credit (other vendors answer with a different status or body).
  • The message says "up to 64000 tokens, can only afford 272": the key had a few hundred tokens of headroom left rather than none, so a request with a small max_tokens may still have succeeded. Whether the chat lane could size max_tokens to what a key can afford was not examined.

Constraints

  • Auto must stay a per-message pick that governance applies to in full (resolve_chat_model.ts header), and Auto and the picker must not disagree about what the user may run.
  • A refusal must stay explicit; the file's own rule is no silent fallback. A retry on another candidate would need to be visible (which model answered is already shown on the message).
  • A turn that failed after the provider accepted the request (tokens already streamed or billed) is not the same as a 402 before any byte; the pipeline already tells these apart (onAccepted).
  • Org-owned credential state is per organization (tenant isolation).

Options (no preference stated)

  1. Retry on refusal. When the provider refuses an Auto turn before accepting the prompt (402, perhaps 401/429), re-resolve with that (provider, model) excluded and run once more, bounded to a few candidates.
  2. Remember it. Record a credential's payment refusal for a short window and have Auto skip that credential's models until it expires or the credential is edited.
  3. Ask the vendor. Where a vendor exposes balance or key limit (OpenRouter's key endpoint does), Auto reads it before picking. Per-vendor code, and an extra round trip on every send.
  4. Explain it. Keep the single pick but replace the raw vendor text with a Tale message naming the provider and suggesting a manual model choice or a top-up.
  5. Smaller request. Lower max_tokens to what the key can afford when the 402 body says so (OpenRouter only).

These combine (1 + 4 is the smallest user-visible change).

Questions

  • Should Auto ever answer on a different provider than the first pick after a refusal, or is a visible error the intended behaviour?
  • Is a spent key a state worth showing in Settings → providers, independent of Auto?

Related

Activity

  1. added
    agent-ready
    on Nov 3, 2026
  2. added a commit that references this issue on Nov 3, 2026
    db4cc78
  3. added a commit that references this issue on Nov 3, 2026
    80b4f57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions