コンテンツにスキップ

GPT ウェブ検索 (Web Search)

モデルが応答を生成する前に、ウェブを検索して最新情報を取得できるようにします。これにより、モデルはインターネット上の最新情報にアクセスし、ソースの引用付きで回答を提供することができます。

現在、当プラットフォーム(OpenAI ネイティブインターフェースと互換)で Web Search ツールを使用する主な方法は、Responses APIChat Completions API の 2 つです。

基本的な呼び出し

1. Responses API を使用する

Responses API では、tools 配列内に web_search ツールを設定できます。他のツールと同様に、モデルは入力プロンプトの内容に基づいてウェブ検索を行うかどうかを独自に決定します。

当サイトの例 (新しい API プラットフォーム)

curl "https://api-cs-al.naci-tech.com/v1/responses" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $API_KEY" \
    -d '{
        "model": "gpt-5",
        "tools": [{"type": "web_search"}],
        "input": "今日のポジティブなニュースは何ですか?"
    }'

OpenAI 公式の例

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

2. Chat Completions API を使用する

Chat Completions を使用する場合、モデルは常にクエリに応答する前にウェブから情報を検索します。この機能を使用するには、特定の検索モデル(gpt-4o-search-preview など)を指定し、web_search_options パラメータを使用して検索を有効にする必要があります。

当サイトの例 (新しい API プラットフォーム)

curl "https://api-cs-al.naci-tech.com/v1/chat/completions" \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-type: application/json" \
    -d '{
        "model": "gpt-4o-search-preview",
        "web_search_options": {},
        "messages": [{
            "role": "user",
            "content": "今日のポジティブなニュースは何ですか?"
        }]
    }'

OpenAI 公式の例

curl "https://api.openai.com/v1/chat/completions" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-type: application/json" \
    -d '{
        "model": "gpt-4o-search-preview",
        "web_search_options": {},
        "messages": [{
            "role": "user",
            "content": "What was a positive news story from today?"
        }]
    }'

出力と引用 (Output and citations)

デフォルトでは、モデルの応答には、ウェブ検索結果で見つかった URL のインライン引用(inline citations)が含まれます。

Responses API の出力

Responses の出力は 2 つの部分で構成されます: 1. 検索呼び出しの ID と実行されたアクション(searchopen_page など)を含む web_search_call 出力項目。 2. テキスト結果(message.content[0].text)と引用された URL の注釈(message.content[0].annotations)を含む message 出力項目。

url_citation 注釈オブジェクトには、引用元の URL、タイトル、および位置が含まれます。

[
  {
    "type": "web_search_call",
    "id": "ws_67c9fa05...",
    "status": "completed"
  },
  {
    "id": "msg_67c9fa07...",
    "type": "message",
    "status": "completed",
    "role": "assistant",
    "content": [
      {
        "type": "output_text",
        "text": "2025年3月6日、複数のニュース報道がありました...",
        "annotations": [
          {
            "type": "url_citation",
            "start_index": 2606,
            "end_index": 2758,
            "url": "https://...",
            "title": "Title..."
          }
        ]
      }
    ]
  }
]

Chat Completions API の出力

返される choices 配列には以下が含まれます: * message.content:モデルのテキスト結果とインライン引用が含まれます。 * message.annotations:引用された URL のリストが含まれ、同様に url_citation を使用して引用の詳細とコンテンツ内の start_index および end_index を提供します。

[
  {
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "モデルの返信内容がここにあります...",
      "refusal": null,
      "annotations": [
        {
          "type": "url_citation",
          "url_citation": {
            "end_index": 985,
            "start_index": 764,
            "title": "Page title...",
            "url": "https://..."
          }
        }
      ]
    },
    "finish_reason": "stop"
  }
]

ドメインのフィルタリング (Domain filtering)

ドメインフィルタリングを使用すると、検索結果を特定のドメインセットに制限できます。filters.allowed_domains パラメータを使用して、最大 100 個の URL の許可リストを設定できます。

注意:ドメインフィルタリングは現在、Responses APIweb_search ツールでのみ利用可能です。

当サイトの例 (新しい API プラットフォーム)

curl "https://api-cs-al.naci-tech.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
  "model": "gpt-5",
  "tools": [
    {
      "type": "web_search",
      "filters": {
        "allowed_domains": [
          "pubmed.ncbi.nlm.nih.gov",
          "www.who.int",
          "www.cdc.gov"
        ]
      }
    }
  ],
  "input": "糖尿病治療におけるセマグルチドの使用に関する研究を検索してください。"
}'

OpenAI 公式の例

curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
  "model": "gpt-5",
  "tools": [
    {
      "type": "web_search",
      "filters": {
        "allowed_domains": [
          "pubmed.ncbi.nlm.nih.gov",
          "www.who.int",
          "www.cdc.gov"
        ]
      }
    }
  ],
  "input": "Please perform a web search on how semaglutide is used in the treatment of diabetes."
}'

ソース (Sources)

ウェブ検索中に取得されたすべての URL を表示するには、include: ["web_search_call.action.sources"] を使用できます。最も関連性の高い参照のみを表示するインライン引用(citations)とは異なり、sources はモデルが応答を作成する際に参照した URL の完全なリストを返します。

当サイトの例 (新しい API プラットフォーム)

curl "https://api-cs-al.naci-tech.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
  "model": "gpt-5",
  "tools": [{"type": "web_search"}],
  "tool_choice": "auto",
  "include": ["web_search_call.action.sources"],
  "input": "量子コンピューティングの最新の進展について説明してください。"
}'

OpenAI 公式の例

curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
  "model": "gpt-5",
  "reasoning": { "effort": "low" },
  "tools": [{"type": "web_search"}],
  "tool_choice": "auto",
  "include": ["web_search_call.action.sources"],
  "input": "Please perform a web search on how semaglutide is used in the treatment of diabetes."
}'

ユーザーの場所 (User location)

地理的な位置に基づいて検索結果を最適化するために、user_location パラメータを使用して、ユーザーの概算の場所(国 country、都市 city、地域 region、またはタイムゾーン timezone を含む)を指定できます。

Responses API での使用

当サイトの例 (新しい API プラットフォーム)

curl "https://api-cs-al.naci-tech.com/v1/responses" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $API_KEY" \
    -d '{
        "model": "o4-mini",
        "tools": [{
            "type": "web_search",
            "user_location": {
                "type": "approximate",
                "country": "CN",
                "city": "Shanghai",
                "region": "Shanghai"
            }
        }],
        "input": "私の近くでおすすめの観光スポットは何ですか?"
    }'

OpenAI 公式の例

curl "https://api.openai.com/v1/responses" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
        "model": "o4-mini",
        "tools": [{
            "type": "web_search",
            "user_location": {
                "type": "approximate",
                "country": "GB",
                "city": "London",
                "region": "London"
            }
        }],
        "input": "What are the best restaurants near me?"
    }'

Chat Completions API での使用

Chat モデルでは、user_locationweb_search_options 内に含めることができます。

当サイトの例 (新しい API プラットフォーム)

curl "https://api-cs-al.naci-tech.com/v1/chat/completions" \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-type: application/json" \
    -d '{
        "model": "gpt-4o-search-preview",
        "web_search_options": {
            "user_location": {
                "type": "approximate",
                "approximate": {
                    "country": "CN",
                    "city": "Beijing",
                    "region": "Beijing"
                }
            }
        },
        "messages": [{
            "role": "user",
            "content": "私の近くで最高のレストランはどこですか?"
        }]
    }'

OpenAI 公式の例

curl "https://api.openai.com/v1/chat/completions" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-type: application/json" \
    -d '{
        "model": "gpt-4o-search-preview",
        "web_search_options": {
            "user_location": {
                "type": "approximate",
                "approximate": {
                    "country": "GB",
                    "city": "London",
                    "region": "London"
                }
            }
        },
        "messages": [{
            "role": "user",
            "content": "What are the best restaurants near me?"
        }]
    }'

ライブインターネットアクセスの制御 (Live internet access)

Responses API の web_search ツールで external_web_access: false を設定することにより、ツールがライブコンテンツを取得するか、キャッシュされた(インデックス付きの)結果のみを使用するかを制御できます。デフォルトは true です。

注意:プレビューバージョン(web_search_preview)はこのパラメータを無視し、常に true として動作します。

当サイトの例 (新しい API プラットフォーム)

curl "https://api-cs-al.naci-tech.com/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5",
    "tools": [
      { "type": "web_search", "external_web_access": false }
    ],
    "tool_choice": "auto",
    "input": "今日のパリの日の出時間を調べて、ソースを引用してください。"
  }'

OpenAI 公式の例

curl "https://api.openai.com/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-5",
    "tools": [
      { "type": "web_search", "external_web_access": false }
    ],
    "tool_choice": "auto",
    "input": "Find the sunrise time in Paris today and cite the source."
  }'

API の互換性 (API compatibility)

Web Search は現在以下をサポートしています: * Responses API:一般バージョン web_search ツール、または初期バージョン web_search_preview ツールを使用できます。 * Chat Completions API:Web Search を有効にするには専用の検索モデルを使用する必要があります。現在サポートされているモデルは次のとおりです: * gpt-5-search-api * gpt-4o-search-preview * gpt-4o-mini-search-preview

制限事項 (Limitations)

  • Web Search ツールは現在、minimal reasoning 設定を持つ gpt-5 モデル、および gpt-4.1-nano などのモデルを**サポートしていません**。
  • Responses API でツールとして使用する場合のレート制限は、選択したモデルの階層のレート制限と同じです。
  • Web Search 機能は 128,000 コンテキストウィンドウの制限(gpt-4.1 および gpt-4.1-mini シリーズを含む)を受けます。

使用上の注意 (Usage notes)

API の可用性 レート制限 (Rate limits)
Responses
Chat Completions
基盤となるツールとして呼び出される**モデル**と同じレート制限を共有します。