Chat completions
Send messages to a physical model or route and read normalized results.
Use a configured client from the quickstart. Your organization needs an enabled provider/model and credential, or an active route with compatible targets. Chat requires gateway execute permission.
Model names beginning with configured/ are placeholders. Replace them with an accessible provider-qualified identifier from model discovery. The snippets reuse the server client from the quickstart.
Generate a reply
const completion = await nirmos.gateway.chat.create({
model: "configured/chat-model",
messages: [
{ role: "system", content: "You are a concise technical editor." },
{ role: "user", content: "Rewrite: caching got better" },
],
temperature: 0.2,
maxOutputTokens: 300,
});
console.log(completion.outputText, completion.usage, completion.metadata.requestId);Pass exactly one model or route. Messages may be omitted only when a managed-prompt reference supplies them. The SDK rejects empty rendered messages before transport. prompt inserts rendered messages before request messages by default; it does not select a model.
Parameters
| Field | Behavior |
|---|---|
model / route | Required exclusive target selection |
messages | Readonly conversation array with role/content; optional name/tool fields |
prompt | Runtime managed-prompt reference, version, variables, cache and insertion position |
temperature, topP, maxOutputTokens, stop | Provider-dependent sampling and output limits |
tools, toolChoice | Function tool schemas and selection policy |
responseFormat | text, jsonObject, or jsonSchema with name/schema/optional strict |
seed, user | Optional provider request values |
provider | Direct provider override; server resolves it |
fallbackModels | Direct-model fallback identifiers |
routingStrategy | Serialized hint; not an implemented optimizer |
metadata | JSON-compatible metadata; not authorization or an executing conditional route rule |
SDK fields use camelCase; transport maps them to gateway wire fields such as top_p, max_tokens, tool_choice and fallback_models.
HTTP role compatibility
SDK messages accept system, user, assistant, tool and developer. For raw
OpenAI-compatible HTTP requests, runtime preserves system/assistant/tool/developer
and normalizes other role strings (for example human) to user. This is a
compatibility rule, not another typed SDK role. Provider adapters may further map
roles into their native protocol. Use declared SDK roles for portable requests.
Use tools and structured output when the application needs function calls or a schema-constrained response.
Multimodal messages
await nirmos.gateway.chat.create({
model: "configured/vision-model",
messages: [{ role: "user", content: [
{ type: "text", text: "Describe this diagram." },
{ type: "image", url: "https://example.com/diagram.png", detail: "high" },
] }],
});Public content parts include text, image and audio. Their availability depends on the runtime adapter/model; a type declaration is not a guarantee of audio execution. Image parts map to image_url on the wire; audio parts map to audio with data/format.
ChatCompletion retains choices/tool calls, concatenates text into outputText, normalizes usage and adds optional metadata. Missing provider usage becomes zero. Errors can arise locally, from authentication/capability validation, rate limits or provider failures.
Gateway reference · Gateway types · Streaming · Routing
Provider-specific controls
Use optional providerOptions, keyed by upstream provider slug, for verified reasoning/routing controls. HTTP clients send provider_options. These options cannot override model selection or authentication. See Groq, OpenRouter and Cloudflare.