API 参考
LyDian Enterprise AI 平台的完整 API 文档。包含所有端点、参数和示例用法。
身份验证
所有 API 请求都需要 Bearer 令牌身份验证。请在 authorization 标头中使用您的令牌。
curl -X GET https://www.ailydian.com/api/models \ -H "Authorization: Bearer sk-lydian-xxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json"
安全提示
- 切勿在公共代码库中共享您的 API 密钥
- 存储在环境变量中
- 不要在客户端代码中使用
- 定期更新您的密钥
post
/api/chat
使用 AI 模型创建对话。您可以从 23 种不同的模型中选择。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| message | string | 是 | 用户消息 |
| model | string | 否 | 要使用的模型(默认:LyDian Engine) |
| stream | boolean | 否 | 流式传输模式(默认:false) |
| temperature | number | 否 | 0-1 范围,创造力级别 |
示例请求
const response = await fetch('https://www.ailydian.com/api/chat', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: 'yapay zeka nedir?',
model: 'LyDian Engine',
temperature: 0.7
})
});
const data = await response.json();
// DEBUG: console.log(data.response);
示例响应
{
"success": true,
"response": "yapay zeka, makinelerin insan benzeri...",
"model": "LyDian Engine",
"tokens": 156,
"timestamp": "2024-01-15T10:30:00Z"
}
post
/api/chat
通过实时流式传输获取响应。每个令牌到达时即时显示。
示例请求(流式传输)
const response = await fetch('https://www.ailydian.com/api/chat', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: 'uzun bir makale yaz',
stream: true
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
process.stdout.write(chunk); // write as each word arrives
}
get
/api/models
列出所有可用的 AI 模型。显示每个模型的功能和限制。
示例请求
curl -X GET https://www.ailydian.com/api/models \ -H "Authorization: Bearer YOUR_API_KEY"
示例响应
{
"models": [
{
"id": "LyDian Engine",
"name": "LyDian Engine Omni",
"provider": "lydian-labs",
"capabilities": ["chat", "vision", "code"],
"max_tokens": 128000
},
{
"id": "enterprise-ai-3.5",
"name": "Ultra Intelligence Model",
"provider": "advanced-ai-platform",
"capabilities": ["chat", "code", "analysis"],
"max_tokens": 200000
}
]
}
post
/api/vision
执行图像分析。对象检测、人脸识别、OCR 和内容审核。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| image | string | 是 | base64 编码的图像或 URL |
| task | string | 是 | detect, ocr, moderate, describe |
示例请求
const response = await fetch('https://www.ailydian.com/api/vision', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
image: 'https://example.com/image.jpg',
task: 'describe'
})
});
const data = await response.json();
post
/api/generate-image
根据文本描述生成高质量图像。使用 LyDian Image Engine 模型。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| prompt | string | 是 | 图像描述 |
| size | string | 否 | 1024x1024, 1792x1024, 1024x1792 |
| quality | string | 否 | standard, hd |
示例请求
const response = await fetch('https://www.ailydian.com/api/generate-image', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'a minimalist mountain landscape at sunset',
size: '1024x1024',
quality: 'hd'
})
});
post
/api/translate
支持 84 种语言的文本翻译。使用 z.ai 语言包。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| text | string | 是 | 要翻译的文本 |
| from | string | 否 | 源语言(自动检测) |
| to | string | 是 | 目标语言代码 |
示例请求
const response = await fetch('https://www.ailydian.com/api/translate', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: 'hello world',
to: 'tr'
})
});
错误代码
| 代码 | 状态 | 说明 |
|---|---|---|
| 400 | 错误请求 | 请求格式或参数无效 |
| 401 | 未授权 | API 密钥无效或缺失 |
| 403 | 禁止访问 | 您无权访问此资源 |
| 429 | 速率限制 | 请求过多,请稍后重试 |
| 500 | 服务器错误 | 服务器错误,请联系支持团队 |
速率限制
您的 API 请求会根据您的套餐类型受到限制。
| 套餐 | 请求/分钟 | 请求/天 | 令牌限制 |
|---|---|---|---|
| free | 10 | 100 | 10k tokens |
| starter | 60 | 10,000 | 100k tokens |
| pro | 300 | 100,000 | 1M tokens |
| enterprise | 无限制 | 无限制 | 无限制 |