Skip to main content
chat() sends a request and waits for the full response. Use it when you need the complete output before continuing — data extraction, classification, or when streaming isn’t practical.

Basic usage

The response

chat() returns a ChatResponse with everything you need:

Controlling generation

Parameters you don’t pass stay at provider defaults. The gateway handles provider-specific quirks automatically — temperature is stripped for reasoning models (o3, o3-mini, o4-mini), max_tokens is renamed to max_completion_tokens where needed.

Aborting a request

Pass an AbortSignal to cancel an in-flight request:

Linking requests to the dashboard

Pass promptId to associate the request with a saved prompt for log correlation:
The prompt’s content is not used — this just tags the log entry. Run a saved prompt’s actual template through /v1/prompts/:slug/run instead.

Fallback chains

Pass fallbackChain to survive provider outages, rate limits, and refusals — if the primary model fails, the gateway tries each fallback in order:
Trigger values: rate_limit, provider_error, timeout, refusal_detected. Without triggers, the entry fires on any failure. Every model in the chain must support the prompt’s output format. When structured output is set, models that can’t produce the format — including models unknown to the catalog — are skipped at request time. The dashboard editor flags them while you build the chain.

Tracking end users

Pass endUserId to tag requests with a user identifier. This shows up in the logs so you can filter by user:
endUserId travels in the x-gatelit-end-user-id header and is never sent to the provider. If you also want the provider to receive an end-user ID (the OpenAI-standard user body field), pass user:

Attaching metadata

Pass metadata to attach arbitrary tags to a request — environment, feature, session, tenant. The gateway stores them on the log entry, so you can filter and debug by them in the dashboard:
Metadata values must be strings, numbers, or booleans, and are stripped before the request reaches the provider.

Response caching

Opt into exact-match caching for deterministic requests — non-streaming, temperature: 0, no tools. Identical requests are served from the gateway cache with no upstream call and no provider spend. Only successful responses are cached, so failure retries always hit the provider fresh.

Error handling

The SDK throws a GatelitError with three fields: