Skip to content
WRAITHERIXDocsENRU

Tool calling

Tool calling (function calling) lets the model request that your code runs a function, then continue with the result. It uses the standard OpenAI tools format and works with GPT, Claude and Gemini models.

import json
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What's the weather in Paris?"}]
r = client.chat.completions.create(model="gpt-5.6-luna", messages=messages, tools=tools)

When the model decides to call a tool, finish_reason is tool_calls:

call = r.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)
# get_weather {"city":"Paris"}
args = json.loads(call.function.arguments)
result = {"temp_c": 18, "sky": "clear"} # your real implementation here
messages.append(r.choices[0].message)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
final = client.chat.completions.create(model="gpt-5.6-luna", messages=messages, tools=tools)
print(final.choices[0].message.content)
# Paris is currently 18°C with clear skies.
Parameter Effect
tool_choice: "auto" Default. The model decides.
tool_choice: "none" Never call tools.
tool_choice: "required" Must call at least one tool.
tool_choice: {"type":"function","function":{"name":"get_weather"}} Force a specific tool.
parallel_tool_calls: false At most one tool call per turn.

The model may return several entries in tool_calls; answer each one with its own tool message carrying the matching tool_call_id.