快速开始
要开始使用 LyDian API,您首先需要一个 API 密钥。您可以在控制台中创建您的 API 密钥并立即开始使用。
身份验证
所有 API 请求都需要在 Authorization 标头中提供 API 密钥。请将您的 API 密钥作为 Bearer 令牌发送。
HTTP 标头
Authorization: Bearer YOUR_API_KEY
基础 URL
所有 API 端点的基础 URL。在生产环境中请始终使用 HTTPS。
https://api.ailydian.com/v1
聊天补全
与 LyDian AI 模型聊天的主要端点。支持流式(streaming)和非流式模式。实时响应请使用流式模式。
/chat/completions
通过聊天补全端点向 AI 模型提问、编写代码、创建内容等。
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
model必填
|
string | 模型 ID(例如:"lydian-turbo"、"lydian-pro") |
messages必填
|
array | 聊天消息数组(role, content) |
temperature可选
|
number | 0 到 2(默认值:0.7)- 创造力水平 |
max_tokens可选
|
integer | 最大令牌数(默认值:2000) |
stream可选
|
boolean | 流式模式(默认值:false) |
请求示例
const response =
await
fetch('https://api.ailydian.com/v1/chat/completions', { method:
'POST', headers:
{ 'Authorization':
'Bearer sk-lydian-...',
'Content-Type':
'application/json'
},
body: JSON.stringify({ model:
'lydian-turbo',
messages: [ { role:
'user', content:
'Merhaba! AI ile neler yapabilirim?' } ],
temperature: 0.7,
max_tokens: 2000
}) });
const data =
await response.json(); console.log(data.choices[0].message.content);
import requests url =
"https://api.ailydian.com/v1/chat/completions"
headers = {
"Authorization":
"Bearer sk-lydian-...",
"Content-Type":
"application/json"
} data = {
"model":
"lydian-turbo",
"messages": [ {"role": "user",
"content":
"Merhaba! AI ile neler yapabilirim?"} ],
"temperature":
0.7,
"max_tokens":
2000 } response = requests.post(url, json=data, headers=headers)
print(response.json()["choices"][0]["message"]["content"])
curl https://api.ailydian.com/v1/chat/completions \ -H
"Authorization: Bearer sk-lydian-..." \ -H
"Content-Type: application/json" \ -d
'{ "model": "lydian-turbo", "messages": [ {"role": "user", "content":
"Merhaba! AI ile neler yapabilirim?"} ], "temperature": 0.7, "max_tokens":
2000 }'
响应示例
{ "id":
"chatcmpl-abc123",
"object":
"chat.completion",
"created":
1677858242,
"model":
"lydian-turbo",
"choices": [ {
"index": 0,
"message": { "role":
"assistant",
"content":
"Hello! You can do many things with AI..."
},
"finish_reason":
"stop"
} ],
"usage": {
"prompt_tokens":
12,
"completion_tokens":
145,
"total_tokens":
157 } }
图像生成
使用 LyDian Image Engine 及其他图像生成模型,根据文本描述生成高质量图像。
/images/generate
通过图像生成端点根据文本描述生成专业品质的图像。提供不同的尺寸和质量选项。
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
prompt必填
|
string | 图像描述(最多 1000 个字符) |
size可选
|
string | "1024x1024"、"1792x1024"、"1024x1792"(默认值:"1024x1024") |
n可选
|
integer | 要生成的图像数量:1-4(默认值:1) |
quality可选
|
string | "standard" 或 "hd"(默认值:"standard") |
请求示例
curl https://api.ailydian.com/v1/images/generate \ -H
"Authorization: Bearer sk-lydian-..." \ -H
"Content-Type: application/json" \ -d
'{ "prompt": "Futuristic city with flying cars at sunset", "size": "1024x1024",
"n": 1, "quality": "hd" }'
可用模型
LyDian 平台上所有可用的 AI 模型。每个模型都具有不同的能力和定价。
/models
列出所有可用的 AI 模型。包含每个模型的能力、上下文窗口大小和定价信息。
热门模型
错误代码
API 使用标准 HTTP 状态代码。所有错误响应均以 JSON 格式包含详细的错误信息。
状态代码
| Code | Status | Description |
|---|---|---|
200 |
OK | 请求成功 |
400 |
Bad Request | 请求无效或缺少参数 |
401 |
Unauthorized | API 密钥无效或缺失 |
403 |
Forbidden | API 密钥有效但未获授权 |
404 |
Not Found | 未找到所请求的资源 |
429 |
Rate Limit Exceeded | 发送的请求过多 |
500 |
Internal Server Error | 服务器错误 |
503 |
Service Unavailable | 服务暂时不可用 |
错误响应格式
{ "error": {
"message":
"Invalid API key provided",
"type":
"invalid_request_error",
"code":
"invalid_api_key" } }
速率限制
API 速率限制按分钟和小时为基础应用。超出限制时,将返回 429 状态代码。每个响应都包含带有您的速率限制信息的标头。
默认限制
| 套餐 | 请求/分钟 | 请求/小时 | 令牌/分钟 |
|---|---|---|---|
| Free | 3 | 100 | 50,000 |
| Pro | 60 | 3,000 | 500,000 |
| Enterprise | Custom | Custom | Custom |
X-RateLimit-Limit, X-RateLimit-Remaining,
X-RateLimit-Reset