> ## Documentation Index
> Fetch the complete documentation index at: https://docs.geekai.co/llms.txt
> Use this file to discover all available pages before exploring further.

# 网页搜索

你可以通过 OpenAI 内置的联网工具 `web_search` 实现联网查询生成响应的功能，以下是联网响应的请求示例：

<CodeGroup>
  ```bash curl theme={null}
  curl --location --request POST 'https://geekai.co/api/v1/responses' \
  --header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "model": "gpt-5-mini",
      "input": "2025年票房最高的电影?",
      "tools": [
          {
              "type": "web_search",
              "search_context_size": "low"
          }
      ]
  }'
  ```

  ```bash python theme={null}
  # 先安装 OpenAI SDK: `pip3 install openai`
  from openai import OpenAI
  client = OpenAI(api_key="$GEEKAI_API_KEY", base_url="https://geekai.co/api/v1")
  response = client.responses.create(
      model="gpt-5-mini",
      input="2025年票房最高的电影?",
      tools=[
          {
              "type": "web_search",
              "search_context_size": "low"
          }
      ]
  )
  print(response)
  ```

  ```bash javascript theme={null}
  // 先安装 OpenAI SDK: `npm install openai`
  import OpenAI from "openai";
  const openai = new OpenAI({
      baseURL: 'https://geekai.co/api/v1',
      apiKey: '$GEEKAI_API_KEY'
  });
  async function main() {
      const response = await openai.responses.create({
          model: "gpt-5-mini",
          input: "2025年票房最高的电影?",
          tools: [
              {
                  type: "web_search",
                  search_context_size: "low"
              }
          ]
      });
      console.log(response);
  }
  main();
  ```

  ```bash go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	requestBody := map[string]any{
  		"model": "gpt-5-mini",
  		"input": "2025年票房最高的电影?",
  		"tools": []any{
  			map[string]any{
  				"type":               "web_search",
  				"search_context_size": "low",
  			},
  		},
  	}

  	jsonData, err := json.Marshal(requestBody)
  	if err != nil {
  		panic(err)
  	}

  	client := &http.Client{}
  	req, err := http.NewRequest("POST", "https://geekai.co/api/v1/responses", bytes.NewBuffer(jsonData))
  	if err != nil {
  		panic(err)
  	}

  	req.Header.Set("Authorization", "Bearer $GEEKAI_API_KEY")
  	req.Header.Set("Content-Type", "application/json")

  	resp, err := client.Do(req)
  	if err != nil {
  		panic(err)
  	}
  	defer resp.Body.Close()

  	body, err := io.ReadAll(resp.Body)
  	if err != nil {
  		panic(err)
  	}

  	fmt.Println(string(body))
  }
  ```
</CodeGroup>

`search_context_size` 参数可以设置为 `low`, `medium`, `high` 来控制搜索上下文的大小，不同搜索上下文参数对应的搜索收费倍率不一样。

联网搜索工具支持以下模型：

* `gpt-5`（推理级别为 `minimal` 时不支持联网搜索）
* `gpt-5-mini`
* `gpt-4.1`
* `gpt-4.1-mini`
* `gpt-4o`
* `gpt-4o-mini`
* `o3`
* `o4-mini`
* `o3-pro`
* `o3-deep-research`
* `o4-mini-deep-research`
