Skip to content

Variable: ErrorCode

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / ErrorCode

const ErrorCode: 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:

readonly AuthenticationFailed: "AUTHENTICATION_FAILED" = 'AUTHENTICATION_FAILED'

API key is invalid or expired

readonly Cancelled: "CANCELLED" = 'CANCELLED'

Request was cancelled via AbortSignal

readonly ContentFiltered: "CONTENT_FILTERED" = 'CONTENT_FILTERED'

Content was blocked by safety filters

readonly ContextLengthExceeded: "CONTEXT_LENGTH_EXCEEDED" = 'CONTEXT_LENGTH_EXCEEDED'

Input exceeds model’s context window

readonly InvalidRequest: "INVALID_REQUEST" = 'INVALID_REQUEST'

Request parameters are malformed

readonly InvalidResponse: "INVALID_RESPONSE" = 'INVALID_RESPONSE'

Provider returned an unexpected response format

readonly ModelNotFound: "MODEL_NOT_FOUND" = 'MODEL_NOT_FOUND'

Requested model does not exist

readonly NetworkError: "NETWORK_ERROR" = 'NETWORK_ERROR'

Network connectivity issue

readonly ProviderError: "PROVIDER_ERROR" = 'PROVIDER_ERROR'

Provider-specific error not covered by other codes

readonly QuotaExceeded: "QUOTA_EXCEEDED" = 'QUOTA_EXCEEDED'

Account quota or credits exhausted

readonly RateLimited: "RATE_LIMITED" = 'RATE_LIMITED'

Rate limit exceeded, retry after delay

readonly Timeout: "TIMEOUT" = 'TIMEOUT'

Request exceeded timeout limit

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');
}
}
}