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.| Type | Tools | Use Case |
|---|---|---|
| Built-in | web_search, fetch_url | Real-time web information retrieval |
| Custom | Your functions | Connect to databases, APIs, business logic |
tools array in your request:
Web Search Tool
Theweb_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
| Filter | Type | Description | Limit |
|---|---|---|---|
search_domain_filter | Array of strings | Filter by specific domains (allowlist or denylist with - prefix) | Max 20 domains |
search_recency_filter | String | Filter by time period: "day", "week", "month", "year" | - |
search_after_date | String | Filter results published after this date (format: "M/D/YYYY") | - |
search_before_date | String | Filter results published before this date (format: "M/D/YYYY") | - |
max_tokens_per_page | Integer | Control the amount of content retrieved per search result | - |
Fetch URL Tool
Thefetch_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
Use fetch_url when… | Use web_search when… |
|---|---|
| You have a specific URL | You need to find relevant pages |
| You need full page content | You need snippets from multiple sources |
| Analyzing a particular document | Researching a broad topic |
| Verifying specific claims | Finding current news or events |
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:- Define functions with names, descriptions, and parameter schemas
- Send your prompt with function definitions
- Model returns a
function_callitem if it needs to call a function - Execute the function in your code
- Return results as a
function_call_outputitem - Model uses the results to generate its final response
Example
Key Properties
| Property | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "function" |
name | string | Yes | Function name the model will use to call it |
description | string | Yes | Clear description of what the function does and when to use it |
parameters | object | Yes | JSON Schema defining the function’s parameters |
strict | boolean | No | Enable strict schema validation |
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.