Inference
Tools
Your application executes tool calls and returns their results.
Define a function
Add tools to a POST /v1/chat/completions request using the
quickstart setup:
{
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}The model can answer directly or return message.tool_calls. To require this
function, set tool_choice to
{"type": "function", "function": {"name": "get_weather"}}.
Return the result
Append the assistant message, validate and execute each tool call, then append one result per call:
{
"role": "tool",
"tool_call_id": "<id-from-tool_calls>",
"content": "<your-function-result>"
}Resend the conversation with the same tools. For streaming, assemble all argument fragments before parsing or executing a call.