Tool Calling
Tool calling lets the model decide to invoke one of your functions to fetch data or take action — for example, looking up the weather, querying a database, or sending an email. The model doesn’t execute the tool itself; it returns the function name and arguments, your code runs the function, and you send the result back in a follow-up message.
This guide covers function tools that your application executes. For tools executed automatically by Mixlayer, see Server-Side Tools.
Mixlayer supports tool calling through both Chat Completions and Responses. The model behavior is the same, but the request and follow-up item formats differ.
The loop
- Define your tools in the
toolsarray on the request. - Send the request. If the model decides to invoke a tool, Chat Completions returns
finish_reason: "tool_calls"with an assistanttool_callsarray. Responses returns afunction_calloutput item. - Execute the tool in your code.
- Send a follow-up request with the tool result. Chat Completions uses a
toolrole message. Responses uses afunction_call_outputinput item. - The model returns its final answer, conditioned on the tool result.
Defining tools
The parameters field is a JSON Schema describing the tool’s arguments.
Chat Completions
Responses
Set strict: true if you want the model’s arguments to be guaranteed to match the schema.
Tool names must be 1-64 characters and contain only ASCII letters, numbers, _, or -.
Sending Tool Results
Chat Completions
Responses
Worked example: Chat Completions weather lookup
The full loop, end to end:
curl
Python
TypeScript
Rust
Streaming with tool calls
When stream: true and the model invokes a tool, tool_calls arrive in deltas across multiple chunks. Each chunk’s delta.tool_calls[].function.arguments is a partial JSON string fragment — accumulate them per tool_calls[].index until the final chunk arrives with finish_reason: "tool_calls".
Notes
Chat Completions does not currently support the OpenAI tool_choice
parameter. Responses supports tool_choice: "auto" and tool_choice: "none". Forced tool choice is not supported.
Tool calling is supported on the Qwen 3.5 family. See Models for the up-to-date list of capable models.