Tool calling: let the model call your functions
Declare tools as JSON, let the model decide when to call them, run the function on your side and send the result back. The format is OpenAI's; the loop stays in your code.
What tool calling covers
A description contract, not remote execution.
You send a list of tools (name, description, JSON Schema
parameters) and optionally tool_choice. The model answers
either text or one or more tool_calls with JSON arguments.
The API never runs your functions: you execute them, then
send the result back as a role: "tool" message with the matching
tool_call_id.
Typical use cases: booking a slot, reading an internal database, a deterministic calculation, calling a business API. For pure deterministic logic, call your function directly: the model adds no guarantee of accuracy.
Compatible models
Declared in the catalogue and enabled on the backend.
Tool calling depends on the model first: the gateway does not invent tool
calls, it forwards the schema and lets the backend (vLLM) parse the output.
Only models whose tools capability is declared in the
catalogue are configured with a tool parser.
| Model | API id | Context |
|---|---|---|
| Dolphin 3.0 (Llama 3.1 8B) | dolphin-3.0-llama3.1-8b | 32 768 tokens |
| Qwen3.6 35B A3B (abliterated) | qwen3.6-35b-a3b-abliterated | 65 536 tokens |
| Qwen3.8 27B (abliterated) | qwen3.8-27b-abliterated | 65 536 tokens |
Complete example: a tool loop
Definition, call, local execution, second turn.
import json
from openai import OpenAI
client = OpenAI(base_url="https://api.effrenus.com/v1", api_key="sk-ef-...")
def get_weather(city: str) -> dict:
return {"city": city, "temperature_c": 18, "conditions": "cloudy"}
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city (demo data).",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string", "description": "City name"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather in Lyon?"}]
response = client.chat.completions.create(
model="dolphin-3.0-llama3.1-8b",
messages=messages,
tools=tools,
tool_choice="auto",
)
message = response.choices[0].message
messages.append(message)
for call in message.tool_calls or []:
fn = call.function
args = json.loads(fn.arguments or "{}")
result = get_weather(**args) if fn.name == "get_weather" else {"error": f"unknown tool: {fn.name}"}
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
final = client.chat.completions.create(
model="dolphin-3.0-llama3.1-8b",
messages=messages,
tools=tools,
)
print(final.choices[0].message.content)
The second call is not optional: it turns the function result into a natural language answer. It is billed as a normal call (tool schemas count as input tokens).
Read the response
Arguments are a JSON string, not an object.
finish_reason = "tool_calls"means the model wants to call a tool. Afinish_reason = "stop"withouttool_callsis a normal text answer.- Each call has a unique
id: send it back unchanged in thetoolmessage. function.argumentsis a string of JSON (sometimes empty). Parse it defensively: a model can produce invalid JSON, especially with complex schemas.- Several calls can arrive in the same message: run them and send one
toolmessage per call.
Common pitfalls
- Model without tool support. It answers in text and
emits no
tool_calls; check the capability in/v1/models. - Invalid arguments. Wrap parsing in try/except and send the error back to the model instead of crashing the loop.
- Infinite loops. Cap the number of turns (4–8) and the token budget; a model can call the same tool again.
- Over-trust. A tool that writes to a database or triggers a payment must be validated server-side, not only described in the prompt.
- Streaming + tools. Calls arrive in fragments
(
delta.tool_calls, index and partial arguments): accumulate them before executing.
FAQ
Which models support tool calling?
Those whose tools capability is declared in the served catalogue. The
table above reflects this instance's real catalogue; the capability is
also available via /v1/models.
Can I force a tool call?
Yes with tool_choice: "required" (or a named tool). Not all
compatible models respect the constraint perfectly: validate the response
before executing.
Going further
A tool to connect?
Test the loop on a catalogue model with €5 of credits.