Eterial Docs
API reference

Tool calling

Function definitions, tool calls, and the round trip back.

Tools work as they do in the OpenAI API: you describe functions in tools, the model may answer with tool_calls instead of prose, you run them and send the results back as messages with role: "tool".

The round trip

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather for a city.",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

messages = [{"role": "user", "content": "What should I wear in Tallinn today?"}]

first = client.chat.completions.create(
    model="minimax-m2.7", messages=messages, tools=tools,
)

call = first.choices[0].message.tool_calls[0]
args = json.loads(call.function.arguments)   # arguments are a JSON string

messages.append(first.choices[0].message)
messages.append({
    "role": "tool",
    "tool_call_id": call.id,
    "content": json.dumps(get_weather(args["city"])),
})

second = client.chat.completions.create(
    model="minimax-m2.7", messages=messages, tools=tools,
)

tool_choice works as usual: "auto", "none", "required", or a named function.

Streaming

Tool calls arrive in fragments, exactly as with OpenAI: the function name comes first, then the arguments accumulate across chunks. Buffer by index until the stream ends before parsing anything as JSON.

A web-search tool is not your tool

Eterial runs web search itself rather than handing it to the model, so a web_search entry in tools is taken as a request for that and never comes back to you as a tool_call. Your own functions are unaffected, and mixing the two in one request is fine — both need the same tools capability. See Web search.

On this page