Skip to content

streamError

function streamError(provider, envelope): ProviderError;

Defined in: core/src/errors.ts:759

A failure the backend reports INSIDE an already-200 stream.

The transport classified everything that failed before the body opened; this is the rest, and every streaming shape has the same hole. An SSE response commits to 200 the moment its headers go out, so a throttle, an overload, or a prompt found too long after the fact arrives as a payload in the body rather than as a status line. Left unread it matches no branch an adapter models, the loop skips it, and the turn ends as a successful zero-token completion: retry sees nothing to retry, and a key pool never rotates off an exhausted key.

error is the vendor’s own payload, whatever shape it came in: the numeric HTTP code Gemini and OpenRouter use, the slug OpenAI and Anthropic put in code/type, the canonical status name. The whole thing serializes into the searchable body, so RetryInfo’s retryDelay is honoured wherever it sits.

A number is a status only from 400 to 599. Vendors put their own codes in the same field: Z.ai’s 1113 is an empty balance, and read as a status it was past 500, which skips the 4xx body patterns that name it quota and lands on overload. With no status stated, the error’s type says which one it stands for (STATUS_BY_TYPE), and the body still outranks it (invariant 3).

unknown is floored to “overload” rather than kept: a stream that dies after its headers is by construction a transient upstream fault, and “unknown” is never retried. Only an error with no status and no type it knows gets there. Before the type was read, one invalid_request_error in words no pattern knew was floored too: retried, then walked across every backup, cooling each for 30s, on a request that fails the same way everywhere. Everything the body does name keeps its own kind, which is what tells the caller to wait, rotate a key, or compact instead of retrying a failure that will repeat.

Parameter Type
provider string
envelope unknown

ProviderError