100 free credits on signup — no cardSee pricing

apipick
blog · tutorial10 min read

How to Enable Web Search in OpenAI, Gemini & Claude APIs

Sarah ChoyPublished November 24, 2026Updated November 25, 202610 min read
How to Enable Web Search in OpenAI, Gemini & Claude APIs

All three APIs turn on web search with one entry in the tools array: web_search for OpenAI, google_search for Gemini, and web_search_20250305 or newer for Claude. Here is the exact code for each, what it costs per 1,000 searches, the limits on domains and models, and when a standalone search API is the better fit.

TL;DR

  • •OpenAI: add {"type": "web_search"} to tools in the Responses API. $10 per 1,000 calls plus search content tokens at model rates.
  • •Gemini: add {"type": "google_search"} (Interactions API) or {"google_search": {}} (generateContent). On Gemini 3 and newer, 5,000 search queries a month are free, then $14 per 1,000 queries.
  • •Claude: add {"type": "web_search_20250305", "name": "web_search"} (or the newer 20260209 / 20260318 versions with dynamic filtering) to tools. $10 per 1,000 searches plus result tokens as input.
  • •In all three, the model decides whether and how often to search, and you pay per search, not per question. In our Gemini test on 2026-11-24, one question triggered two billed queries.
  • •Use a standalone search API when you need the same search across models, one predictable call per question, or the raw results for your own pipeline. apipick costs $15 per 1,000 calls and bills only HTTP 200 responses.

How do you enable web search in the OpenAI, Gemini and Claude APIs?

Add one built-in tool to the tools array of the request: {"type": "web_search"} in the OpenAI Responses API, {"type": "google_search"} in the Gemini Interactions API ({"google_search": {}} in generateContent), and {"type": "web_search_20250305", "name": "web_search"} or a newer version in the Claude Messages API. The provider then runs the searches, feeds the results to the model and returns an answer with citations. You pay a fee per search on top of model tokens.

Everything below was checked against each provider's official documentation on 2026-11-24, and the Gemini examples were run on that day.

Built-in web search compared with a standalone search API, as of 2026-11-24. Sources: OpenAI web search guide and pricing, Google AI Studio grounding docs and pricing, Anthropic web search tool docs, apipick pricing.
OpenAIGeminiClaudeapipick search API
What to add{"type": "web_search"}{"type": "google_search"}{"type": "web_search_20250305", "name": "web_search"}POST /api/search/web
EndpointResponses APIInteractions API or generateContentMessages APIAny model, your code
Price per 1,000$10 per call$14 per query after 5,000 free a month$10 per search$15 per call
Search tokensBilled at model ratesNot billed as inputBilled as input tokensYou choose what to send
Domain filterAllow or block, 100 eachBlock only, Vertex AI onlyAllow or block, not bothYour code filters results
Citationsurl_citation annotationsGrounding metadataAlways onTitle, URL, snippet per result
Who decides to searchThe modelThe modelThe modelYou

How do you enable web search in the OpenAI API?

Use the Responses API and add {"type": "web_search"} to tools. The model decides whether to search, and the answer comes back with inline url_citation annotations that hold the URL, the title and the character range they support.

from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-6.2-astra",
    tools=[{"type": "web_search"}],
    input="What was a positive news story from today?",
)

print(response.output_text)
curl "https://api.openai.com/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-6.2-astra",
    "tools": [{"type": "web_search"}],
    "input": "What was a positive news story from today?"
  }'

These are OpenAI's own examples from its web search guide. The options that matter in practice:

OptionWhat it does
filters.allowed_domains / blocked_domainsLimit or exclude up to 100 domains each, without https://; subdomains are included
user_locationApproximate country (ISO code), city, region, timezone
search_context_sizelow, medium (default) or high
external_web_accessfalse switches to an offline, cache-only mode
include: ["web_search_call.action.sources"]Returns every URL consulted, not only the cited ones
tool_choice: "required"Forces a search; with "auto" it is optional

Limits to know. The search context window is capped at 128k tokens even when the model supports more. With gpt-5, web search needs a reasoning effort above minimal. The older web_search_preview tool still works for legacy integrations but does not support filters. In Chat Completions there is no tool to add: you switch to a search model such as gpt-5-search-api.

Price. $10 per 1,000 web search calls, plus the search content tokens at the model's own rates. The legacy preview tool on non-reasoning models is $25 per 1,000 calls with free search content tokens (OpenAI pricing page, 2026-11-24).

How do you turn on Grounding with Google Search in the Gemini API?

Add the google_search tool: {"type": "google_search"} in the Interactions API, or {"google_search": {}} in a generateContent request. Google's current docs use the Interactions API; generateContent still accepts the tool and returns groundingMetadata.

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-4-hydrogen",
    input="Who won the euro 2024?",
    tools=[{"type": "google_search"}],
)

print(interaction.output_text)
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Api-Revision: 2026-05-20" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-4-hydrogen",
    "input": "Who won the euro 2024?",
    "tools": [{"type": "google_search"}]
  }'

If your code still calls generateContent, the tool goes in the same place:

{"contents": [{"role": "user", "parts": [{"text": "Which team won the 2026 World Series?"}]}],
 "tools": [{"google_search": {}}]}

We sent exactly that request to gemini-3.8-flash on 2026-11-24. The model answered "The Milwaukee Brewers won the 2026 World Series" and the response listed two search queries in webSearchQueries, so one question cost two billable queries. The sources in groundingChunks came back as vertexaisearch.cloud.google.com/grounding-api-redirect/… links with only the domain as the title, and no page text.

What else to know:

  • Response fields. generateContent returns groundingMetadata with webSearchQueries, groundingChunks, groundingSupports (which text segment each source supports) and searchEntryPoint (rendered HTML for search suggestions). The Interactions API returns google_search_call, google_search_result and url_citation annotations instead. Google's Terms of Service set the rules for showing search suggestions in your UI.
  • Filters. The Gemini Developer API supports timeRangeFilter on the tool. Excluding domains (exclude_domains) is documented for Vertex AI; it worked when we tested it there on 2026-11-24. There is no allow-list.
  • Models. Gemini 4, Gemini 3.x and Gemini 2.5 / 2.0 models support the tool. Older models used google_search_retrieval.
  • Price. Gemini 3 and newer are billed per search query: 5,000 free a month shared across those models, then $14 per 1,000, with a default cap of 1,500 grounding requests a day on the paid tier of the Developer API. Gemini 2.5 is billed per grounded prompt: $35 per 1,000 after 1,500 free a day.

How often Gemini searches, and how accurate it is with and without grounding, is the subject of our 40-question test of Google Search grounding vs a search API. This page sticks to the setup.

How do you enable the web search tool in the Claude API?

Add {"type": "web_search_20250305", "name": "web_search"} to tools in the Messages API, or web_search_20260209 / web_search_20260318 on Claude 4.6 and newer models to get dynamic filtering. Claude runs the searches on Anthropic's side and the response contains the queries, the results and cited text in one reply.

import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=4096,
    messages=[{"role": "user", "content": "What's the weather in NYC?"}],
    tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 5}],
)

for block in response.content:
    if block.type == "text":
        print(block.text)
curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 4096,
    "messages": [{"role": "user", "content": "What is the weather in NYC?"}],
    "tools": [{"type": "web_search_20250305", "name": "web_search", "max_uses": 5}]
  }'

Both examples follow Anthropic's web search tool documentation. The tool versions and options:

SettingDetail
web_search_20250305Basic search, every supported model and platform
web_search_20260209Adds dynamic filtering: Claude filters results in code before they reach the context
web_search_20260318Adds response_inclusion to drop filtered result blocks from the response
max_usesCaps searches per turn; failed searches count
allowed_domains / blocked_domainsOne or the other, never both (400 error)
user_locationtype: "approximate" plus city, region, country, timezone

Limits to know. Citations are always on; each one carries url, title and up to 150 characters of cited_text. The full result text comes back as encrypted_content, which you must send back unchanged in later turns but cannot read. Errors such as max_uses_exceeded arrive as HTTP 200 with an error object inside the web_search_tool_result block. An organization admin can turn web search off in the Claude Console, and then the request fails with a 400. On Google Cloud's Google-managed Claude and on Azure-hosted Microsoft Foundry deployments, only the basic version is available.

Price. $10 per 1,000 searches plus standard token costs; search results count as input tokens in that turn and in later turns. A search that errors is not billed.

What does a web search really cost per question?

The cost per question is the search fee times the number of searches the model runs, plus the tokens the results add, and with built-in tools the model controls both. That is why the per-1,000 prices above do not compare directly.

  • Number of searches. Each tool lets the model run several searches per question. Our Gemini request above ran two. In our November 14 grounding test Gemini averaged 1.9 to 2.85 queries per question, and 16 on one question. Claude's max_uses caps this per turn; the OpenAI and Gemini pages we checked list no equivalent cap.
  • Result tokens. OpenAI bills search content tokens at the model's rates, and Claude counts results as input tokens, so a more expensive model makes every search more expensive. Gemini does not bill grounding text as input tokens.
  • Free allowances. Gemini gives 5,000 queries a month on Gemini 3 and newer. Amazon Bedrock AgentCore's Web Search, a standalone option for agents on AWS, is $7 per 1,000 queries and has given 5,000 free queries a month since 2026-11-17 (AWS announcement).

A standalone search API reverses this: you decide how many calls a question gets (usually one) and how many results go into the prompt. In our earlier test, five apipick results added about 1,400 input tokens per question.

When is the built-in search tool not enough?

Built-in search is the fastest way to ground one provider's model, but it ties the search to that provider and leaves the model in charge of it. Five situations where teams move the search into their own code:

  1. You use more than one model. Google Search grounding only works with Gemini, and Claude's tool only with Claude. A router that sends some questions to GPT and others to Claude would get three different search engines, prices and citation formats.
  2. You need one predictable cost per question. With built-in tools the model chooses how many searches to run. If you search first and pass the results in, every question costs exactly one call.
  3. You need to control the sources. Domain filters differ by provider, and the Gemini Developer API has no allow-list. With results in your own code you can drop, re-rank, log or cache them before the model sees anything.
  4. You need the raw results. Claude returns result text encrypted, and Gemini returns redirect links and domain names. For your own RAG pipeline, evaluation set or audit log you need readable titles, URLs and snippets.
  5. You want to test models fairly. Comparing models is only fair when each gets the same evidence. A separate search call gives every model identical input.

The trade-off is real: a search API is one more call and a few lines of glue code, and in our Gemini test Google's grounding was faster than fetching results and passing them in.

How do you add the same web search to any model?

Call a search API before the model, then pass the results into the prompt, or register the search as a function tool the model can call. With apipick it is one POST request:

curl -X POST https://www.apipick.com/api/search/web \
  -H "x-api-key: $APIPICK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "2026 World Series winner", "max_num_results": 5}'

The real response from 2026-11-25, trimmed to the first two results with shortened snippets:

{
  "query": "2026 World Series winner",
  "results": [
    {
      "title": "2026 World Series: Brewers vs. Rays Results, MVP & Recap",
      "url": "https://swipesports.com/encyclopedia/2026-world-series/",
      "snippet": "The Milwaukee Brewers won the 2026 World Series. They beat the Tampa Bay Rays four games to one and clinched with a 4-1 win in Game 5 at Tropicana Field on October 28, 2026.…",
      "source_type": "website",
      "published_at": null,
      "score": 0.97,
      "data_type": "unstructured"
    },
    {
      "title": "World Series 2026: Milwaukee Brewers beat Tampa Bay Rays to become MLB champions - BBC Sport",
      "url": "https://www.bbc.co.uk/sport/baseball/articles/c5x2v991l0lvo",
      "snippet": "# Brewers win first World Series in 57-year history…",
      "source_type": "website",
      "published_at": null,
      "score": 0.9550247754091665,
      "data_type": "unstructured"
    }
  ],
  "result_count": 5,
  "credits_used": 15
}

Each result has title, url, snippet, published_at and a relevance score; you can also pass country_code, start_date and end_date. The same results then go to whichever model you call:

import os, requests

def search(query: str) -> str:
    r = requests.post(
        "https://www.apipick.com/api/search/web",
        headers={"x-api-key": os.environ["APIPICK_API_KEY"]},
        json={"query": query, "max_num_results": 5},
        timeout=60,
    )
    r.raise_for_status()
    return "\n\n".join(
        f"[{i + 1}] {x['title']} ({x['url']})\n{x['snippet']}"
        for i, x in enumerate(r.json()["results"])
    )

question = "Who won the 2026 World Series?"
prompt = f"Search results:\n{search(question)}\n\nAnswer with citations: {question}"
# Send `prompt` to OpenAI, Gemini, Claude or a local model; the evidence is identical.

A web search costs 15 credits, which is $15 per 1,000 calls at $1 per 1,000 credits, and only HTTP 200 responses are charged (pricing). New accounts get 100 free credits, enough for six searches. If you want the model to decide when to search instead, our tutorial on adding a web search tool to an OpenAI or Claude agent wires the same endpoint in as a function tool, and the web search API page has the tool schema.

Which option should you choose?

Built-in search: one provider, quick start
If all your traffic goes to one provider, turn on its tool. It is one line, the provider handles citations, and Gemini's 5,000 free queries a month cover small apps. Set max_uses on Claude and keep prompts from inviting the model to skip the search.
A standalone search API: several models, fixed cost, your own pipeline
If you route between models, need one search per question, or want to filter, store and evaluate the results yourself, run the search in your code. apipick is $15 per 1,000 calls and is more expensive per call than every built-in tool here; what you get is the same results for every model and a predictable bill. For other providers' prices, see our Tavily alternatives comparison.

What does this guide not cover?

  • Prices and model names change quickly. Every price and parameter here was checked on 2026-11-24; re-check the provider pages before you budget.
  • Deep research agents. OpenAI, Google and Anthropic also offer multi-step research products and agents with their own pricing. This page covers only the search tool in a single API request.
  • Azure OpenAI, Vertex AI and Bedrock. Cloud platforms can differ from the first-party APIs in which tool versions and filters they support, as Claude's basic-only search on some platforms shows.
  • Search quality. We did not benchmark OpenAI's or Claude's search results against each other here; for Gemini's accuracy with and without grounding, see the 40-question test.

Sources (checked 2026-11-24): OpenAI web search guide, OpenAI pricing, Grounding with Google Search, Gemini API pricing, Vertex AI grounding, Claude web search tool, AgentCore pricing.

Frequently Asked Questions

Does the OpenAI API have built-in web search?

Yes. In the Responses API, add {"type": "web_search"} to the tools array and the model can search the web and cite its sources. It costs $10 per 1,000 search calls plus the search content tokens at the model's rates (checked 2026-11-24). In Chat Completions, web search is only available through dedicated search models such as gpt-5-search-api.

Is grounding with Google Search free in the Gemini API?

Partly. On Gemini 3 and newer models, the first 5,000 search queries each month are free, shared across those models. After that Google charges $14 per 1,000 search queries, and every query the model runs is billed, so one question can cost two or more queries. Gemini 2.5 models are billed per grounded prompt instead: $35 per 1,000 after 1,500 free a day.

How much does web search cost in the Claude API?

$10 per 1,000 searches, plus standard token costs, because the search results Claude reads count as input tokens. A search that fails with an error is not billed. Prices checked on Anthropic's documentation on 2026-11-24.

Can I limit web search to specific websites?

In OpenAI, yes: filters.allowed_domains or blocked_domains, up to 100 domains each. In Claude, yes: allowed_domains or blocked_domains, but not both in one request. In Gemini, the Developer API has no domain allow-list; Vertex AI accepts exclude_domains to block domains.

Can I use Google Search grounding with Claude or GPT?

No. Each provider's built-in search only grounds its own models. To give Claude, GPT, Gemini or a local model the same live results, call a search API yourself and pass the results into the prompt or return them from a tool call.

Why didn't the model search even though I enabled the tool?

Because with all three built-in tools the model decides when to search. Questions about stable facts are often answered without a search. Ask for current information explicitly, set tool_choice to "required" in OpenAI, or run the search in your own code before calling the model.

Sarah Choy
Written by
Sarah Choy
CEO, apipick

Sarah Choy is the CEO of apipick. She writes about building production-ready APIs for AI agents and LLM workflows.