All errors thrown by the SDK descend fromDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/core/llms.txt
Use this file to discover all available pages before exploring further.
AiSdkException, which extends PHP’s RuntimeException. Every exception carries a structured $context array and a set of typed accessor methods, giving you a consistent interface for reading provider name, HTTP status, request ID, and retry hints — regardless of which provider raised the error. The HttpErrorNormalizer utility maps provider HTTP responses to the appropriate subclass automatically.
Base class: AiSdkException
AiSdkException extends RuntimeException is the root of the exception hierarchy. All SDK exceptions can be caught at this level.
Constructor
Human-readable description of the error.
Structured data attached to the exception. Keys such as
provider, modelId, status, and retryable are populated by the SDK; specific subclasses add additional keys.The original exception that caused this one, used to preserve the full stack trace chain.
Context accessor methods
Returns the raw context array attached to this exception.
The identifier of the provider that raised the error (e.g.
'anthropic', 'openai'). null when not set.The model ID that was in use when the error occurred.
null when not set.The HTTP status code from the provider’s response.
null for non-HTTP errors such as connection failures or SDK-internal exceptions.The provider-assigned request identifier, when the provider includes one in the response headers or body. Useful for filing support tickets.
The provider-specific error type string, when the response body includes one (e.g.
'invalid_request_error').The provider-specific error code string, when the response body includes one (e.g.
'context_length_exceeded').The number of seconds the client should wait before retrying, sourced from a
Retry-After header or equivalent body field. null when not provided.Returns
true when the error is considered safe to retry. The HttpErrorNormalizer sets this for HTTP status codes 408, 409, 429, 500, 502, 503, 504, and 529.The raw response body from the provider, either as a decoded array or a raw string depending on the content type.
null when not available.Exception hierarchy
Exception classes
ProviderException
Thrown when a provider returns any error response. The direct parent of all HTTP and connection errors. Catch this class to handle all provider-side failures in a single clause.APIStatusException
Thrown when the provider returns a non-success HTTP status code. All HTTP-status-specific subclasses extend this class.AuthenticationException
Thrown for HTTP 401 responses. Indicates that the API key or token is missing, expired, or invalid.PermissionDeniedException
Thrown for HTTP 403 responses. Indicates that the credentials are valid but lack permission to access the requested resource or model.NotFoundException
Thrown for HTTP 404 responses. Indicates that the requested resource (endpoint, file, fine-tune, etc.) does not exist on the provider.InvalidRequestException
Thrown for HTTP 4xx responses not covered by a more specific class. Indicates a malformed request, missing required parameters, or a parameter value outside the allowed range.RateLimitException
Thrown for HTTP 429 responses.isRetryable() returns true. Check retryAfter() for the number of seconds to wait before retrying.
OverloadedException
Thrown for HTTP 529 responses. Indicates the provider is temporarily over capacity.isRetryable() returns true.
InternalServerException
Thrown for HTTP 5xx responses. Indicates a server-side failure on the provider.isRetryable() returns true for all 5xx codes.
APIConnectionException
Thrown when the HTTP request could not be completed due to a network-level failure — DNS resolution failure, connection timeout, TLS error, etc. No HTTP status code is available. The original transport exception is available viagetPrevious().
CapabilityNotSupportedException
Thrown when a requested capability (e.g.Capability::ToolCalling) is not available for the selected model and provider. Constructed via CapabilityNotSupportedException::for() or ::fromSupport().
NoSuchModelException
Thrown when the specified model ID is not recognised by the provider. Constructed viaNoSuchModelException::for(string $provider, string $modelId, string $modelType).
NoSuchToolException
Thrown when a tool name is referenced that has not been registered with the SDK. Constructed viaNoSuchToolException::for(string $tool).
MissingApiKeyException
Thrown when no API key is configured for a provider. Constructed viaMissingApiKeyException::forProvider(string $provider, string $envVar). The message includes the expected environment variable name.
InvalidArgumentException
Thrown when an invalid argument is passed to an SDK method. ExtendsAiSdkException directly.
ToolExecutionException
Thrown when a registered tool handler throws during execution. The original exception is chained asgetPrevious(). Constructed via ToolExecutionException::for(string $tool, Throwable $previous).
InvalidToolInputException
Thrown when a tool’s input arguments fail validation. Has two named constructors:::missing() for absent required inputs and ::invalid() for inputs of the wrong type or value.
JsonException
Thrown when a JSON decode operation fails. ExtendsAiSdkException directly.
SchemaValidationException
Thrown when a structured output response fails validation against the provided schema. ExtendsAiSdkException directly.
Retryable status codes
The following HTTP status codes are markedisRetryable() === true by the HttpErrorNormalizer:
| Status | Exception class | Reason |
|---|---|---|
| 408 | InvalidRequestException | Request timeout — safe to retry. |
| 409 | InvalidRequestException | Conflict — transient state, safe to retry. |
| 429 | RateLimitException | Rate limit exceeded — back off and retry. |
| 500 | InternalServerException | Internal server error — transient failure. |
| 502 | InternalServerException | Bad gateway — transient infrastructure issue. |
| 503 | InternalServerException | Service unavailable — transient overload. |
| 504 | InternalServerException | Gateway timeout — transient timeout. |
| 529 | OverloadedException | Provider overloaded — back off and retry. |