API文档

1. 获取API密钥

登录后进入控制台,在"密钥管理"页面生成您的API密钥。请妥善保管密钥,不要泄露给他人。

sk-ailetme-xxxxxxxxxxxxxxxx

2. 发起请求

使用以下示例代码发起API请求:

curl https://api.ailetme.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'

3. Python示例

import openai

client = openai.OpenAI(
    base_url="https://api.ailetme.com/v1",
    api_key="YOUR_API_KEY"
)

response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)

4. 错误处理

API返回标准HTTP状态码:

  • 200 - 请求成功
  • 400 - 请求参数错误
  • 401 - 认证失败(密钥无效)
  • 429 - 速率限制
  • 500 - 服务器错误