狼小嗷把你的本地大模型反向代理为 OpenAI 兼容接口,任何支持 OpenAI 格式的客户端都可以直接接入。
| 项目 | 说明 |
|---|---|
| 基础地址 | 同当前域名 |
| 鉴权方式 | Authorization: Bearer <API 密钥>或 X-API-Key: <API 密钥> |
| 密钥获取 | 「管理后台」中生成 |
| Content-Type | application/json |
AUTH_ENABLED=false),则无需提供密钥。获取可用模型列表。
curl {BASE_URL}/v1/models \
-H "Authorization: Bearer sk-xxxxxxxx"
{
"object": "list",
"data": [
{ "id": "qwen2.5:7b", "object": "model", "created": 1720000000, "owned_by": "local" }
]
}
对话补全(核心接口,支持流式与非流式)。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 否 | 模型名,缺省用默认模型 |
messages | array | 是 | 消息数组 |
stream | boolean | 否 | 是否流式,默认 false |
temperature | number | 否 | 采样温度 0~2 |
max_tokens | integer | 否 | 最大生成 token 数 |
top_p | number | 否 | 核采样参数 |
curl {BASE_URL}/v1/chat/completions \
-H "Authorization: Bearer sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen2.5:7b",
"messages": [
{ "role": "system", "content": "你是狼小嗷,一只乐于助人的小狼。" },
{ "role": "user", "content": "你好!" }
]
}'
{
"id": "chatcmpl-xxxxxxxx",
"object": "chat.completion",
"created": 1720000000,
"model": "qwen2.5:7b",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "你好嗷!有什么可以帮你的吗?" },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 12, "completion_tokens": 8, "total_tokens": 20 }
}
curl {BASE_URL}/v1/chat/completions \
-H "Authorization: Bearer sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen2.5:7b",
"messages": [ { "role": "user", "content": "你好!" } ],
"stream": true
}'
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"好"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
文本补全(旧版接口),输入为 prompt 字符串。
curl {BASE_URL}/v1/completions \
-H "Authorization: Bearer sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{ "model": "qwen2.5:7b", "prompt": "Once upon a time", "max_tokens": 50 }'
文本向量化,输入为 input(字符串或数组)。
curl {BASE_URL}/v1/embeddings \
-H "Authorization: Bearer sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{ "model": "qwen2.5:7b", "input": "Hello world" }'
健康检查(无需鉴权)。
出错时返回 OpenAI 风格错误对象:
{
"error": {
"message": "API 密钥无效、已禁用或已过期。",
"type": "authentication_error",
"code": "invalid_api_key"
}
}
| 状态码 | 含义 |
|---|---|
401 | 缺少或无效的 API 密钥 |
404 | 接口不存在 |
502 | 上游大模型服务错误 |
500 | 服务器内部错误 |
任何 OpenAI SDK 都可以通过设置 base_url 与 api_key 接入,例如 Python:
from openai import OpenAI
client = OpenAI(
base_url="{BASE_URL}/v1",
api_key="sk-xxxxxxxx"
)
resp = client.chat.completions.create(
model="qwen2.5:7b",
messages=[{"role": "user", "content": "你好,狼小嗷!"}]
)
print(resp.choices[0].message.content)