API 参考
BigDogAI API 完全兼容 OpenAI 格式,可使用现有 SDK 直接调用。
Base URL
https://dashuaigou.cn/v1
URL
认证
所有请求需在 Header 中携带 API Key:
Authorization: Bearer sk-your-api-key
Header
Chat Completions
核心接口POST /v1/chat/completions
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 必填 | 模型 ID,如 qwen-turbo、qwen-plus |
| messages | array | 必填 | 消息列表,每条包含 role 和 content |
| temperature | number | 可选 | 随机性 0-2,默认 1 |
| max_tokens | integer | 可选 | 最大输出 token 数 |
| top_p | number | 可选 | 核采样参数 |
| stream | boolean | 可选 | 是否流式输出 |
| tools | array | 可选 | Function Calling 工具定义 |
| tool_choice | string | 可选 | 工具调用策略:auto/none/required |
| response_format | object | 可选 | JSON Mode 配置 |
请求示例
response = client.chat.completions.create(
model="qwen-turbo",
messages=[
{"role": "system", "content": "你是专业助手"},
{"role": "user", "content": "解释什么是API网关"}
],
temperature=0.7,
max_tokens=1000
)Python
流式输出
设置 stream=True 可启用流式响应:
response = client.chat.completions.create(
model="qwen-turbo",
messages=[{"role": "user", "content": "写一首诗"}],
stream=True
)
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")Python
Function Calling
高级功能支持 OpenAI 兼容的 Function Calling 格式:
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定城市的天气",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "城市名称"}
},
"required": ["city"]
}
}
}
]
response = client.chat.completions.create(
model="qwen-plus",
messages=[{"role": "user", "content": "北京今天天气怎么样?"}],
tools=tools,
tool_choice="auto"
)Python
JSON Mode
强制输出 JSON 格式:
response = client.chat.completions.create(
model="qwen-plus",
messages=[
{"role": "system", "content": "请以JSON格式输出"},
{"role": "user", "content": "列出3个编程语言及其特点"}
],
response_format={"type": "json_object"}
)Python
模型列表
GET /v1/models
curl https://dashuaigou.cn/v1/models -H "Authorization: Bearer sk-your-api-key"
bash
错误码
| 状态码 | 错误码 | 说明 |
|---|---|---|
| 400 | invalid_request_error | 请求参数错误 |
| 401 | invalid_api_key | API Key 无效 |
| 429 | rate_limit_exceeded | 请求过于频繁 |
| 500 | server_error | 服务器内部错误 |