Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

Web Search

最終更新 Markdown で表示Agent セットアップ

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 検索

Anthropic モデルは、ネイティブの web_search_20250305 ツール で Web 検索を公開します。POST /ai/v1/messages リクエストの tools 配列に追加します。

対応モデル — anthropic/claude-haiku-4.5anthropic/claude-opus-4.5anthropic/claude-opus-4.6anthropic/claude-opus-4.7anthropic/claude-opus-4.8anthropic/claude-sonnet-4.5anthropic/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_usesallowed_domainsblocked_domainsuser_location があります。一覧は Anthropic の Web 検索ツールのドキュメント を参照してください。

OpenAI の Web 検索

OpenAI モデルは、Responses API の web_search_preview ツール で Web 検索を公開します。POST /ai/v1/responses エンドポイントを使い、tools 配列にツールを追加します。

対応モデル — openai/gpt-4.1openai/gpt-4.1-miniopenai/gpt-4oopenai/gpt-4o-miniopenai/gpt-5openai/gpt-5-miniopenai/gpt-5-nanoopenai/gpt-5.1openai/gpt-5.4openai/gpt-5.4-miniopenai/gpt-5.4-nanoopenai/gpt-5.4-proopenai/gpt-5.5openai/gpt-5.5-proopenai/o3openai/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 の Web 検索

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(Qwen)の Web 検索

Alibaba DashScope の Qwen モデルは、chat completions リクエストのトップレベル enable_search フラグで Web 検索を有効にします。Anthropic、OpenAI、xAI と違い、tools エントリはありません。フラグだけで Web 検索が有効になります。

対応モデル — alibaba/qwen3-maxalibaba/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

任意の 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

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
  }'

Web 検索に対応していないモデル

次のモデルは、AI Gateway 経由の Web 検索を受け付けません。

  • Google Gemini — Vertex の OpenAI 互換面が、統一の web_search ツールを Gemini ネイティブの googleSearch ツールへ変換しないため、利用できません。Gemini のグラウンディングを使うには、ネイティブの google_search ツールを プロバイダー固有の Vertex エンドポイント へ渡します。
  • Grok の chat-completions モデルxai/grok-4.20-0309-non-reasoningxai/grok-4.20-0309-reasoningxai/grok-4.3 は chat-completions エンドポイントを使い、web_search ツールを受け付けません。Grok の Web 検索は xAI の Web 検索 を参照してください。
  • DeepSeek deepseek-v4-flashdeepseek-v4-pro — これらのモデルは function ツールのみを受け付けます。
  • MiniMax m2.7m3 — これらのモデルは { "type": "function" } ツールのみを受け付けます。
  • OpenAI gpt-4.1-nanoo1-proo3-mini — 上流がこれらのモデルで web_search_preview に対して invalid_request_error を返します。
  • OpenAI gpt-4o-search-previewgpt-4o-mini-search-preview — これらのプレビューモデルは上流で非推奨です。

料金とログ

Web 検索リクエストは、上流プロバイダーの Web 検索料金で課金され、モデル呼び出しのほかの部分と同様に Unified Billing を通ります。AI Gateway は、Web 検索の別料金は請求しません。

Web 検索のツール呼び出しとその結果は、リクエストとレスポンスのほかの部分とあわせて、AI Gateway の ログ で確認できます。

関連リソース

役に立ちましたか?