Tools & JSON responses
A model can do more than write text — it can ask your code to do something: check the weather, look something up, send an email. And you can get a response that strictly matches your schema, with no extra words.
Function calling
Describe the functions you're ready to run and pass them in the request.
{
"model": "gpt-5.6-sol",
"messages": [{ "role": "user", "content": "What's the weather in Kaliningrad?" }],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather in a city",
"parameters": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}
}
]
}Then it's a two-step flow: the model asks for a call — you supply the result.
// 1. The model asks to call a function
const first = await client.chat.completions.create({ model, messages, tools });
const call = first.choices[0].message.tool_calls?.[0];
if (call) {
const args = JSON.parse(call.function.arguments);
const result = await getWeather(args.city); // your code
// 2. Return the result and get the final response
messages.push(first.choices[0].message);
messages.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify(result) });
const final = await client.chat.completions.create({ model, messages, tools });
console.log(final.choices[0].message.content);
}Your code always executes the functions. Validate the arguments before running them — the model can pass unexpected values.
Strict JSON
If the response feeds into your code, set a schema — the model returns an object with the exact structure, no text parsing required.
{
"model": "gpt-5.6-sol",
"messages": [{ "role": "user", "content": "Parse this address: 12 Lenin St, Kaliningrad" }],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "address",
"schema": {
"type": "object",
"properties": {
"street": { "type": "string" },
"house": { "type": "string" },
"city": { "type": "string" }
},
"required": ["street", "house", "city"],
"additionalProperties": false
}
}
}
}Web search
The gateway itself doesn't access the internet. Add a tool like web_search, run the search with your own service, and feed the results back into the conversation — the model will answer using fresh data.