Skip to main content

errors.ts

Source: sdks/typescript/packages/sdk/src/errors.ts. Back to the TypeScript SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Interface ErrorEnvelope​

JSON error body of the API: code, message, localized messages, details and request id under error.

Fields:

NameTypeRequiredDescription
error{ code: string; message: string; message_i18n?: Partial<Record<Locale, string>>; details?: Record<string, unknown>; request_id?: string; }yesThe error: code, message, message_i18n, details and request_id.

Interface EaiErrorInit​

Fields given to the EaiError constructor.

Fields:

NameTypeRequiredDescription
codestringyesCode of the control, 1 to 64 characters: a catalogue code such as EAI-GOV-01, or a custom one. Unique in the tenant.
messagestringyesStatus message (up to 2000 characters).
statusnumbernoHTTP status of the response.
detailsRecord<stringnoFree attributes of the event, at most 16384 bytes once serialized.
requestIdstringnoRequest id of the call.
messageI18nPartial<Record<LocalenoMessage in en and fr.
retryAfterMsnumbernoDelay before a retry, in milliseconds.
causeunknownnoOriginal error, kept as cause.

Class EaiError​

Base class of every SDK error: code, HTTP status, details with secrets masked, request id and localized messages.

Error

Attributes:

NameTypeRequiredDescription
codestringyesMachine readable error code, for example policy_denied.
detailsRecord<string, unknown>yesDetails sent by the server, secret looking keys replaced by ***.
messageI18nPartial<Record<Locale, string>>yesMessage of the server in en and fr when it sent them.
requestIdstring | undefinedyesRequest id of the failed call, to quote to support.
retryAfterMsnumber | undefinedyesDelay asked by the Retry-After header, in milliseconds.
statusnumber | undefinedyesHTTP status, undefined for a local or network error.

Constructor EaiError​

new EaiError(init: EaiErrorInit)

Builds the error; the class name becomes name and the secret looking keys of details are masked.

NameTypeDefaultRequiredDescription
initEaiErrorInityesCode, message and optional status, details, request id, localized messages, retry delay and cause.

Class AuthError​

Authentication or permission refused: codes unauthorized, unauthenticated, forbidden, invalid_credentials, or HTTP 401 and 403.

EaiError

Class EgressDeniedError​

The egress guard refused an outbound call (403 egress_denied); reason is details.reason.

EaiError

EgressDeniedError.reason​

reason(): string | undefined

Reason of the refusal, read from details.reason.

This element takes no parameter.

Returns: string \| undefined. The reason, or undefined when it is not a string.

Class PromptInjectionBlockedError​

The prompt injection screen blocked the content (403 prompt_injection_blocked).

EaiError

Class PayloadTooLargeError​

The request body exceeds the server limit (413 payload_too_large).

EaiError

Class NotFoundError​

The resource does not exist (not_found or HTTP 404).

EaiError

Class PolicyDeniedError​

A policy refused the action (policy_denied).

EaiError

PolicyDeniedError.decisionId​

decisionId(): string | undefined

Id of the policy decision, read from details.decision_id.

This element takes no parameter.

Returns: string \| undefined. The decision id, or undefined when the server sent none.

PolicyDeniedError.reasons​

reasons(): string[]

Reasons of the refusal, read from details.reasons.

This element takes no parameter.

Returns: string[]. The reasons as strings, an empty array when there are none.

Class QuotaExceededError​

A quota or a budget is exhausted (quota_exceeded or budget_exceeded).

EaiError

Class EffortNotSupportedError​

The model does not support the requested reasoning effort (effort_not_supported).

EaiError

Class ContextOverflowError​

The context does not fit in the budget (context_overflow), raised by the server or by ContextBudget.

EaiError

Class ApprovalRequiredError​

The action needs a human approval first (approval_required).

EaiError

ApprovalRequiredError.approvalId​

approvalId(): string | undefined

Id of the approval to wait for, read from details.approval_id.

This element takes no parameter.

Returns: string \| undefined. The approval id, or undefined when the server sent none.

Class RateLimitError​

Too many requests (rate_limited or HTTP 429); retryAfterMs gives the delay when the server sent one.

EaiError

Class ValidationError​

One invalid field of a request.

EaiError

Class ConflictError​

The request conflicts with the current state (conflict or HTTP 409).

EaiError

Class ServerError​

Server failure (HTTP 500 or more) after the retries.

EaiError

Class NetworkError​

The request did not get a response: network failure (network_error) or timeout (timeout).

EaiError

Class ContractValidationError​

A document does not match its contract JSON Schema, or the contract is unknown.

EaiError

Class AgentLoopError​

Error of the agent loop and of local tools: step limit, budget, abort, kill switch or invalid tool input.

EaiError

Class AuthzUnconfirmedError​

An authorization answer without an explicit OPA or OpenFGA decision: the SDK never assumes an allow.

EaiError

Functions​

redactSecrets​

redactSecrets(value: unknown): unknown

Copy of a value with every secret looking key masked (recursive).

NameTypeDefaultRequiredDescription
valueunknownyesValue to copy: object, array or scalar.

Returns: unknown. The copy, keys such as api_key, token, password or authorization set to ***.

maskSecret​

maskSecret(value: string | undefined): string | undefined

Masks a secret: at most 4 visible characters.

NameTypeDefaultRequiredDescription
valuestring | undefinedyesSecret to mask; an empty or missing value is returned as is.

Returns: string \| undefined. The first 4 characters and *** for a secret longer than 12 characters, else only ***.

errorFromResponse​

errorFromResponse(status: number, body: unknown, locale: Locale, requestId?: string, retryAfterMs?: number): EaiError

Builds the typed error for an HTTP error response, using the server message in the client locale.

NameTypeDefaultRequiredDescription
statusnumberyesHTTP status of the response, used to choose the class when the code is unknown.
bodyunknownyesRequest body, serialized as JSON.
localeLocaleyesLanguage whose message is taken from message_i18n.
requestIdstringnoRequest id of the response header, used when the body gives none.
retryAfterMsnumbernoDelay of the Retry-After header in milliseconds.

Returns: EaiError. The EaiError subclass of the error code or status; without an error envelope the code is http_<status>.