Tool calling
Function tools on every protocol, plus gateway-run tool search for agents with hundreds of tools.
このページはまだ翻訳されていません。英語版を表示しています。
Function tools
Standard OpenAI tools / tool_choice. The model returns tool_calls; you run them and send results back as role: "tool" messages. A model whose route cannot call tools answers 400 unsupported_capability; check supported_params on GET /api/models/{slug}.
| Limit | Value |
|---|---|
Tool and function description | 65,536 characters (longer: a 400 stating the limit) |
| Tool call ids | 65,536 characters; signed ids round-trip untouched |
| Duplicate call ids in one assistant turn | 400; fix the history |
/v1/chat/completionsGET/api/models/{slug}from openai import OpenAI
import json
client = OpenAI(base_url="https://api.experientiallabs.ai/v1", api_key="YOUR_API_KEY")
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": "Weather in Paris?"}]
r = client.chat.completions.create(model="gpt-6-luna", messages=messages, tools=tools)
call = r.choices[0].message.tool_calls[0]
messages += [r.choices[0].message, {"role": "tool", "tool_call_id": call.id,
"content": json.dumps({"temp_c": 18})}]
final = client.chat.completions.create(model="gpt-6-luna", messages=messages, tools=tools)
print(final.choices[0].message.content)Tool search
MCP-heavy agents can spend 100k+ tokens per turn on tool definitions. Mark rarely needed tools defer_loading: true and declare a tool-search tool: the gateway withholds deferred definitions, exposes one tool_search function, runs a BM25 (or regex) search when the model calls it, loads the matches and re-dials the model on the same request. You only see the final tool call. Up to 3 search rounds per request; each dispatch spends the request's attempt budget.
| Surface | Declaration |
|---|---|
| Chat Completions | {"type": "openrouter:tool_search", "max_results": 5} |
| Responses | {"type": "tool_search"} |
| Messages | {"type": "tool_search_tool_bm25_20251119", "name": "tool_search"} (regex: tool_search_tool_regex_20251119) |
tool_choice "auto" and "required" work; a tool_choice naming tool_search does not yet. No deferred tools: dropped with tool_search->dropped(no_deferred_tools).
tools = [
{"type": "openrouter:tool_search", "max_results": 5},
*[{"type": "function", "defer_loading": True, "function": t} for t in my_mcp_tools],
]
r = client.chat.completions.create(
model="gpt-6-luna", tools=tools, tool_choice="auto",
messages=[{"role": "user", "content": "Book a flight from SFO to JFK."}],
)
print(r.choices[0].message.tool_calls) # the search round stays inside the gatewayCustom and namespaced tools (Responses)
On native OpenAI routes, custom, namespace and tool_search tool types pass through. Elsewhere a custom tool is served as a function with one string input (a grammar becomes instructions, not enforced) and calls return as custom_tool_call items, disclosed as tools.custom->translated(custom_as_function_input). Chat Completions accepts the same custom tools in its own spelling.
/v1/responses{
"model": "gpt-6-luna",
"input": "Patch the bug in utils.py",
"tools": [{"type": "custom", "name": "apply_patch", "description": "Apply a unified diff"}]
}