完全兼容 OpenAI 官方协议,切换 baseURL 即可完成迁移
将官方 SDK 的 baseURL 替换为以下地址,其余代码无需改动:
| API Base URL | https://ld.cccfgg.icu/v1 |
|---|---|
| 对话接口 | POST https://ld.cccfgg.icu/v1/chat/completions |
| 模型列表 | GET https://ld.cccfgg.icu/v1/models |
| 向量接口 | POST https://ld.cccfgg.icu/v1/embeddings |
所有接口均需在 HTTP 请求头携带 Bearer Token:
Authorization: Bearer sk-你的密钥 Content-Type: application/json
请勿将密钥硬编码在客户端代码中。建议为不同应用创建不同密钥,并配置模型白名单与额度上限。
POST https://ld.cccfgg.icu/v1/chat/completions
curl https://ld.cccfgg.icu/v1/chat/completions \ -H "Authorization: Bearer sk-你的密钥" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-mini", "messages": [ {"role": "system", "content": "你是一个乐于助人的助手"}, {"role": "user", "content": "用三句话介绍 PHP"} ], "temperature": 0.7, "max_tokens": 1024 }'
{
"id": "chatcmpl-xxxxxxx",
"object": "chat.completion",
"created": 1720000000,
"model": "gpt-4o-mini",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "PHP 是一种..." },
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 88,
"total_tokens": 112
}
}
请求体中传入 "stream": true,响应将以 Server-Sent Events 格式逐块返回:
data: {"id":"chatcmpl-xx","choices":[{"delta":{"content":"你"},"index":0}]}
data: {"id":"chatcmpl-xx","choices":[{"delta":{"content":"好"},"index":0}]}
data: [DONE]
fastcgi_buffering off),否则流式响应会被缓存直至请求结束。
GET https://ld.cccfgg.icu/v1/models Authorization: Bearer sk-你的密钥
返回当前账号可调用的全部模型:
{
"object": "list",
"data": [
{ "id": "gpt-4o-mini", "object": "model", "owned_by": "OpenAI" },
{ "id": "claude-sonnet-4-5", "object": "model", "owned_by": "Anthropic" }
]
}
curl https://ld.cccfgg.icu/v1/embeddings \ -H "Authorization: Bearer sk-你的密钥" \ -H "Content-Type: application/json" \ -d '{"model":"text-embedding-3-small","input":"Hello world"}'
from openai import OpenAI client = OpenAI( api_key="sk-你的密钥", base_url="https://ld.cccfgg.icu/v1" ) response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "你好"}], stream=True ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")
import OpenAI from "openai"; const client = new OpenAI({ apiKey: "sk-你的密钥", baseURL: "https://ld.cccfgg.icu/v1" }); const stream = await client.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: "你好" }], stream: true }); for await (const part of stream) { process.stdout.write(part.choices[0]?.delta?.content || ""); }
# 查看可用模型 curl https://ld.cccfgg.icu/v1/models -H "Authorization: Bearer sk-你的密钥" # 健康检查(无需鉴权) curl https://ld.cccfgg.icu/health
| 参数 | 类型 | 说明 |
|---|---|---|
model | string | 必需。要调用的模型名称 |
messages | array | 必需。对话消息数组,含 role 与 content |
stream | boolean | 是否流式返回,默认 false |
temperature | number | 采样温度,0~2,越大越随机 |
max_tokens | integer | 生成的最大 token 数 |
top_p | number | 核采样,与 temperature 二选一调节 |
stop | string/array | 停止生成的标记词 |
stream_options | object | {"include_usage": true} 可在流末尾返回用量 |
| 状态码 | code | 含义与处理建议 |
|---|---|---|
| 401 | invalid_api_key | 密钥无效或未提供,检查 Authorization 头 |
| 402 | insufficient_quota | 账号额度不足,请充值后重试 |
| 403 | permission_denied | 该密钥无此模型权限,或 IP 不在允许列表 |
| 404 | unknown_endpoint | 接口地址不存在 |
| 429 | rate_limit | 请求过于频繁,请降低频率 |
| 502 | upstream_error | 上游渠道异常,系统已尝试自动切换 |
| 503 | model_not_available | 暂无可用渠道支持该模型 |
所有错误均遵循 OpenAI 格式:
{"error": {"message": "错误描述", "type": "invalid_request_error", "code": "xxx"}}