简单、易用、稳定的AI模型API接口
访问 API密钥管理页面 创建您的专属API密钥。
使用以下接口发送AI对话请求:
curl -X POST "http://localhost:9090/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key-here" \
-H "X-AI-Provider: deepseek" \
-d '{
"model": "deepseek-chat",
"messages": [
{
"role": "user",
"content": "你好,请介绍一下青城数智平台"
}
],
"temperature": 0.7,
"max_tokens": 1000,
"stream": true
}'
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 使用的模型名称 |
| messages | array | 是 | 对话消息列表 |
| temperature | number | 否 | 控制回答的随机性,范围0-2,默认0.7 |
| max_tokens | number | 否 | 最大输出Token数量 |
| stream | boolean | 否 | 是否启用流式响应,默认false |
| 请求头 | 必填 | 说明 |
|---|---|---|
| Content-Type | 是 | application/json |
| X-API-Key | 是 | 您的API密钥 |
| X-AI-Provider | 是 | AI提供商:deepseek |
{
"id": "chatcmpl-123456",
"object": "chat.completion",
"created": 1677652288,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!青城数智是一个先进的AI模型平台..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}
| 状态码 | 错误类型 | 说明 |
|---|---|---|
| 400 | Bad Request | 请求参数错误 |
| 401 | Unauthorized | API密钥无效或缺失 |
| 403 | Forbidden | 账户余额不足 |
| 429 | Too Many Requests | 请求频率超限 |
| 500 | Internal Server Error | 服务器内部错误 |
import requests
import json
url = "http://localhost:9090/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"X-API-Key": "your-api-key-here",
"X-AI-Provider": "deepseek"
}
data = {
"model": "deepseek-chat",
"messages": [
{
"role": "user",
"content": "你好,请介绍一下青城数智平台"
}
],
"temperature": 0.7
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result)
const response = await fetch('http://localhost:9090/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here',
'X-AI-Provider': 'deepseek'
},
body: JSON.stringify({
model: 'deepseek-chat',
messages: [
{
role: 'user',
content: '你好,请介绍一下青城数智平台'
}
],
temperature: 0.7
})
});
const result = await response.json();
console.log(result);
async function streamChat(message) {
const response = await fetch('http://localhost:9090/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here',
'X-AI-Provider': 'deepseek'
},
body: JSON.stringify({
model: 'deepseek-chat',
messages: [{ role: 'user', content: message }],
stream: true,
temperature: 0.7
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6);
if (data === '[DONE]') return;
try {
const parsed = JSON.parse(data);
const content = parsed.choices[0]?.delta?.content;
if (content) {
console.log(content); // 实时输出内容
}
} catch (e) {
// 忽略解析错误
}
}
}
}
} finally {
reader.releaseLock();
}
}
// 使用示例
streamChat('你好,请介绍一下青城数智平台');