Nirmos

Chat completions

Send OpenAI-compatible chat requests through the Nirmos gateway.

Chat completions are available through both client libraries. Use a provider-qualified model to make direct resolution explicit.

const completion = await nirmos.gateway.chat.create({
  model: "openai/gpt-5.4-mini",
  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);
const completion = await client.chat.completions.create({
  model: "openai/gpt-5.4-mini",
  messages: [
    { role: "system", content: "You are a concise technical editor." },
    { role: "user", content: "Rewrite: caching got better" },
  ],
  temperature: 0.2,
  max_tokens: 300,
});

console.log(completion.choices[0]?.message.content);

Choose a target

Nirmos SDK calls require exactly one of model or route:

// Direct model
await nirmos.gateway.chat.create({
  model: "openai/gpt-5.4-mini",
  messages,
});

// Centrally configured route
await nirmos.gateway.chat.create({
  route: "production-chat",
  messages,
});

OpenAI-compatible clients call the same route through model: "nirmos/production-chat". See Routing and fallback.

Nirmos SDK request fields

FieldTypePurpose
modelstringPhysical model or nirmos/<route-slug>; exclusive with route
routestringActive route ID or slug; exclusive with model
messagesChatMessage[]Conversation messages
promptPromptReferenceManaged prompt rendered by the SDK before the request
temperaturenumberSampling temperature
topPnumberNucleus sampling threshold
maxOutputTokensnumberMaximum generated tokens
stopstring | string[]Stop sequence or sequences
toolsFunctionTool[]Function tool definitions
toolChoiceToolChoiceTool selection behavior
responseFormatResponseFormatText, JSON object, or JSON Schema output
providerstringOptional provider hint for direct model resolution
fallbackModelsstring[]Ordered direct-model fallbacks
routingStrategyRoutingStrategyRouting hint forwarded to the gateway
metadataJSON objectOptional application metadata sent in the gateway request

Multimodal content

The Nirmos SDK uses normalized content-part names and maps them to the OpenAI wire shape.

await nirmos.gateway.chat.create({
  model: "google/gemini-3.5-flash",
  messages: [{
    role: "user",
    content: [
      { type: "text", text: "Describe this diagram." },
      { type: "image", url: "https://example.com/diagram.png", detail: "high" },
    ],
  }],
});
await client.chat.completions.create({
  model: "google/gemini-3.5-flash",
  messages: [{
    role: "user",
    content: [
      { type: "text", text: "Describe this diagram." },
      { type: "image_url", image_url: { url: "https://example.com/diagram.png", detail: "high" } },
    ],
  }],
});

The selected model must advertise the required vision capability.

Structured output

const completion = await nirmos.gateway.chat.create({
  model: "openai/gpt-5.4-mini",
  messages: [{ role: "user", content: "Extract: Pro costs $29" }],
  responseFormat: {
    type: "jsonSchema",
    name: "product",
    strict: true,
    schema: {
      type: "object",
      properties: {
        name: { type: "string" },
        price: { type: "number" },
      },
      required: ["name", "price"],
      additionalProperties: false,
    },
  },
});
const completion = await client.chat.completions.create({
  model: "openai/gpt-5.4-mini",
  messages: [{ role: "user", content: "Extract: Pro costs $29" }],
  response_format: {
    type: "json_schema",
    json_schema: {
      name: "product",
      strict: true,
      schema: {
        type: "object",
        properties: {
          name: { type: "string" },
          price: { type: "number" },
        },
        required: ["name", "price"],
        additionalProperties: false,
      },
    },
  },
});

Validate parsed output in your application before using it for writes or tool execution.

Normalized response

chat.create returns choices, joined outputText, normalized token usage, and optional request metadata:

console.log({
  text: completion.outputText,
  inputTokens: completion.usage.inputTokens,
  outputTokens: completion.usage.outputTokens,
  requestId: completion.metadata.requestId,
  provider: completion.metadata.provider,
});

On this page