API 文档

快速开始

我们的API完全兼容OpenAI API格式,您可以使用任何OpenAI SDK直接对接。

Base URL
https://www.reshi123.com/api/v1

认证方式

所有API请求都需要在HTTP头部携带API密钥进行认证:

Authorization: Bearer YOUR_API_KEY
您可以在 控制台 中创建和管理API密钥。

Chat Completions

创建一个聊天补全请求。

请求
POST /v1/chat/completions
请求参数
参数类型必填说明
modelstring模型ID
messagesarray消息数组
streamboolean是否流式输出
请求示例
{
    "model": "gemini-pro",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": false
}

图片生成 (Gemini)

使用 Gemini 模型生成图片。

请求
POST /v1/gemini/images
请求参数
参数类型必填说明
promptstring图片描述文本
请求示例
{
    "prompt": "我要一个卡通可爱的头像"
}
响应示例
{
    "created": 1703123456,
    "data": [
        {"b64_json": "/9j/4AAQSkZJRg..."}
    ]
}
图片生成消耗更多积分,请确保账户余额充足。

视频生成 (Sora)

使用 Sora 模型生成视频内容,支持标准和高清两种模式。

创建视频生成任务
POST /v1/videos/generations
请求参数
参数类型必填说明
promptstring视频描述文本
modelstringsora-2(标准) 或 sora-2-pro(高清)
durationinteger视频时长(秒),默认: 5
aspect_ratiostring宽高比: 16:9, 9:16, 1:1
请求示例
{
    "prompt": "一只可爱的猫咪在花园里玩者,阳光明媚",
    "model": "sora-2",
    "duration": 5,
    "aspect_ratio": "16:9"
}
查询视频状态
GET /v1/videos/generations/{task_id}
积分消耗: 标准视频(sora-2)消耗 15 积分/次,高清视频(sora-2-pro)消耗 150 积分/次

图片上传

上传图片到服务器,返回可访问的URL。支持文件上传和Base64两种方式。

请求
POST /api/upload.php
方式一: 文件上传 (multipart/form-data)
参数类型必填说明
imagefile图片文件 (JPG/PNG/GIF/WebP, 最大10MB)
方式二: Base64上传 (application/json)
{
    "image_base64": "data:image/png;base64,iVBORw0KGgo...",
    "filename": "my_image.png"
}
响应示例
{
    "success": true,
    "message": "上传成功",
    "data": {
        "url": "http://example.com/uploads/images/20231228/xxx.png",
        "filename": "xxx.png",
        "size": 102400,
        "expire_at": "2023-12-31 12:00:00"
    }
}
图片默认保留 3 天后自动删除,请及时保存重要图片。

获取模型列表

GET /v1/models

错误处理

状态码说明
200请求成功
401未认证或API密钥无效
402积分不足
403API密钥被禁用

代码示例

对话示例

Python
import openai

client = openai.OpenAI(
    base_url="https://www.reshi123.com/api/v1",
    api_key="sk-your-api-key"
)

response = client.chat.completions.create(
    model="gemini-pro",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
cURL
curl https://www.reshi123.com/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{"model": "gemini-pro", "messages": [{"role": "user", "content": "Hello!"}]}'

图片生成示例

Python
import requests
import base64

api_base = "https://www.reshi123.com/api/v1"
headers = {
    "Authorization": "Bearer sk-your-api-key",
    "Content-Type": "application/json"
}

response = requests.post(f"{api_base}/gemini/images", headers=headers, json={
    "prompt": "我要一个卡通可爱的头像"
})

result = response.json()
print(result)
cURL
curl https://www.reshi123.com/api/v1/gemini/images \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{"prompt": "我要一个卡通可爱的头像"}'

视频生成示例

Python
import requests
import time

api_base = "https://www.reshi123.com/api/v1"
headers = {
    "Authorization": "Bearer sk-your-api-key",
    "Content-Type": "application/json"
}

# 创建视频生成任务
response = requests.post(f"{api_base}/videos/generations", headers=headers, json={
    "prompt": "一只可爱的猫咪在花园里玩者",
    "model": "sora-2",
    "duration": 5
})
task = response.json()
task_id = task["id"]
print(f"任务ID: {task_id}")

# 轮询查询状态
while True:
    status = requests.get(f"{api_base}/videos/generations/{task_id}", headers=headers).json()
    if status["status"] == "completed":
        print(f"视频URL: {status['video_url']}")
        break
    elif status["status"] == "failed":
        print(f"生成失败: {status['error']}")
        break
    time.sleep(5)
cURL
# 创建任务
curl https://www.reshi123.com/api/v1/videos/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{"prompt": "一只可爱的猫咪在花园里玩者", "model": "sora-2"}'