AI Gateway は、対応プロバイダーのネイティブ Web 検索ツールをプロキシします。モデルは学習カットオフ以降の出来事についても答えられます。検索は上流プロバイダー側で実行されます。AI Gateway は、ログ、キャッシュ、レート制限、Guardrails などの標準機能をリクエストに適用します。
Web 検索の有効化方法はプロバイダーによって異なります。tools 配列へのツール追加か、リクエストボディのトップレベルフラグかのいずれかです。次の表で該当セクションを確認してください。
| プロバイダー | エンドポイント | 有効化 |
|---|---|---|
| Anthropic | POST /ai/v1/messages |
tools: [{ "type": "web_search_20250305", "name": "web_search", "max_uses": N }] |
| OpenAI | POST /ai/v1/responses |
tools: [{ "type": "web_search_preview" }] |
| xAI | POST /ai/v1/responses |
tools: [{ "type": "web_search" }] |
| Alibaba | POST /ai/v1/chat/completions |
トップレベルの "enable_search": true |
プロダクト自体が検索であるプロバイダー(Perplexity と Parallel)は、検索特化プロバイダー を参照してください。
Anthropic モデルは、ネイティブの web_search_20250305 ツール ↗ で Web 検索を公開します。POST /ai/v1/messages リクエストの tools 配列に追加します。
対応モデル — anthropic/claude-haiku-4.5、anthropic/claude-opus-4.5、anthropic/claude-opus-4.6、anthropic/claude-opus-4.7、anthropic/claude-opus-4.8、anthropic/claude-sonnet-4.5、anthropic/claude-sonnet-4.6。
# Run `wrangler whoami` to get your account ID to replace $CLOUDFLARE_ACCOUNT_ID,
# and `wrangler auth token` to get an auth token to replace $CLOUDFLARE_API_TOKEN.
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/messages" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "anthropic/claude-haiku-4.5",
"max_tokens": 4096,
"messages": [
{
"role": "user",
"content": "What were the top news stories about Cloudflare this week? Summarize in three bullets."
}
],
"tools": [
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3
}
]
}'Worker から AI バインディングで同等の呼び出しをする例です。
const resp = await env.AI.run(
"anthropic/claude-haiku-4.5",
{
max_tokens: 4096,
messages: [
{
role: "user",
content:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
},
],
tools: [{ type: "web_search_20250305", name: "web_search", max_uses: 3 }],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);const resp = await env.AI.run(
"anthropic/claude-haiku-4.5",
{
max_tokens: 4096,
messages: [
{
role: "user",
content:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
},
],
tools: [{ type: "web_search_20250305", name: "web_search", max_uses: 3 }],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);検索の呼び出しと結果は、レスポンス内の server_tool_use および web_search_tool_result コンテンツブロックとして現れます。設定可能なパラメーターには max_uses、allowed_domains、blocked_domains、user_location があります。一覧は Anthropic の Web 検索ツールのドキュメント ↗ を参照してください。
OpenAI モデルは、Responses API の web_search_preview ツール ↗ で Web 検索を公開します。POST /ai/v1/responses エンドポイントを使い、tools 配列にツールを追加します。
対応モデル — openai/gpt-4.1、openai/gpt-4.1-mini、openai/gpt-4o、openai/gpt-4o-mini、openai/gpt-5、openai/gpt-5-mini、openai/gpt-5-nano、openai/gpt-5.1、openai/gpt-5.4、openai/gpt-5.4-mini、openai/gpt-5.4-nano、openai/gpt-5.4-pro、openai/gpt-5.5、openai/gpt-5.5-pro、openai/o3、openai/o4-mini。
# Run `wrangler whoami` to get your account ID to replace $CLOUDFLARE_ACCOUNT_ID,
# and `wrangler auth token` to get an auth token to replace $CLOUDFLARE_API_TOKEN.
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/responses" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "openai/gpt-4o-mini",
"input": "What were the top news stories about Cloudflare this week? Summarize in three bullets.",
"max_output_tokens": 4096,
"tools": [
{ "type": "web_search_preview" }
]
}'Worker から AI バインディングで同等の呼び出しをする例です。
const resp = await env.AI.run(
"openai/gpt-4o-mini",
{
input:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
max_output_tokens: 4096,
tools: [{ type: "web_search_preview" }],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);const resp = await env.AI.run(
"openai/gpt-4o-mini",
{
input:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
max_output_tokens: 4096,
tools: [{ type: "web_search_preview" }],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);OpenAI の Web 検索は、Responses API エンドポイント(POST /ai/v1/responses)でのみ利用できます。/ai/v1/chat/completions エンドポイントは web_search_preview ツールを受け付けません。
Responses API では { "type": "web_search_preview" } と { "type": "web_search" } の両方を受け付けます。ここでの例は web_search_preview を使います。
xAI のマルチエージェント Grok モデルは、Responses API の web_search ツール ↗ で Web 検索を公開します。POST /ai/v1/responses リクエストの tools 配列に { "type": "web_search" } を追加します。
対応モデル — xai/grok-4.20-multi-agent-0309。
# Run `wrangler whoami` to get your account ID to replace $CLOUDFLARE_ACCOUNT_ID,
# and `wrangler auth token` to get an auth token to replace $CLOUDFLARE_API_TOKEN.
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/responses" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-4.20-multi-agent-0309",
"input": "What were the top news stories about Cloudflare this week? Summarize in three bullets.",
"max_turns": 4,
"tools": [
{ "type": "web_search" }
]
}'Worker から AI バインディングで同等の呼び出しをする例です。
const resp = await env.AI.run(
"xai/grok-4.20-multi-agent-0309",
{
input:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
max_turns: 4,
tools: [{ type: "web_search" }],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);const resp = await env.AI.run(
"xai/grok-4.20-multi-agent-0309",
{
input:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
max_turns: 4,
tools: [{ type: "web_search" }],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);AI Gateway 経由で Web 検索を受け付ける xAI モデルは xai/grok-4.20-multi-agent-0309 だけです。ほかの Grok モデルは Web 検索に対応していないモデル を参照してください。
Alibaba DashScope の Qwen モデルは、chat completions リクエストのトップレベル enable_search ↗ フラグで Web 検索を有効にします。Anthropic、OpenAI、xAI と違い、tools エントリはありません。フラグだけで Web 検索が有効になります。
対応モデル — alibaba/qwen3-max、alibaba/qwen3.5-397b-a17b。
# Run `wrangler whoami` to get your account ID to replace $CLOUDFLARE_ACCOUNT_ID,
# and `wrangler auth token` to get an auth token to replace $CLOUDFLARE_API_TOKEN.
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "alibaba/qwen3-max",
"enable_search": true,
"max_tokens": 4096,
"messages": [
{
"role": "user",
"content": "What were the top news stories about Cloudflare this week? Summarize in three bullets."
}
]
}'Worker から AI バインディングで同等の呼び出しをする例です。
const resp = await env.AI.run(
"alibaba/qwen3-max",
{
enable_search: true,
max_tokens: 4096,
messages: [
{
role: "user",
content:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
},
],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);const resp = await env.AI.run(
"alibaba/qwen3-max",
{
enable_search: true,
max_tokens: 4096,
messages: [
{
role: "user",
content:
"What were the top news stories about Cloudflare this week? Summarize in three bullets.",
},
],
},
{
gateway: {
id: "default", // or use a specific gateway name
},
},
);DashScope は、検索で得たコンテキストを別の tool-call レスポンスブロックとしては返しません。取得したコンテキストを追加の入力トークンとしてプロンプトに折り込みます。検索グラウンディングに成功したレスポンスでは、prompt_tokens が大きく増える想定です。
一部のプロバイダーでは、本体 API がチャットエンドポイント+ Web 検索ツールではなく、検索エンドポイントです。AI Gateway は、既存のプロバイダープロキシエンドポイント(gateway.ai.cloudflare.com)経由で公開します。
AI Gateway は、プロバイダー非依存の Web 検索抽象化は提供しません。次のパターンでプロバイダープロキシを直接呼び出します。
任意の Perplexity Sonar モデル ↗ を、Perplexity プロバイダープロキシ 経由で呼び出します。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/perplexity-ai/chat/completions \
--header "Authorization: Bearer $PERPLEXITY_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "sonar",
"messages": [
{ "role": "user", "content": "What were the top news stories about Cloudflare this week?" }
]
}'Parallel の Search API を、Parallel プロバイダープロキシ 経由で呼び出します。リクエストスキーマの全体は、Parallel の Search API ドキュメント ↗ を参照してください。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/parallel/v1beta/search \
--header "x-api-key: $PARALLEL_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"objective": "Top news stories about Cloudflare this week.",
"processor": "base",
"max_results": 10
}'次のモデルは、AI Gateway 経由の Web 検索を受け付けません。
- Google Gemini — Vertex の OpenAI 互換面が、統一の
web_searchツールを Gemini ネイティブのgoogleSearchツールへ変換しないため、利用できません。Gemini のグラウンディングを使うには、ネイティブのgoogle_searchツールを プロバイダー固有の Vertex エンドポイント へ渡します。 - Grok の chat-completions モデル —
xai/grok-4.20-0309-non-reasoning、xai/grok-4.20-0309-reasoning、xai/grok-4.3は chat-completions エンドポイントを使い、web_searchツールを受け付けません。Grok の Web 検索は xAI の Web 検索 を参照してください。 - DeepSeek
deepseek-v4-flash、deepseek-v4-pro— これらのモデルは function ツールのみを受け付けます。 - MiniMax
m2.7、m3— これらのモデルは{ "type": "function" }ツールのみを受け付けます。 - OpenAI
gpt-4.1-nano、o1-pro、o3-mini— 上流がこれらのモデルでweb_search_previewに対してinvalid_request_errorを返します。 - OpenAI
gpt-4o-search-preview、gpt-4o-mini-search-preview— これらのプレビューモデルは上流で非推奨です。
Web 検索リクエストは、上流プロバイダーの Web 検索料金で課金され、モデル呼び出しのほかの部分と同様に Unified Billing を通ります。AI Gateway は、Web 検索の別料金は請求しません。
Web 検索のツール呼び出しとその結果は、リクエストとレスポンスのほかの部分とあわせて、AI Gateway の ログ で確認できます。
- REST API — これらの例が対象とする 4 つのエンドポイント
- Workers Bindings —
env.AI.runのリファレンス - Anthropic プロバイダー
- OpenAI プロバイダー
- Grok(xAI)プロバイダー
- Perplexity プロバイダー
- Parallel プロバイダー
- Unified Billing