API 接口文档
通过统一的 OpenAI 兼容接口,轻松接入文本、图像和视频生成模型。
基础地址与鉴权
所有的 API 请求都需要使用统一的 Base URL,并在请求头中携带您的 API 密钥(Token)进行鉴权。
文本对话接口 (Chat Completions)POST /v1/chat/completions
用于与文本模型进行对话、编写代码、翻译等任务。兼容 OpenAI 的 `/v1/chat/completions` 标准。
cURL 示例
bash
curl https://api.onekeymodel.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'Python 示例
python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.onekeymodel.com/v1"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)图像生成接口 (Image Generations)POST /v1/images/generations
用于调用图像生成模型生成图片。
cURL 示例
bash
curl https://api.onekeymodel.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-d '{
"model": "wan2.7-image",
"prompt": "A beautiful sunset over the mountains, digital art",
"n": 1,
"size": "1024x1024"
}'Python 示例
python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.onekeymodel.com/v1"
)
response = client.images.generate(
model="wan2.7-image",
prompt="A beautiful sunset over the mountains, digital art",
n=1,
size="1024x1024"
)
print(response.data[0].url)视频生成接口 (Video Generations)
由于视频生成通常需要较长的时间(如 wan2.7-t2v),因此该过程分为两步:提交任务和轮询结果。