Skip to main content

TypeScript SDK Reference

See the TypeScript SDK Guide for usage examples and getting started.

Client

Initialize a client with configuration options:

Resources


Chat Completions

client.chat.completions.create(params)

Creates a chat completion. Supports single-model and multi-model routing.

Parameters

gateway.metadata fields

Only the four fields above are accepted. Use custom_fields for arbitrary key-value pairs.

Response (non-streaming)

Response (streaming)

Returns a Stream that yields ChatCompletionChunk objects.

Responses

client.responses.create(params)

Creates a response using the OpenAI Response API format. Supports single-model and multi-model routing.

Parameters

Response (non-streaming)

Response (streaming)

Returns a ResponseStream that yields Response API events.
routing_metadata on completedResponse is available for both streaming and non-streaming responses. For streaming, it’s populated after iteration completes.

Models

Query the model catalog:

Identity

Get current API key identity:

Error Classes

All errors extend ArbytraAPIError. Dispatch is driven by the type field of the canonical error envelope (see Errors for the full envelope and retry policy).

ArbytraAPIError Fields

Unknown error responses fall through to the base ArbytraAPIError class. Always keep a catch-all for forward compatibility.
mapErrorFromCode(code, message, responseHeaders, opts?) constructs a typed ArbytraAPIError subclass from an error code string (e.g., "rate_limit_error"RateLimitError):

Response Headers

Available on ChatCompletion.responseHeaders, Stream.responseHeaders, and ResponseObject.responseHeaders:

Constants

Runtime enum objects for routing configuration:

Types

All types use snake_case field names matching the wire format:

Client & Stream

Chat Response Types

Response Types

Common types for the Response API. The SDK exports all event types in the ResponseStreamEvent union — import individual event types (e.g., ResponseTextDeltaEvent, ResponseFunctionCallArgumentsDoneEvent) as needed.

Common Types

Routing Types

Extensions

Model Catalog Types

Request Types

Runtime Constants

Error Classes