跳至主要内容

API 参考

LyDian Enterprise AI 平台的完整 API 文档。包含所有端点、参数和示例用法。

基础 URL
https://www.ailydian.com/api
所有 API 请求均以此基础 URL 开头。在生产环境中请使用您自己的域名。
快速开始
LyDian API 采用 RESTful 架构。所有请求均为 JSON 格式。每个请求都需要通过 authorization 标头进行身份验证。

身份验证

所有 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 无限制 无限制 无限制