Skip to main content

Overview

The Agent API provides tools that extend model capabilities beyond their training data. Tools must be explicitly configured in your API request—once enabled, models autonomously decide when to use them based on your instructions. Enable tools by adding them to the tools array in your request:

Web Search Tool

The web_search tool allows models to perform web searches with advanced filtering capabilities. Use it when you need current information, news, or data beyond the model’s training cutoff. Pricing: $5.00 per 1,000 search calls ($0.005 per search), plus token costs.

Example

Key Parameters

Use - prefix to exclude domains: "-reddit.com" excludes Reddit from results. Lower max_tokens_per_page to reduce context token costs.

Fetch URL Tool

The fetch_url tool fetches and extracts content from specific URLs. Use it when you need the full content of a particular web page, article, or document rather than search results. Pricing: $0.50 per 1,000 requests ($0.0005 per fetch), plus token costs.

Example

When to Use

Combine web_search and fetch_url for comprehensive research: search to find relevant pages, then fetch full content from the most relevant results.

Function Calling

Function calling allows you to define custom functions that models can invoke during a conversation. Unlike built-in tools, custom functions let you connect the model to your own systems—databases, APIs, business logic, or any external service. Pricing: No additional cost (standard token pricing applies).

How It Works

Function calling follows a multi-turn conversation pattern:
  1. Define functions with names, descriptions, and parameter schemas
  2. Send your prompt with function definitions
  3. Model returns a function_call item if it needs to call a function
  4. Execute the function in your code
  5. Return results as a function_call_output item
  6. Model uses the results to generate its final response

Example

Key Properties

The arguments field in function calls is a JSON string, not a parsed object. Always use json.loads() (Python) or JSON.parse() (JavaScript) to parse it.
Write clear, specific function descriptions. The model uses these to decide when to call each function. Include details about what the function returns and any constraints.

Next Steps

Agent API Quickstart

Get started with the Agent API.

Models

Explore direct model selection and third-party models.

API Reference

View complete endpoint documentation.

Output Control

Configure streaming responses and structured outputs with JSON schema.