Skip to content

Function: statusToErrorCode()

@providerprotocol/ai


@providerprotocol/ai / http / statusToErrorCode

statusToErrorCode(status): ErrorCode

Defined in: src/http/errors.ts:37

Maps HTTP status codes to standardized UPP error codes.

This function provides consistent error categorization across all providers:

  • 400 -> INVALID_REQUEST (bad request format or parameters)
  • 401, 403 -> AUTHENTICATION_FAILED (invalid or missing credentials)
  • 404 -> MODEL_NOT_FOUND (requested model does not exist)
  • 408 -> TIMEOUT (request timed out)
  • 413 -> CONTEXT_LENGTH_EXCEEDED (input too long)
  • 429 -> RATE_LIMITED (too many requests)
  • 5xx -> PROVIDER_ERROR (server-side issues)

number

HTTP status code from the response

ErrorCode

The corresponding UPP ErrorCode

const errorCode = statusToErrorCode(429);
// Returns 'RATE_LIMITED'
const serverError = statusToErrorCode(503);
// Returns 'PROVIDER_ERROR'