Skip to main content
Tool calling — sometimes called function calling — lets a model signal that it wants to invoke a specific function in your application rather than generating a plain text reply. Your code executes the function, returns the result to the model in a follow-up message, and the model incorporates that result into its final response. This two-step pattern is the foundation for building agents, enriching responses with real-time data, and automating structured workflows. Meliai’s implementation is fully compatible with the OpenAI tools interface, so existing tool-calling code points at Meliai with no changes beyond the base_url and API key.

Define Tools

Pass a tools 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
Write clear, specific 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 new tool role message to the conversation, then make a second request. The model will use the tool output to generate its final reply.
Python
Always pass the assistant message object (not a reconstructed dict) so that the tool_calls field is preserved exactly as returned by the API.

tool_choice Options

The tool_choice parameter controls how the model decides whether to call a tool.
Use "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 the tools parameter, retrieve its metadata from the models endpoint and inspect supported_parameters.
curl
Look for "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.