Variable: ErrorCode
@providerprotocol/ai / @providerprotocol/ai / ErrorCode
Variable: ErrorCode
Section titled “Variable: ErrorCode”
constErrorCode:object
Defined in: src/types/errors.ts:34
Error code constants for cross-provider error handling.
Use these constants instead of raw strings for type-safe error handling:
Type Declaration
Section titled “Type Declaration”AuthenticationFailed
Section titled “AuthenticationFailed”
readonlyAuthenticationFailed:"AUTHENTICATION_FAILED"='AUTHENTICATION_FAILED'
API key is invalid or expired
Cancelled
Section titled “Cancelled”
readonlyCancelled:"CANCELLED"='CANCELLED'
Request was cancelled via AbortSignal
ContentFiltered
Section titled “ContentFiltered”
readonlyContentFiltered:"CONTENT_FILTERED"='CONTENT_FILTERED'
Content was blocked by safety filters
ContextLengthExceeded
Section titled “ContextLengthExceeded”
readonlyContextLengthExceeded:"CONTEXT_LENGTH_EXCEEDED"='CONTEXT_LENGTH_EXCEEDED'
Input exceeds model’s context window
InvalidRequest
Section titled “InvalidRequest”
readonlyInvalidRequest:"INVALID_REQUEST"='INVALID_REQUEST'
Request parameters are malformed
InvalidResponse
Section titled “InvalidResponse”
readonlyInvalidResponse:"INVALID_RESPONSE"='INVALID_RESPONSE'
Provider returned an unexpected response format
ModelNotFound
Section titled “ModelNotFound”
readonlyModelNotFound:"MODEL_NOT_FOUND"='MODEL_NOT_FOUND'
Requested model does not exist
NetworkError
Section titled “NetworkError”
readonlyNetworkError:"NETWORK_ERROR"='NETWORK_ERROR'
Network connectivity issue
ProviderError
Section titled “ProviderError”
readonlyProviderError:"PROVIDER_ERROR"='PROVIDER_ERROR'
Provider-specific error not covered by other codes
QuotaExceeded
Section titled “QuotaExceeded”
readonlyQuotaExceeded:"QUOTA_EXCEEDED"='QUOTA_EXCEEDED'
Account quota or credits exhausted
RateLimited
Section titled “RateLimited”
readonlyRateLimited:"RATE_LIMITED"='RATE_LIMITED'
Rate limit exceeded, retry after delay
Timeout
Section titled “Timeout”
readonlyTimeout:"TIMEOUT"='TIMEOUT'
Request exceeded timeout limit
Example
Section titled “Example”import { ErrorCode } from 'upp';
try { await llm.generate('Hello');} catch (error) { if (error instanceof UPPError) { switch (error.code) { case ErrorCode.RateLimited: await delay(error.retryAfter); break; case ErrorCode.AuthenticationFailed: throw new Error('Invalid API key'); } }}