OneKeyModel LogoOneKeyModel

API 接口文档

通过统一的 OpenAI 兼容接口,轻松接入文本、图像和视频生成模型。

基础地址与鉴权

所有的 API 请求都需要使用统一的 Base URL,并在请求头中携带您的 API 密钥(Token)进行鉴权。

Base URL
https://api.onekeymodel.com/v1
鉴权请求头格式
Authorization: Bearer YOUR_API_KEY

文本对话接口 (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),因此该过程分为两步:提交任务和轮询结果。

步骤 1:提交视频生成任务POST /v1/video/generations
向接口提交生成参数,会立即返回一个状态为 `in_progress` 或 `queued` 的任务记录,包含 `id`(即 task_id)。
bash
curl -X POST https://api.onekeymodel.com/v1/v1/video/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -d '{
    "model": "wan2.7-t2v",
    "prompt": "A futuristic city in cyberpunk style, flying cars",
    "resolution": "1280*720"
  }'

# Response Example:
# {
#   "id": "148ed382-b7e1-4357-9d29-c70f61cd3a2f",
#   "status": "in_progress",
#   "created_at": 1715865000
# }
步骤 2:轮询任务状态GET /v1/video/generations/:task_id
使用上一步获取的 `id`,每隔几秒查询一次任务状态。当状态变为 `succeeded` 或 `completed` 时,将包含最终的视频链接。
bash
curl -X GET "https://api.onekeymodel.com/v1/video/generations/148ed382-b7e1-4357-9d29-c70f61cd3a2f" \
  -H "Authorization: Bearer $YOUR_API_KEY"

# Response Example (When Finished):
# {
#   "id": "148ed382-b7e1-4357-9d29-c70f61cd3a2f",
#   "status": "succeeded",
#   "created_at": 1715865000,
#   "video_url": "https://example.com/video.mp4"
# }