---
title: "Web Search"
description: "从全网搜索网页信息和链接，返回适合 AI 使用的准确结果与完整摘要。"
slug: "/api-reference/web-search"
version: "1.0.0"
source: "https://api.bocha.cn/v1/web-search"
---

# Web Search

## 接口信息

- **请求方式**：`POST`
- **接口路径**：`/v1/web-search`
- **完整地址**：`https://api.bocha.cn/v1/web-search`

从全网搜索网页信息和链接，返回适合 AI 使用的准确结果与完整摘要。

## OpenAPI 定义

~~~yaml
/v1/web-search:
    post:
      # summary 用于在线调试的接口名称和示例标题，与页面产品名保持一致。
      summary: Web Search
      operationId: webSearch
      # 首屏只保留接口用途；Mintlify 会根据下方真实的 path 和 docs.json 的 api.url: full，
      # 自动紧接着渲染“POST + 完整地址”的调用卡，避免手写地址与接口定义发生偏差。
      description: 从全网搜索网页信息和链接，返回适合 AI 使用的准确结果与完整摘要。
      tags:
        - 搜索
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WebSearchRequest"
            examples:
              basic:
                summary: 基础网页搜索
                value:
                  query: 阿里巴巴2024年的ESG报告
                  freshness: noLimit
                  summary: true
                  count: 10
      responses:
        "200":
          description: 搜索成功
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WebSearchResponse"
              example:
                code: 200
                log_id: d71841ad20095f61
                msg: null
                data:
                  _type: SearchResponse
                  queryContext:
                    originalQuery: 阿里巴巴2024年的ESG报告
                  webPages:
                    webSearchUrl: https://bochaai.com/search?q=阿里巴巴2024年的ESG报告
                    totalEstimatedMatches: 8912791
                    someResultsRemoved: false
                    value:
                      - name: 阿里巴巴发布2024年ESG报告
                        url: https://www.alibabagroup.com
                        displayUrl: https://www.alibabagroup.com
                        snippet: 阿里巴巴集团发布《2024财年环境、社会和治理（ESG）报告》。
                        summary: 报告介绍了阿里巴巴在环境、社会和治理方面的进展。
                        siteName: www.alibabagroup.com
                        datePublished: "2024-07-22T00:00:00+08:00"
                  images:
                    value: []
                  videos: null
        "400":
          description: 请求参数错误，例如缺少 `query`
        "401":
          description: 鉴权失败，API Key 缺失或无效
        "403":
          description: 账户余额不足
        "429":
          description: 请求频率达到限制
        "500":
          description: 搜索服务内部错误

    WebSearchRequest:
      type: object
      required:
        - query
      properties:
        query:
          type: string
          description: 用户的搜索词。
        freshness:
          type: string
          default: noLimit
          description: |
            搜索指定时间范围内的网页。可填 `noLimit`、`oneDay`、`oneWeek`、`oneMonth`、`oneYear`、
            单个日期（`YYYY-MM-DD`）或日期范围（`YYYY-MM-DD..YYYY-MM-DD`）。
          # 示例必须加引号：不加引号时 YAML 会把 2025-04-06 解析成日期类型，
          # 渲染到 API 参考页会变成 ISO 时间 2025-04-06T00:00:00.000Z，与接口实际支持的格式不符。
          examples:
            - "noLimit"
            - "2025-04-06"
            - "2025-01-01..2025-04-06"
        summary:
          type: boolean
          default: false
          description: 是否显示网页内容的文本摘要。设为 `true` 时返回结果中包含 `summary` 字段。
        include:
          type: string
          description: |
            限定搜索的网站范围。多个根域名或子域名以 `|` 或 `,` 分隔，最多 100 个；
            例如：`qq.com|m.163.com`。
        exclude:
          type: string
          description: |
            排除搜索的网站范围。多个根域名或子域名以 `|` 或 `,` 分隔，最多 100 个；
            例如：`qq.com|m.163.com`。
        count:
          type: integer
          minimum: 1
          maximum: 50
          default: 10
          description: 返回结果数量。实际返回数量可能小于指定值，单次最多返回 50 条。

    WebSearchResponse:
      type: object
      description: 网页搜索的统一响应结构。
      properties:
        code:
          type: integer
          description: 业务状态码，`200` 表示成功。
        log_id:
          type: string
          description: 本次请求的追踪 ID；排查问题时请提供该值。
        msg:
          type: [string, "null"]
          description: 响应消息；成功响应中为 `null`，错误信息见非成功响应的 `message` 字段。
        data:
          $ref: "#/components/schemas/WebSearchData"

    WebSearchData:
      type: object
      properties:
        _type:
          type: string
          description: 搜索类型，固定为 `SearchResponse`。
        queryContext:
          $ref: "#/components/schemas/WebSearchQueryContext"
        webPages:
          $ref: "#/components/schemas/WebSearchWebPages"
        images:
          $ref: "#/components/schemas/WebSearchImages"
        videos:
          type: "null"
          description: 当前 Web Search API 暂不返回视频结果，固定为 `null`。

    WebSearchQueryContext:
      type: object
      properties:
        originalQuery:
          type: string
          description: 原始搜索关键词。鉴权或内容安全校验未通过时可能为 `query not safe`。

    WebSearchWebPages:
      type: object
      properties:
        webSearchUrl:
          type: string
          format: uri
          description: 网页搜索结果页地址。
        totalEstimatedMatches:
          type: integer
          description: 估算的网页匹配总数。
        value:
          type: array
          description: 网页搜索结果列表。
          items:
            $ref: "#/components/schemas/WebPageValue"
        someResultsRemoved:
          type: boolean
          description: 搜索结果中是否有内容被安全过滤。

    WebSearchImages:
      type: object
      properties:
        id:
          type: string
          description: 图片搜索结果 ID。
        readLink:
          type: string
          format: uri
          description: 图片搜索结果读取链接。
        webSearchUrl:
          type: string
          format: uri
          description: 图片搜索结果页地址。
        isFamilyFriendly:
          type: boolean
          description: 是否为家庭友好内容。
        value:
          type: array
          description: 图片搜索结果列表。
          items:
            $ref: "#/components/schemas/ImageValue"

    WebPageValue:
      type: object
      properties:
        id:
          type: string
          description: 网页结果的排序 ID。
        name:
          type: string
          description: 网页标题。
        url:
          type: string
          format: uri
          description: 网页原始地址。
        displayUrl:
          type: string
          description: 用于展示的网页地址（`url` 解码后的形式）。
        snippet:
          type: string
          description: 网页内容的简短描述。
        summary:
          type: string
          description: '网页内容的文本摘要；仅在请求 `summary: true` 时返回。'
        siteName:
          type: string
          description: 网站名称。
        siteIcon:
          type: string
          format: uri
          description: 网站图标地址。
        datePublished:
          type: string
          format: date-time
          description: '网页发布时间，例如 `2025-02-23T08:18:30+08:00`（UTC+8）。'
        dateLastCrawled:
          type: string
          format: date-time
          description: 兼容字段，实际表示 UTC+8 的发布时间；请优先使用 `datePublished`。
        cachedPageUrl:
          type: string
          format: uri
          description: 网页缓存页地址。
        language:
          type: string
          description: 网页语言。
        isFamilyFriendly:
          type: boolean
          description: 是否为家庭友好页面。
        isNavigational:
          type: boolean
          description: 是否为导航性页面。

    ImageValue:
      type: object
      properties:
        webSearchUrl:
          type: string
          format: uri
          description: 图片搜索结果页地址。
        name:
          type: string
          description: 图片名称。
        thumbnailUrl:
          type: string
          format: uri
          description: 图片缩略图地址。
        datePublished:
          type: string
          format: date-time
          description: 图片发布日期。
        contentUrl:
          type: string
          format: uri
          description: 原始图片地址。
        hostPageUrl:
          type: string
          format: uri
          description: 图片所在网页地址。
        contentSize:
          type: string
          description: 图片文件大小。
        encodingFormat:
          type: string
          description: 图片编码格式。
        hostPageDisplayUrl:
          type: string
          description: 图片所在网页的展示地址。
        width:
          type: integer
          description: 图片宽度（像素）。
        height:
          type: integer
          description: 图片高度（像素）。
        thumbnail:
          $ref: "#/components/schemas/Thumbnail"

    Thumbnail:
      type: object
      properties:
        height:
          type: integer
          description: 缩略图高度（像素）。
        width:
          type: integer
          description: 缩略图宽度（像素）。

~~~
