// guides
Function calling
Describe functions your code can run. The model decides when to call one and returns the arguments as JSON; your code runs it and sends the result back.
Models with function calling
- GLM-5.3 ·
z-ai/glm-5.3 - GLM 5.3 Flash ·
z-ai/glm-5.3-flash - Minimax M3 ·
minimax/minimax-m3 - OpenAI gpt-oss-120b ·
openai/gpt-oss-120b - Nemotron Lightning 3.5 30B A3B ·
nvidia/nemotron-lightning-3.5-30b-a3b - Nemotron 3 Ultra ·
nvidia/nemotron-3-ultra - Kimi K3 ·
moonshotai/kimi-k3 - Qwen 3.8 Max ·
qwen/qwen3.8-max - DeepSeek V4.1 Flash 1017 ·
deepseek/deepseek-v4.1-flash-1017 - DeepSeek V4.1 Flash ·
deepseek/deepseek-v4.1-flash-paid - GLM 5.3 Flash ·
z-ai/glm-5.3-flash-paid - Kimi K3.1 Pro ·
moonshotai/kimi-k3.1-pro - MiniMax M3.1 Flash ·
minimax/minimax-m3.1-flash
How it works
- Send your messages with a
toolslist describing each function and its JSON Schema parameters. - If the model wants a function, the reply has
finish_reason: "tool_calls"and atool_callslist with the function name and arguments. - Run the function in your code.
- Append the assistant message and a
toolmessage with the result (matchingtool_call_id), then call the API again for the final answer.
Example
Python
import json
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "Is it raining in Pune?"}]
reply = client.chat.completions.create(model="nvidia/nemotron-lightning-3.5-30b-a3b", messages=messages, tools=tools)
call = reply.choices[0].message.tool_calls[0]
result = get_weather(**json.loads(call.function.arguments)) # your code
messages += [
reply.choices[0].message,
{"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)},
]
final = client.chat.completions.create(model="nvidia/nemotron-lightning-3.5-30b-a3b", messages=messages, tools=tools)
print(final.choices[0].message.content)Controlling tool use
tool_choice | Effect |
|---|---|
"auto" | Default. The model decides whether to call a function. |
"none" | Never call a function; reply with text. |
"required" | Always call at least one function. |
{"type": "function", "function": {"name": "get_weather"}} | Call this specific function. |
warning
Always validate the arguments before running a function. The model can produce arguments that don't match your schema.