Prerequisites
- An Arbytra API key
- Python 3.10+ with the OpenAI SDK (
pip install openai) or the arbytra SDK (pip install arbytra)- OR Node.js 18+ with the OpenAI SDK (
npm install openai) or@arbytra/sdk(npm install @arbytra/sdk)
- OR Node.js 18+ with the OpenAI SDK (
Define tools
Define tools as JSON schemas describing the function signature:Call tools
Send a request with tools and check the response:Execute tool calls
After receiving tool calls, execute them and send the results back:model_dump(exclude_none=True) preserves all tool call fields while stripping None fields that some providers reject. Some providers attach a cryptographic signature to tool calls for multi-turn verification. Using model_dump(exclude_none=True) ensures the signature is echoed back correctly.
Use multiple tools
Define multiple tools in the same request:Use parallel tool calls
Models can request multiple tool calls in parallel:Control tool choice
Control which tools the model can use:tool_choice controls whether the model calls tools:
"auto"(default): The model decides whether to call a tool based on the conversation."required": The model must call at least one tool. Most providers support this; see below for exceptions.{"type": "function", "function": {"name": "..."}}: The model must call the specified tool."none": The model won’t call any tools. Arbytra ensures no tool calls are produced, even on providers that don’t respect"none". These requests can route to more providers, improving availability.
Provider-specific behavior
tool_choice with reasoning models
Some providers activate reasoning by default for certain models. When reasoning is active, these providers don’t fully support tool_choice="required" or named tool_choice. Arbytra handles this automatically:
These models still call tools reliably with
tool_choice="auto". The constraint only affects forcing tool use.
See Extensions and Thinking for details on reasoning_effort and how Arbytra translates it per provider.
These constraints originate from the providers’ APIs. Third-party hosts (e.g., Fireworks) serving the same model weights typically don’t have this restriction.
tool_choice="required" provider support
Arbytra filters out providers known not to honor tool_choice="required" when routing these requests.
If no capable provider is available for the requested model, the API returns a
tool_choice_required_not_supported error. To resolve this:
- Use
tool_choice: "auto". Models still call tools when prompted appropriately. - Remove the provider constraint to allow routing to a capable provider.
tool_choice: "auto", models still call tools when the prompt makes it appropriate. The model isn’t forced to call a tool and may respond with text instead. In practice, well-prompted requests still produce tool calls reliably.
Named tool_choice ({type: "function", function: {name: "..."}}) isn’t affected by this filtering. Only the string value "required" triggers provider filtering.
If you need guaranteed forced tool use, exclude affected providers using
exclude_providers to route to a provider that fully supports tool_choice: "required".Stream tool calls
Reassemble streamed tool call chunks into complete function calls:Convert legacy functions
Arbytra auto-converts the deprecatedfunctions/function_call parameters to the modern tools/tool_choice format:
Conversion only runs when the legacy field is present and the modern field is absent. If both are present, the modern field takes precedence.
Use
tools/tool_choice for new code. Arbytra supports the legacy format for backward compatibility.
Arbytra also normalizes legacy message formats in chat history:
Your existing chat histories with legacy function messages work without changes.
Most providers support tool calling, but subfeatures like
parallel_tool_calls vary. Check /v1/directory/models for current capability details.Best practices
Clear Descriptions
Write clear, specific function descriptions so the model knows when to use them.
Validate Arguments
Always validate tool call arguments before executing.
Error Handling
Return helpful error messages in tool results when execution fails.
Limit Tools
Only include relevant tools to reduce confusion and latency.