Skip to main content
Use Cases
  • Connecting models to live data (databases, calendars, internal APIs) without prompt hacks.
  • Agents that take actions on behalf of users: create tickets, send emails, run queries.
  • Multi-step workflows where the model decides which tools to invoke and in what order.
  • Replacing brittle regex parsing with structured function calls for data extraction.

Quick Start

Enable AI models to call external functions with structured parameters.

Configuration

Tool Definition

Responses API (/v3/router/responses): flat shape: Chat Completions (/v3/router/chat/completions): nested function wrapper:

Tool Choice Options

Tool Message Format

This format applies to the Chat Completions endpoint (/v3/router/chat/completions). On the Responses API, tool results use type: "function_call_output", call_id, and output instead.
When providing tool results back to the model, use the tool role:
The tool_call_id can be null in certain scenarios, such as when tool results are being provided without a corresponding tool call from the model, or when working with providers that don’t require tool call IDs.

Code examples

Function Execution Patterns

Basic Tool Handler

A registry that maps tool names to handler functions, replacing per-call switch statements with a single dispatch path.

Parallel Tool Execution

When the model returns multiple tool calls in one turn, execute them concurrently to reduce latency.

Advanced Use Cases

Database Integration

Expose SQL access as a tool so the model can query data directly. Always sanitize queries before execution.

API Integration

Expose external service actions (email, calendar, notifications) as tools the model can invoke during a conversation.

Multi-Steps Workflows

Run the model in a loop until it produces a final text response, enabling multi-step agent behavior without streaming.

Error Handling

Return structured error objects in tool outputs so the model can report failures or retry with corrected arguments.

Best Practices

Tool design

  • Use clear, descriptive function names.
  • Provide detailed parameter descriptions.
  • Include examples in descriptions.
  • Make tools idempotent when possible.

Schema design

Security considerations

  • Never expose destructive operations directly.
  • Validate all inputs thoroughly.
  • Use allowlists for sensitive operations.
  • Implement proper authentication.
  • Log all tool executions.

Troubleshooting

Tool not being called
  • Check tool descriptions are clear.
  • Verify parameter schemas are correct.
  • Ensure tool_choice is set appropriately.
  • Try more explicit prompts. Invalid arguments
  • Validate JSON Schema thoroughly.
  • Add parameter examples.
  • Check required fields are marked.
  • Simplify complex parameter structures.
Execution failures
  • Implement proper error handling.
  • Add timeout protection.
  • Validate inputs before execution.
  • Return structured error messages.

Limitations

Performance Optimization

Tool caching

Cache results from read-only tools to avoid redundant external calls within a session.

Batch operations

Accept arrays of inputs in a single tool to reduce the number of model turns required for bulk operations.