Skip to main content
Give your AI models access to real-time web data. Instead of relying on training data alone, models can search the web and ground their responses in current information.

What This Unlocks

  • Live web data — No more “I don’t know about recent events”
  • Current information — Break free from training cutoff dates
  • Automatic integration — Search results blend seamlessly into responses
  • Configurable depth — Control how much web context to include

How It Works

Add web_search_options to your API request. AnyAPI passes the search request to the model’s provider, which performs the web search and returns a response grounded in real-time data. The exact search mechanism depends on the provider — Anthropic uses its native web search tool, Google uses grounding with search, OpenAI uses its built-in search, and so on.

Chat Completions API

Basic Example

curl -X POST "https://api.anyapi.ai/v1/chat/completions" \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4",
    "messages": [
      {
        "role": "user",
        "content": "What are the latest developments in AI research this week?"
      }
    ],
    "web_search_options": {
      "search_context_size": "medium"
    }
  }'

The web_search_options Parameter

ParameterTypeDescription
search_context_sizestringAmount of web context to include: "low", "medium" (default), or "high"
user_locationobjectOptional location for localized search results (supported by OpenAI, Anthropic, and Google models)

Localized Search with user_location

Pass a location to get region-specific search results:
Python
response = requests.post(
    "https://api.anyapi.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "anthropic/claude-sonnet-4",
        "messages": [
            {"role": "user", "content": "What's the weather forecast for this weekend?"}
        ],
        "web_search_options": {
            "search_context_size": "low",
            "user_location": {
                "type": "approximate",
                "city": "San Francisco",
                "region": "California",
                "country": "US",
                "timezone": "America/Los_Angeles"
            }
        }
    }
)

Responses API

You can also use web search through the /v1/responses endpoint with the web_search_preview tool:
import requests

response = requests.post(
    "https://api.anyapi.ai/v1/responses",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "openai/gpt-5",
        "input": "What is happening in the stock market today?",
        "tools": [
            {
                "type": "web_search_preview",
                "search_context_size": "medium"
            }
        ]
    }
)

print(response.json())

Search Context Levels

LevelContextSpeedBest For
"low"MinimalFastestQuick fact-checks, simple questions
"medium"BalancedModerateNews updates, general research
"high"MaximumSlowestDeep analysis, complex research

Real-World Examples

Latest News

Python
response = requests.post(
    "https://api.anyapi.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "google/gemini-2.5-flash",
        "messages": [
            {"role": "user", "content": "What are the top tech news stories today?"}
        ],
        "web_search_options": {
            "search_context_size": "medium"
        }
    }
)

Deep Research with Perplexity

Python
response = requests.post(
    "https://api.anyapi.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "perplexity/sonar-pro",
        "messages": [
            {"role": "user", "content": "Analyze current trends in renewable energy investments"}
        ],
        "web_search_options": {
            "search_context_size": "high"
        }
    }
)

Reasoning Over Web Results

Python
response = requests.post(
    "https://api.anyapi.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "openai/o3",
        "messages": [
            {"role": "user", "content": "Compare the latest quarterly earnings of NVIDIA vs AMD"}
        ],
        "web_search_options": {
            "search_context_size": "high"
        }
    }
)

Supported Models

Web search works with 800+ models on AnyAPI, including:
  • OpenAI: GPT-5, GPT-5 Mini, GPT-5.4, GPT-4o, GPT-4o Search Preview, o3, o4-mini, and more
  • Anthropic: Claude Opus 4.6, Claude Sonnet 4.6, Claude Haiku 4.5, and more
  • Google: Gemini 2.5 Pro, Gemini 2.5 Flash, Gemini 3 Pro/Flash Preview, and more
  • xAI: Grok 4, Grok 4.1 Fast, Grok 3, and more
  • Perplexity: Sonar, Sonar Pro, Sonar Deep Research, Sonar Reasoning Pro
  • DeepSeek: DeepSeek V3.2, DeepSeek R1, and more
  • Qwen: Qwen3 Max, Qwen3 Coder Plus, Qwen3 235B, and more
  • Meta: Llama 4 Maverick, Llama 4 Scout, Llama 3.1 405B, and more
  • Mistral: Mistral Large, Codestral, Devstral, Magistral Small, and more
Check the model database for the full list of models with web search support.

Pricing

Web search incurs an additional per-search cost on top of regular token pricing. The exact cost depends on the model and provider.

Pro Tips

  1. Match context to your needs: Quick questions = "low", research = "high"
  2. Be specific in your prompts: “Tesla Q4 2025 earnings” beats “stock market”
  3. Use with reasoning models: Models like o3, DeepSeek R1, and Claude with extended thinking can reason over web results for deeper analysis
  4. Use Perplexity for research: Sonar models are built for search and return citations by default

Things to Keep in Mind

  • Slight latency: Web search adds a moment to response time
  • Cost scaling: Higher search_context_size uses more tokens and increases cost
  • Rate limits: Standard rate limits apply to requests with web search

Give your AI models internet access. Web search turns any model into a research assistant that knows what happened five minutes ago.