code values.
Gateway error codes
Strict structured output
A request that asks for a strict JSON schema gets a reply that matches it, whichever provider serves the request. That meansresponse_format.json_schema.strict: true on /v1/chat/completions, text.format.strict: true on /v1/responses, or any output_config.format on /v1/messages. Some providers can’t enforce a schema themselves. Amazon Bedrock rejects it for the newest Claude models, for example. So the gateway checks every such reply:
- A reply that doesn’t match is sent back to the model once, with the problems listed, and the corrected reply is returned. Usage covers both calls.
- If the second reply doesn’t match either, the request fails with
502andstructured_output_invalid. - A streamed reply has already been sent when the check runs, so it isn’t retried. The stream ends with an error event carrying
structured_output_invalid.
strict: true are passed through unchanged.
Build matching envelopes
Import error classes and envelope builders from the./errors subpath for custom handlers or embedding hosts that need to produce gateway-compatible error responses.
toAnthropicErrorResponse produces the equivalent envelope for the /v1/messages route’s wire format.
For an error that is not a GatewayError, toStatusErrorResponse builds the same envelope from a status, taking type and a default code from the status:
'anthropic' for the /v1/messages shape, and code or param to set them.
Error classes
ConfigError, ModelIdError, ProviderNotConfiguredError, UnsupportedModalityError, RequestValidationError, BodyTooLargeError, InvalidToolArgumentsError, ModelNotFoundError, ModelUnsupportedOperationError, NotFoundError, NoProvidersError, and StructuredOutputError all extend GatewayError and carry a code matching the table above.