Tool Calling
Large models gain the ability to work with external systems through tool calling. Rather than stopping at pure text generation, the model can invoke tools in those external systems to extend what it can do.
1. Models That Support Tool Calling
Tool calling is available on the following models:
GLM
- GLM-5.1
- GLM-5
- GLM-4.7
MiniMax
- MiniMax-M2.5
- MiniMax-M2.1
2. How to Pass Tools
2.1 Requesting with the OpenAI Library
from openai import OpenAI
import json
client = OpenAI(
base_url="https://api.watt-cloud.com/v1/chat/completions",
api_key="${API_KEY}"
)
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
}
}]
2.2 Adding the tools Parameter over REST
{
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
}
}
]
}
3. Complete Walkthrough
The script below covers one full round trip: the user asks a question, the model responds with a tool call, the tool's result is fed back into the conversation, and the model produces its final answer.
from openai import OpenAI
import json
client = OpenAI(
base_url="https://api.watt-cloud.com/v1/chat/completions",
api_key="${API_KEY}"
)
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
}
}]
messages = [{"role": "user", "content": "What's the weather like in Beijing?"}]
# First request: the model answers with a tool call
resp = client.chat.completions.create(
model="${MODEL_NAME}",
messages=messages,
tools=tools,
tool_choice="auto"
)
# Pull the tool call out of the response
tool_call = resp.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
# Stand-in for actually running the tool
weather_result = f"{args['city']} sunny 25°C"
# Second request: hand the tool result back to the model
messages.append(resp.choices[0].message)
messages.append({"role": "tool", "tool_call_id": tool_call.id, "content": weather_result})
final = client.chat.completions.create(
model="${MODEL_NAME}",
messages=messages
)
print(final.choices[0].message.content)
What the Model Returns
<think>The weather data for Beijing has come back. Time to write a friendly reply for the user.
</think>
Beijing is seeing **sunny** skies at the moment, and the temperature stands at **25°C**. Conditions are great for spending time outdoors — just remember sunscreen and plenty of water.