Choose a model with tool_calling: true in the catalog. Declare functions in tools.
Declare a function
curl -X POST 'https://redrouter.org/v1/chat/completions' \
-H "Authorization: Bearer $REDROUTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"messages": [
{
"content": "Look up CVE-2024-3094.",
"role": "user"
}
],
"model": "glm-5.3-flash-rr",
"tool_choice": "auto",
"tools": [
{
"function": {
"description": "Look up a CVE by ID.",
"name": "lookup_cve",
"parameters": {
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
],
"type": "object"
}
},
"type": "function"
}
]
}'
import os, json
from urllib.request import Request, urlopen
body = json.loads(r'''{
"messages": [
{
"content": "Look up CVE-2024-3094.",
"role": "user"
}
],
"model": "glm-5.3-flash-rr",
"tool_choice": "auto",
"tools": [
{
"function": {
"description": "Look up a CVE by ID.",
"name": "lookup_cve",
"parameters": {
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
],
"type": "object"
}
},
"type": "function"
}
]
}''')
request = Request(
"https://redrouter.org/v1/chat/completions",
method="POST",
data=json.dumps(body).encode(),
headers={
"Authorization": "Bearer " + os.environ["REDROUTER_API_KEY"],
"Content-Type": "application/json",
},
)
with urlopen(request) as response:
print(json.load(response))
const key = process.env.REDROUTER_API_KEY;
const response = await fetch("https://redrouter.org/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${key}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"messages": [
{
"content": "Look up CVE-2024-3094.",
"role": "user"
}
],
"model": "glm-5.3-flash-rr",
"tool_choice": "auto",
"tools": [
{
"function": {
"description": "Look up a CVE by ID.",
"name": "lookup_cve",
"parameters": {
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
],
"type": "object"
}
},
"type": "function"
}
]
}),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
Return results
Read assistant tool_calls. Execute each function in your application. Append the assistant message, then one tool message per call with a matching tool_call_id. Send the conversation again.
Respond to every assistant call before the next message. RedRouter does not execute tools.
Function limits
Declare up to 128 unique functions, totaling at most 256 KiB. Names contain 1 to 64 letters, digits, underscores, or hyphens. Use auto, none, required, or a named function for tool_choice. Set parallel_tool_calls to control parallel requests.
Function definitions accept strict as a boolean or null. Schema enforcement depends on the model.