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
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 anAbortSignal to cancel an in-flight request:
Linking requests to the dashboard
PasspromptId to associate the request with a saved prompt for log correlation:
/v1/prompts/:slug/run instead.
Fallback chains
PassfallbackChain to survive provider outages, rate limits, and refusals — if the primary model fails, the gateway tries each fallback in order:
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
PassendUserId 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
Passmetadata 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:
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 aGatelitError with three fields: