Tool & function calling
Define tools as JSON schemas; the model decides when to call them and returns structured arguments you execute. All 154 tool-capable models on MeshTok follow the OpenAI tools API. Top picks for agentic work: DeepSeek V4 Pro, GLM 5.2, Claude Sonnet 5.
Define a tool
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a city.",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City name" },
"unit": { "type": "string", "enum": ["c", "f"] }
},
"required": ["city"]
}
}
}] Python: full agentic loop
from openai import OpenAI client = OpenAI(base_url="https://meshtok.com/v1", api_key="sk-...") messages = [{"role": "user", "content": "What's the weather in Tokyo?"}] # 1. Let the model decide which tool to call resp = client.chat.completions.create( model="deepseek/deepseek-v4-pro", messages=messages, tools=tools, ) tool_call = resp.choices[0].message.tool_calls[0] print(tool_call.function.name, tool_call.function.arguments) # get_weather {"city":"Tokyo","unit":"c"} # 2. Execute the tool yourself, then feed the result back import json result = get_weather(**json.loads(tool_call.function.arguments)) messages.append(resp.choices[0].message) messages.append({ "role": "tool", "tool_call_id": tool_call.id, "content": json.dumps(result), }) # 3. Model produces the final natural-language answer final = client.chat.completions.create(model="deepseek/deepseek-v4-pro", messages=messages) print(final.choices[0].message.content)
Parallel tool calls
Frontier models (GPT-5.x, Claude 5, GLM 5.2) can request multiple tool calls in a single response. Iterate message.tool_calls, dispatch them concurrently, then append all results before the next turn.
Forcing tool use
Pass tool_choice: {"type":"function","function":{"name":"get_weather"}} to force a specific tool, or "required" to force any tool. Use "auto" (default) to let the model decide.