标准兼容 · 鉴权 · 流式输出

开发者文档

集中说明 Base URL、鉴权、聊天补全、流式输出、错误码和限流。已有 API Key 时可以直接按示例接入。

快速开始

确认端点、配置密钥、接入客户端,然后发起首个请求。

选择接入端点

根据你的客户端类型选择合适的 API 端点。支持 Chat Completions、Responses 和 Messages 等标准兼容接口。

Base URL: https://new.weeanno.shop/v1

准备 API Key

使用已经开通的 API Key,并只放在服务端环境变量中,避免暴露到浏览器代码。

Authorization: Bearer sk-your-api-key

集成客户端

使用兼容客户端或直接调用 REST API,配置 base_url 后即可快速接入。

base_url = 'https://new.weeanno.shop/v1'

开始调用

发送请求获取 AI 响应,支持流式输出以获得更好的用户体验。

POST /v1/chat/completions

身份认证

所有 API 请求都需要在 HTTP Header 中携带 API Key 进行身份认证。

认证格式

Add your API key to the Authorization header on every request.

POST/v1/chat/completions

带认证的请求示例

Request example
json
curl https://new.weeanno.shop/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{
    "model": "deepseek-r1",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
Response example
json
{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "Hello! How can I help you today?"
    }
  }]
}
推荐 Base URL
https://new.weeanno.shop/v1大部分客户端使用此地址
备用 Base URL
https://new.weeanno.shop客户端验证失败时使用
Chat Completions 兼容接口
/v1/chat/completions标准聊天补全协议
Responses 兼容接口
/v1/responses支持 Responses 格式的客户端优先使用
Messages 兼容接口
/v1/messagesMessages-compatible 客户端优先使用

聊天补全 API

Chat Completions 兼容接口,支持多种模型能力。

curl
curl https://new.weeanno.shop/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{
    "model": "deepseek-r1",
    "messages": [
      { "role": "system", "content": "你是一个简洁的助手。" },
      { "role": "user", "content": "用一句话介绍你自己。" }
    ]
  }'

请求参数

参数类型必填说明
modelstringYesModel ID, for example gpt-4o-mini
messagesarrayYesArray of chat messages
temperaturenumberNoSampling temperature from 0 to 2, default 1
max_tokensintegerNoMaximum number of tokens to generate
streambooleanNoWhether to enable streaming output
top_pnumberNoNucleus sampling value, default 1

响应字段

字段类型说明
idstringUnique response identifier
objectstringObject type, usually chat.completion
createdintegerCreation timestamp
modelstringModel ID used for the response
choicesarrayGenerated response choices
usageobjectToken usage statistics

流式输出

启用流式输出可以实时接收生成的 token,显著降低用户感知延迟。

流式输出的优势
  • 降低感知延迟 - 用户无需等待完整响应,可以立即看到内容
  • 更好的长文本体验 - 内容像人类打字一样逐步显示
  • 成本相同 - 与同步输出成本完全一致,只是传输方式不同
curl
curl https://new.weeanno.shop/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{
    "model": "deepseek-r1",
    "messages": [
      { "role": "system", "content": "你是一个简洁的助手。" },
      { "role": "user", "content": "用一句话介绍你自己。" }
    ],
    "stream": true
  }'

# 响应将是 SSE (Server-Sent Events) 流式数据

错误码

API 可能返回的错误码及其处理建议。

HTTP 状态码错误名称说明处理建议
400INVALID_REQUESTRequest body is malformed or parameters are invalidCheck the request body and parameters
401UNAUTHORIZEDAPI key is invalid or expiredVerify that the API key is correct
429RATE_LIMITRequest rate limit exceededRetry with exponential backoff
500INTERNAL_ERRORInternal service errorTry again later
503SERVICE_UNAVAILABLEService temporarily unavailableTry again later

限流说明

为了保证服务稳定性,我们对 API 请求进行频率限制。

限流规则
  • Each API key has its own request-rate limits
  • Use exponential backoff when you receive a 429 response
  • Streaming and non-streaming requests share the same rate-limit quota
  • The effective limit follows the current configuration of the key

如有问题,请联系客服或查看 FAQ 页面