身份认证
所有API请求都需要在请求头中包含有效的API Key。获取API Key请前往用户中心。
认证方式
支持两种认证方式:
# 方式1:X-API-Key 头 curl -H "X-API-Key: sk-your-api-key-here" \ https://www.sozeer.com/api/search?q=example # 方式2:Authorization Bearer 头 curl -H "Authorization: Bearer sk-your-api-key-here" \ https://www.sozeer.com/api/search?q=example
搜索引擎API
提供强大的网页搜索功能,支持多种参数配置。
GET
POST
/api/search
请求参数
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
q / query | string | 是 | 搜索关键词,最多200字符 |
page | integer | 否 | 页码,默认1,范围1-100 |
page_size | integer | 否 | 每页结果数,默认10,范围1-50 |
safe | string | 否 | 安全搜索级别,默认moderate |
lang | string | 否 | 语言代码,默认zh-CN |
响应示例
{ "success": true, "message": "搜索完成", "timestamp": 1640995200, "data": { "query": "人工智能", "page": 1, "page_size": 10, "total_results": 1520000, "search_time": 0.42, "results": [ { "title": "人工智能 - 维基百科", "link": "https://zh.wikipedia.org/wiki/人工智能", "display_link": "zh.wikipedia.org", "snippet": "人工智能(Artificial Intelligence,缩写为AI)亦称机器智能...", "position": 1 } ], "pagination": { "current_page": 1, "total_pages": 152000, "has_next_page": true, "has_prev_page": false, "next_page": 2, "prev_page": null } } }
AI模型API
提供多种AI模型的对话和图像生成功能,兼容OpenAI API格式。
对话补全 (Chat Completions)
POST
/api/chat
请求参数
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
model | string | 是 | 模型ID,见模型列表API |
messages | array | 是 | 对话消息列表 |
temperature | float | 否 | 温度参数,默认0.7,范围0-2 |
max_tokens | integer | 否 | 最大token数,默认1000,范围1-4000 |
请求示例
{ "model": "Qwen/Qwen3-8B", "messages": [ {"role": "system", "content": "你是一个有用的AI助手。"}, {"role": "user", "content": "请介绍一下人工智能的发展历史"} ], "temperature": 0.7, "max_tokens": 1000 }
图像生成
POST
/api/chat
请求参数
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
model | string | 是 | 图像生成模型,如Kwai-Kolors/Kolors |
prompt | string | 是 | 图像描述,最多1000字符 |
size | string | 否 | 图像尺寸,支持256x256、512x512、1024x1024 |
n | integer | 否 | 生成数量,默认1,范围1-4 |
请求示例
{ "model": "Kwai-Kolors/Kolors", "prompt": "一只可爱的橙色小猫在花园里玩耍", "size": "1024x1024", "n": 1 }
模型列表API
获取所有可用的AI模型信息。
GET
/api/models
响应示例
{ "success": true, "message": "Success", "timestamp": 1640995200, "data": { "object": "list", "data": [ { "id": "Qwen/Qwen3-8B", "object": "model", "created": 1640995200, "owned_by": "Qwen", "description": "通义千问3代8B参数模型", "capabilities": ["chat", "completion"], "tags": ["general", "multilingual", "chinese"], "context_length": 8192, "max_tokens": 8192, "pricing": { "input": "免费", "output": "免费" } } ] } }
错误代码
API使用标准的HTTP状态码表示请求结果。
状态码 | 含义 | 说明 |
---|---|---|
200 | 成功 | 请求成功处理 |
400 | 请求错误 | 请求参数有误 |
401 | 未授权 | API Key无效或缺失 |
403 | 权限不足 | API Key没有访问权限 |
429 | 频率限制 | 请求频率超出限制 |
500 | 服务器错误 | 内部服务器错误 |
错误响应格式
{ "success": false, "error": { "message": "API Key 不能为空", "code": 401 }, "timestamp": 1640995200 }
使用示例
JavaScript/Node.js
// 搜索API示例 const searchResponse = await fetch('https://www.sozeer.com/api/search', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-API-Key': 'sk-your-api-key-here' }, body: JSON.stringify({ query: '人工智能', page: 1, page_size: 10 }) }); const searchData = await searchResponse.json(); console.log(searchData); // AI对话API示例 const chatResponse = await fetch('https://www.sozeer.com/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-API-Key': 'sk-your-api-key-here' }, body: JSON.stringify({ model: 'Qwen/Qwen3-8B', messages: [ {role: 'user', content: '请介绍一下人工智能'} ] }) }); const chatData = await chatResponse.json(); console.log(chatData);
Python
import requests # 搜索API示例 search_response = requests.post( 'https://www.sozeer.com/api/search', headers={'X-API-Key': 'sk-your-api-key-here'}, json={ 'query': '人工智能', 'page': 1, 'page_size': 10 } ) print(search_response.json()) # AI对话API示例 chat_response = requests.post( 'https://www.sozeer.com/api/chat', headers={'X-API-Key': 'sk-your-api-key-here'}, json={ 'model': 'Qwen/Qwen3-8B', 'messages': [ {'role': 'user', 'content': '请介绍一下人工智能'} ] } ) print(chat_response.json())
PHP
Warning: file_get_contents(https://www.sozeer.com/api/search): Failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /www/wwwroot/sozeer.com/api/index.php on line 525
Warning: file_get_contents(https://www.sozeer.com/api/chat): Failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /www/wwwroot/sozeer.com/api/index.php on line 547