# see2ai_web_search_serper_v1

> 实时网络搜索；适合时效性问题、最新事件、实时数据、最新政策法规、最近发布的产品 / 报告等需要新鲜信息的查询。

## 📖 接入指引

**Endpoint**: `POST /api/v1/actions/see2ai_web_search_serper_v1`

**认证方式**: Bearer Token (租户 API Key)

### Endpoints

| Method | Path | Purpose |
| --- | --- | --- |
| `POST` | `/api/v1/actions/see2ai_web_search_serper_v1` | Submit the standard action request. |

> **⚠️ 重要提示**
> 
> 本 API 是 SEE2AI 平台标准化封装后的接口，**参数格式与任何上游 API 不同**。
> 请直接使用下方 Schema 中定义的参数，无需参考其他文档。
> 
> *例如：*
> *- 文本模型参数可能是 `query` 而不是 `messages` 数组*
> *- 视频模型参数可能是 `brief` (创意简报) 而不是复杂的配置项*

## 📥 输入参数 (Input Schema)

```json
{
  "description": "H13 + H14 + H16: LLM-facing schema 只暴露 q + num；gl/hl hardcode 在 service 层。",
  "properties": {
    "q": {
      "description": "搜索查询字符串（最长 256 字符）",
      "maxLength": 256,
      "minLength": 1,
      "title": "Q",
      "type": "string"
    },
    "num": {
      "default": 10,
      "description": "返回结果数（1-20，默认 10）",
      "maximum": 20,
      "minimum": 1,
      "title": "Num",
      "type": "integer"
    }
  },
  "required": [
    "q"
  ],
  "title": "WebSearchInput",
  "type": "object"
}
```

### 参数说明

| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|--------|------|------|--------|------|
| `q` | string | ✅ 是 | `-` | 搜索查询字符串（最长 256 字符） |
| `num` | integer | ❌ 否 | `10` | 返回结果数（1-20，默认 10） |

## 📤 输出结果 (Output Schema)

```json
{
  "$defs": {
    "SearchResultItem": {
      "description": "H9 Raw 精简后的 organic 结果条目（不含 sitelinks / attributes 等深嵌字段）。",
      "properties": {
        "title": {
          "title": "Title",
          "type": "string"
        },
        "link": {
          "title": "Link",
          "type": "string"
        },
        "snippet": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Snippet"
        },
        "position": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Position"
        },
        "date": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Date"
        }
      },
      "required": [
        "title",
        "link"
      ],
      "title": "SearchResultItem",
      "type": "object"
    }
  },
  "description": "H9 锁定的 3 个 key + query 回显 + provider_config_id 给 ops audit。",
  "properties": {
    "input_tokens": {
      "default": 0,
      "description": "输入消耗的词元数量",
      "title": "Input Tokens",
      "type": "integer"
    },
    "output_tokens": {
      "default": 0,
      "description": "输出消耗的词元数量",
      "title": "Output Tokens",
      "type": "integer"
    },
    "total_tokens": {
      "default": 0,
      "description": "总消耗的词元数量",
      "title": "Total Tokens",
      "type": "integer"
    },
    "model": {
      "default": "",
      "description": "实际使用的 SEE2AI 化身模型名称（由各 action 显式填写）",
      "title": "Model",
      "type": "string"
    },
    "source": {
      "default": "see2ai",
      "description": "服务来源（统一 `see2ai`；真实路由仅平台内部可见）",
      "title": "Source",
      "type": "string"
    },
    "cost_points": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "预先计算的扣费词元（如果插件内部已经计算好费用，则直接使用此值，忽略基于词元的计算）",
      "title": "Cost Points"
    },
    "query": {
      "default": "",
      "title": "Query",
      "type": "string"
    },
    "results": {
      "items": {
        "$ref": "#/$defs/SearchResultItem"
      },
      "title": "Results",
      "type": "array"
    },
    "knowledge_graph": {
      "anyOf": [
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Knowledge Graph"
    },
    "related_searches": {
      "anyOf": [
        {
          "items": {
            "additionalProperties": {
              "type": "string"
            },
            "type": "object"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Related Searches"
    },
    "provider_config_id": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Provider Config Id"
    }
  },
  "title": "WebSearchOutput",
  "type": "object"
}
```

### 输出字段说明

| 字段名 | 类型 | 说明 |
|--------|------|------|
| `input_tokens` | integer | 输入消耗的词元数量 |
| `output_tokens` | integer | 输出消耗的词元数量 |
| `total_tokens` | integer | 总消耗的词元数量 |
| `model` | string | 实际使用的 SEE2AI 化身模型名称（由各 action 显式填写） |
| `source` | string | 服务来源（统一 `see2ai`；真实路由仅平台内部可见） |
| `cost_points` | integer / null | 预先计算的扣费词元（如果插件内部已经计算好费用，则直接使用此值，忽略基于词元的计算） |
| `query` | string |  |
| `results` | array |  |
| `knowledge_graph` | object / null |  |
| `related_searches` | array / null |  |
| `provider_config_id` | integer / null |  |

## 💡 调用示例

### cURL 示例

```bash
curl -X POST "https://see2ai.com/api/v1/actions/see2ai_web_search_serper_v1" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer sk-your-tenant-api-key" \
     -d '{
  "q": "sample",
  "num": 10
}'
```

### Python 示例

```python
import requests

API_KEY = "sk-your-tenant-api-key"
ENDPOINT = "https://see2ai.com/api/v1/actions/see2ai_web_search_serper_v1"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {API_KEY}"
}

payload = {
  "q": "sample",
  "num": 10
}

response = requests.post(ENDPOINT, json=payload, headers=headers)
result = response.json()

print(f"结果：{result}")
```

## 💰 计费说明

> 每次成功调用按管理后台配置的 per_query_cost_points 词元扣费（fallback 1000 词元 ≈ 0.02 元），失败不计费。

**注意**: 所有费用都以词元为单位，系统会自动从租户余额中扣除。

## ⚠️ 常见错误码

| HTTP 状态码 | 错误原因 | 解决方案 |
| --- | --- | --- |
| `402` | 租户余额不足 | 请稍后重试 |
| `422` | 查询字符串无效（空 / 超 256 字符 / num 超界 1-20） | 检查请求参数是否符合 Schema 要求 |
| `503` | 搜索服务暂不可用（凭证未配置 / 上游超时 / 上游错误） | 请稍后重试 |

## 📞 技术支持

- **文档问题**: 查看 [SEE2AI 官方文档](https://see2ai.com/docs)
- **API 状态**: 访问 [服务状态页面](https://see2ai.com/status)
- **问题反馈**: 联系技术支持团队

---

**API 版本**: see2ai_web_search_serper_v1
**最后更新**: 2026-03-23
