Nirmos
Gateway

Tools and structured output

Handle function calls and request schema-constrained model output.

Use a configured server client and a model that supports the requested capability. Tools and structured-output combinations are provider-specific; consult provider limits.

Function tools

const completion = await nirmos.gateway.chat.create({
  model: "configured/tool-model",
  messages: [{ role: "user", content: "Check order 123." }],
  tools: [{ type: "function", function: {
    name: "lookup_order",
    description: "Read an authorized customer's order status",
    parameters: { type: "object", properties: { orderId: { type: "string" } }, required: ["orderId"] },
  } }],
  toolChoice: "auto",
});
for (const call of completion.choices[0]?.message.toolCalls ?? []) {
  console.log(call.id, call.function.name, call.function.arguments);
}

Tool arguments are JSON text. Parse and validate them, check authorization and execute approved tools in your application. The SDK does not execute tools or run an agent loop. Follow-up tool messages use role: "tool" and toolCallId.

Structured output

const completion = await nirmos.gateway.chat.create({
  model: "configured/json-model",
  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,
  } },
});
console.log(completion.outputText);

The SDK returns text, not an automatically parsed/validated object. Validate before using output for application writes.

Gateway methods · Streaming

On this page