📖 API文档

兼容OpenAI API格式,轻松接入

Base URL

https://ai.api.ltzy.top/v1

认证方式

在请求Header中携带API密钥:

Authorization: Bearer sk-your-api-key-here

Chat Completions

POST /v1/chat/completions

curl https://ai.api.ltzy.top/v1/chat/completions \ -H "Authorization: Bearer sk-your-key" \ -H "Content-Type: application/json" \ -d '{ "model": "meta/llama-3.1-70b-instruct", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ], "temperature": 0.7, "max_tokens": 1024 }'

Python SDK 示例

from openai import OpenAI client = OpenAI( api_key="sk-your-key", base_url="https://ai.api.ltzy.top/v1" ) response = client.chat.completions.create( model="meta/llama-3.1-70b-instruct", messages=[ {"role": "user", "content": "你好!"} ] ) print(response.choices[0].message.content)

流式输出 (SSE)

response = client.chat.completions.create( model="meta/llama-3.1-70b-instruct", messages=[{"role": "user", "content": "写一首诗"}], stream=True ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")

Models 列表

GET /v1/models

curl https://ai.api.ltzy.top/v1/models \ -H "Authorization: Bearer sk-your-key"

错误码

状态码说明
401API密钥无效或缺失
429请求过于频繁,请稍后重试
500服务内部错误
503服务暂时不可用