Every error the SDK encounters — network failures, authentication issues, rate limits, invalid requests, missing capabilities — surfaces as a typed exception that extendsDocumentation 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. Because all exceptions share a common base, you can catch them at a single point or handle each case specifically. The HttpErrorNormalizer maps provider HTTP responses to the correct exception class so your code stays the same regardless of which provider you use.
Base class: AiSdkException
AiSdkException extends RuntimeException and carries a $context array populated by the throwing code. All context values are accessible through typed accessor methods:
Exception hierarchy
HTTP status mapping
HttpErrorNormalizer::normalize() maps the HTTP status code from a failed provider response to the appropriate exception class:
| Exception | HTTP Status | Description |
|---|---|---|
AuthenticationException | 401 | Invalid or missing API key |
PermissionDeniedException | 403 | Access denied to the requested resource |
NotFoundException | 404 | Requested resource does not exist |
InvalidRequestException | 4xx | Bad request parameters (other 4xx) |
RateLimitException | 429 | Rate limit exceeded |
OverloadedException | 529 | Provider is overloaded |
InternalServerException | 5xx | Provider server error |
ProviderException | other | Any other unexpected status |
APIConnectionException | — | Network or connection failure |
CapabilityNotSupportedException | — | Model does not support the required capability |
NoSuchModelException | — | Model not found in the registry or catalog |
MissingApiKeyException | — | API key environment variable not set |
ToolExecutionException | — | A tool handler threw during execution |
InvalidToolInputException | — | Tool input failed validation |
Retryable statuses
isRetryable() returns true for these HTTP statuses:
APIConnectionException (network failure) is not automatically marked retryable because the request may or may not have reached the provider.
Catch patterns
Catch all SDK exceptions
Retry on retryable errors
Catch specific exceptions
HttpErrorNormalizer
Provider adapters call HttpErrorNormalizer::normalize() when they receive a non-2xx response. You don’t need to call this directly, but understanding it helps when writing custom provider adapters.
error.message, error, or message keys, then falls back to a generic "{provider} request failed with status {status}." string.
Exception class reference
Exception class reference
| Class | Extends | Namespace |
|---|---|---|
AiSdkException | RuntimeException | AiSdk\Exceptions |
ProviderException | AiSdkException | AiSdk\Exceptions |
APIStatusException | ProviderException | AiSdk\Exceptions |
APIConnectionException | ProviderException | AiSdk\Exceptions |
AuthenticationException | APIStatusException | AiSdk\Exceptions |
PermissionDeniedException | APIStatusException | AiSdk\Exceptions |
NotFoundException | APIStatusException | AiSdk\Exceptions |
InvalidRequestException | APIStatusException | AiSdk\Exceptions |
RateLimitException | APIStatusException | AiSdk\Exceptions |
OverloadedException | APIStatusException | AiSdk\Exceptions |
InternalServerException | APIStatusException | AiSdk\Exceptions |
CapabilityNotSupportedException | AiSdkException | AiSdk\Exceptions |
NoSuchModelException | AiSdkException | AiSdk\Exceptions |
MissingApiKeyException | AiSdkException | AiSdk\Exceptions |
InvalidArgumentException | AiSdkException | AiSdk\Exceptions |
ToolExecutionException | AiSdkException | AiSdk\Exceptions |
InvalidToolInputException | AiSdkException | AiSdk\Exceptions |