Endpunkte
Tool Calling
Lassen Sie Modelle Ihre Funktionen aufrufen: das OpenAI-Format tools, tool_choice, die Aufrufschleife, parallele Aufrufe und Tipps zum Streaming.
Im Playground testenTool Calling (Function Calling) lässt ein Modell Ihren Code bitten, eine Funktion auszuführen, und das Ergebnis dann in seiner Antwort verwenden. api14 nutzt das OpenAI-Format tools für jedes Modell, das Tools unterstützt: OpenAI, Anthropic, Google, Mistral, Qwen, DeepSeek und andere. Um Modelle mit Tool-Unterstützung zu finden, filtern Sie in der Liste unter Modelle nach unterstützten Parametern (supported_parameters enthält tools).
Anfrageparameter
| Parameter | Typ | Beschreibung |
|---|---|---|
tools | array | [{ "type": "function", "function": { "name", "description", "parameters" } }], wobei parameters ein JSON Schema ist. |
tool_choice | string | object | "auto" (Standard), "none", "required" oder { "type": "function", "function": { "name": "get_weather" } }. |
parallel_tool_calls | boolean | Mehrere Tool-Aufrufe in einem Zug erlauben (Standard true, wo unterstützt). |
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api14.com/api/v1",
apiKey: process.env.API14_API_KEY,
});
const result = await client.chat.completions.create({
"model": "openai/gpt-5-mini",
"messages": [
{
"role": "user",
"content": "What is the weather in Istanbul?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
}
]
});
console.log(result.choices[0].message.tool_calls);
Die Schleife
- Senden Sie
messagesundtools. - Hat die Antwort
finish_reason: "tool_calls", führen Sie jeden Eintrag inmessage.tool_callsaus. - Fügen Sie die Assistant-Nachricht hinzu, dann je Aufruf eine Nachricht
{ "role": "tool", "tool_call_id", "content" }, und senden Sie die Anfrage erneut. - Wiederholen Sie dies, bis das Modell mit normalem Inhalt antwortet.
Antwort mit einem Tool-Aufruf:
{
"id": "gen-1760000000-tool1",
"model": "anthropic/claude-sonnet-4.5",
"choices": [
{
"index": 0,
"finish_reason": "tool_calls",
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_01",
"type": "function",
"function": { "name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}" }
}
]
}
}
],
"usage": { "prompt_tokens": 182, "completion_tokens": 21, "total_tokens": 203, "cost": 0.000861 }
}
Die Folgeanfrage enthält das Tool-Ergebnis:
{
"model": "anthropic/claude-sonnet-4.5",
"tools": [ ... same tools ... ],
"messages": [
{ "role": "user", "content": "What's the weather in Istanbul?" },
{ "role": "assistant", "content": null, "tool_calls": [ { "id": "call_01", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}" } } ] },
{ "role": "tool", "tool_call_id": "call_01", "content": "{\"temp_c\": 21, \"sky\": \"clear\"}" }
]
}
Senden Sie tools weiterhin mit jeder Anfrage in der Schleife. Viele Provider lehnen eine tool-Nachricht ab, wenn die Anfrage keine tools-Definitionen enthält.
Tipps
argumentsist ein String mit JSON. Parsen und validieren Sie ihn, denn Modelle können ungültiges JSON erzeugen.- Beim Streaming kommen Tool-Aufrufe als Fragmente in
delta.tool_calls, geordnet nachindex. Fügen Sie diearguments-Strings zusammen, bevor Sie sie parsen. - Um nur an Provider mit Tool-Unterstützung zu routen, setzen Sie
provider: { "require_parameters": true }. Siehe Provider-Routing. - Jede Iteration der Schleife ist eine eigene berechnete Anfrage.
Fehler
Ein Modell ohne Tool-Unterstützung liefert möglicherweise ein Upstream-400 oder 404 ("No endpoints found that support tool use"). Andere Fehler entsprechen denen von Chat Completions. Siehe Fehler.