base_url and API key.
Define Tools
Pass atools array to the chat completions request. Each element has type: "function" and a function object that describes the name, purpose, and expected parameters using a JSON Schema subset.
Python
description strings. The model uses these descriptions — not your code — to decide whether and when to call a tool, so precision here directly affects reliability.
Full Example
The example below registers two tools, sends a user message, and inspects the model’s response to determine whether a tool call was requested.Python
Sending Tool Results Back
After you run the function, append the original assistant message and a newtool role message to the conversation, then make a second request. The model will use the tool output to generate its final reply.
Python
tool_calls field is preserved exactly as returned by the API.
tool_choice Options
Thetool_choice parameter controls how the model decides whether to call a tool.
tool_choice values
tool_choice values
"required" when you need a guaranteed structured output via a tool and want to avoid a plain-text fallback.
Checking Tool Calling Support
Not every model supports tool calling. To check whether a specific model accepts thetools parameter, retrieve its metadata from the models endpoint and inspect supported_parameters.
curl
"tools" in the supported_parameters array of the response before building tool-calling workflows against a new model.
Use
GET /v1/models to list all available models and filter by supported_parameters to find every model that supports tool calling. Models without "tools" in that list will return an error if you include a tools array in the request.