Tools & Structured Output
Function calling, tool results, and strict JSON Schema output.
Models that advertise capabilities.tools: true can choose custom functions.
Your application executes the function and sends the result back; the platform
does not run customer code.
Function calling with Responses
const tools = [
{
type: "function",
name: "get_order_status",
description: "Look up an order by its public id",
parameters: {
type: "object",
properties: {
order_id: { type: "string" },
},
required: ["order_id"],
additionalProperties: false,
},
strict: true,
},
];
const first = await client.responses.create({
model: "your-tool-capable-model",
input: "Where is order A-104?",
tools,
});
const call = first.output.find((item) => item.type === "function_call");
if (call) {
const result = await getOrderStatus(JSON.parse(call.arguments));
const second = await client.responses.create({
model: "your-tool-capable-model",
tools,
input: [
...first.output,
{
type: "function_call_output",
call_id: call.call_id,
output: JSON.stringify(result),
},
],
});
console.log(second.output_text);
}
Function calling with Chat Completions
Use the standard tools, tool_choice, parallel_tool_calls, assistant
tool_calls, and role: "tool" message fields. Both streaming and
non-streaming tool calls are supported on compatible model routes.
Strict JSON Schema
const response = await client.responses.create({
model: "your-structured-output-model",
input: "Extract the invoice number and total: Invoice A-52, total $90.",
text: {
format: {
type: "json_schema",
name: "invoice",
strict: true,
schema: {
type: "object",
properties: {
invoice_number: { type: "string" },
total: { type: "number" },
},
required: ["invoice_number", "total"],
additionalProperties: false,
},
},
},
});
const invoice = JSON.parse(response.output_text);
For Chat Completions, send the equivalent schema under
response_format: { type: "json_schema", json_schema: ... }.
Structured output is provider- and model-dependent. Enable it only when model
discovery advertises structuredOutput: true. A provider rejection is returned
as an OpenAI-shaped error rather than silently falling back to unstructured text.