Guides
Tool calling enables Cortiqa models like openai/gpt-oss-120b to connect to external systems. The model intelligently decides when to invoke a function, extracts typed arguments, and incorporates the output into its final response.
You supply a list of function definitions to the API. When a user prompt requires external data (like weather, database records, or math computations), the model returns structured arguments in tool_calls instead of raw text.
Define tools using standard JSON Schema objects:
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current temperature and conditions for a given city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "Name of the city, e.g. Bengaluru, San Francisco"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city"]
}
}
}
]1from cortiqa import Cortiqa23client = Cortiqa()45response = client.chat.completions.create(6 model="openai/gpt-oss-120b",7 messages=[{"role": "user", "content": "What is the weather in Delhi right now?"}],8 tools=tools,9)1011message = response.choices[0].message1213if message.tool_calls:14 for tool_call in message.tool_calls:15 print("Model requested tool:", tool_call.function.name)16 print("Arguments:", tool_call.function.arguments)1import Cortiqa, { Tool } from "@cortiqa/sdk";23const client = new Cortiqa();45const tools: Tool[] = [6 {7 type: "function",8 function: {9 name: "get_weather",10 description: "Get temperature for a city",11 parameters: {12 type: "object",13 properties: {14 city: { type: "string" },15 },16 required: ["city"],17 },18 },19 },20];2122async function run() {23 const response = await client.messages.create({24 model: "openai/gpt-oss-120b",25 messages: [{ role: "user", content: "What is the weather in Mumbai?" }],26 tools,27 });2829 const toolCalls = response.choices?.[0]?.message?.tool_calls;30 if (toolCalls && toolCalls.length > 0) {31 console.log("Tool requested:", toolCalls[0].function.name);32 console.log("Arguments:", toolCalls[0].function.arguments);33 }34}3536run();After executing the function on your server, send the result back with role: "tool" to get the final answer:
messages = [
{"role": "user", "content": "What is the weather in Delhi right now?"},
message, # the assistant message with tool_calls
{
"role": "tool",
"tool_call_id": message.tool_calls[0].id,
"content": '{"temperature": "28°C", "condition": "Partly Cloudy"}'
}
]
final_response = client.chat.completions.create(
model="openai/gpt-oss-120b",
messages=messages
)
print(final_response.choices[0].message.content)