简介
Grsai API 是一个 AI 模型 API 聚合平台,提供 GPT Image、Gemini、Veo3 等主流 AI 模型的接口服务。 本文档面向下游开发者,描述如何通过 API Key 调用我们的接口,请求会自动转发到上游模型提供商。
核心流程:下游用户 → 提交请求到我们的 API → 我们转发到上游模型 → 返回结果给下游用户
认证方式
所有 API 请求都需要在 HTTP 头中携带 API Key 进行认证:
# 请求头格式
Authorization: Bearer sk-grsai-xxxxxxxxxxxxxxxxxxxxxxxx
获取 API Key 步骤:
- 1. 注册 Grsai API 账号(注册即送 5000 积分)
- 2. 登录控制台,进入「API 密钥」页面
- 3. 点击「创建密钥」,生成
sk-grsai-xxx格式的密钥 - 4. 在请求头中使用该密钥调用 API
API Key 仅在创建时显示一次完整内容,请妥善保存。每个账户最多可创建 5 个密钥。
基础信息
| Base URL | https://your-domain.com/api/v1 |
| 认证方式 | Bearer Token(API Key) |
| 请求格式 | JSON (application/json) |
| 响应格式 | JSON |
| 字符编码 | UTF-8 |
/api/v1/generate
图像/视频生成
提交图像或视频生成请求,支持 GPT Image、Nano Banana、Veo3 等模型。异步接口,返回任务 ID 后需轮询查询结果。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,如 gpt-image-2-vip |
prompt | string | 是 | 提示词,描述要生成的内容 |
images | array | 否 | 参考图片 URL 数组(图生图模式) |
aspectRatio | string | 否 | 宽高比,默认 1:1,可选 16:9 9:16 4:3 3:4 |
imageSize | string | 否 | 图片尺寸,默认 1K |
replyType | string | 否 | 返回类型,默认 json |
请求示例
# cURL curl -X POST https://your-domain.com/api/v1/generate \ -H "Authorization: Bearer sk-grsai-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-image-2-vip", "prompt": "A cute cat wearing sunglasses", "aspectRatio": "1:1" }'
响应示例
{
"code": 0,
"message": "操作成功",
"data": {
"id": "task-abc123",
"status": "succeeded",
"results": [
{ "url": "https://cdn.grsai.com/generated/image.jpg" }
]
}
}
/api/v1/result?id={task_id}
查询异步结果
生成接口返回任务 ID 后,通过此接口轮询查询生成结果。建议每 2-3 秒轮询一次。
请求示例
curl -X GET "https://your-domain.com/api/v1/result?id=task-abc123" \ -H "Authorization: Bearer sk-grsai-xxx"
响应示例
{
"code": 0,
"data": {
"id": "task-abc123",
"status": "succeeded",
"results": [{ "url": "https://cdn.grsai.com/result.jpg" }]
}
}
/api/v1/chat/completions
对话补全(OpenAI 兼容)
支持 GPT-5.4、Gemini 等文本对话模型,接口格式兼容 OpenAI Chat Completions API。支持流式(SSE)和非流式两种模式。
流式模式:设置 "stream": true 即可启用 SSE 流式输出,响应头 Content-Type: text/event-stream,数据以 data: {...}\n\n 格式逐块推送,末尾发送 data: [DONE]。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,如 gpt-5.4 |
messages | array | 是 | 消息数组,格式同 OpenAI |
stream | boolean | 否 | 是否流式输出,默认 false |
请求示例(非流式)
curl -X POST https://your-domain.com/api/v1/chat/completions \ -H "Authorization: Bearer sk-grsai-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.4", "messages": [ { "role": "user", "content": "Hello, who are you?" } ] }'
响应示例(非流式)
{
"code": 0,
"data": {
"id": "chat-xxx",
"choices": [{
"message": { "role": "assistant", "content": "I am an AI assistant..." }
}],
"usage": { "prompt_tokens": 10, "completion_tokens": 20 }
}
}
请求示例(流式)
curl -X POST https://your-domain.com/api/v1/chat/completions \ -H "Authorization: Bearer sk-grsai-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.4", "messages": [ { "role": "user", "content": "Hello!" } ], "stream": true }'
响应示例(流式 SSE)
# 响应头: Content-Type: text/event-stream data: {"id":"chat-xxx","choices":[{"delta":{"content":"Hello"}}]} data: {"id":"chat-xxx","choices":[{"delta":{"content":"!"}}]} data: [DONE]
/api/v1/images/generations
图片生成(OpenAI 兼容)
兼容 OpenAI Images API 格式的图片生成接口。
请求示例
curl -X POST https://your-domain.com/api/v1/images/generations \ -H "Authorization: Bearer sk-grsai-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "nano-banana-pro", "prompt": "A sunset over mountains", "size": "1024x1024", "response_format": "url" }'
/api/v1/batch-generate
批量生成
一次请求生成多张图片(1-10张),每张独立计费。
请求示例
curl -X POST https://your-domain.com/api/v1/batch-generate \ -H "Authorization: Bearer sk-grsai-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-image-2", "prompt": "A beautiful landscape", "count": 3, "aspectRatio": "16:9" }'
/api/v1/models
模型列表
获取所有可用模型及其定价信息。
curl -X GET https://your-domain.com/api/v1/models \
-H "Authorization: Bearer sk-grsai-xxx"
响应示例
{
"object": "list",
"data": [
{
"id": "gpt-image-2",
"display_name": "GPT Image 2",
"category": "image",
"pricing_type": "per_request",
"cost_credits": 600,
"description": "高质量图像生成模型"
},
{
"id": "rh-video",
"display_name": "RunningHub 图生视频",
"category": "video",
"pricing_type": "per_request",
"cost_credits": 3000,
"description": "图生视频模型,支持时长6-30秒"
}
]
}
图像模型
| 模型 ID | 显示名称 | 积分消耗 |
|---|---|---|
gpt-image-2 | GPT Image 2 | 600 |
gpt-image-2-vip | GPT Image 2 VIP | 1300 |
nano-banana-pro | Nano Banana Pro | 1800 |
nano-banana-2 | Nano Banana 2 | 1200 |
nano-banana-2-lite | Nano Banana 2 Lite | 440 |
nano-banana-fast | Nano Banana Fast | 440 |
gemini-3.1-flash-image-preview | Gemini 3.1 Flash Image | 440 |
gemini-3-pro-image-preview | Gemini 3 Pro Image | 1200 |
gemini-2.5-flash-image | Gemini 2.5 Flash Image | 440 |
视频模型
| 模型 ID | 显示名称 | 支持分辨率 | 支持时长 | 积分消耗 |
|---|---|---|---|---|
rh-video | RunningHub 图生视频 | 480p, 720p | 6-30s | 3000 |
rh-video-v3.1-fast | RunningHub 图生视频 V3.1 Fast | 720p, 1080p, 4K | 8s | 4000 |
rh-video-s | RunningHub 图生视频 S | 720p, 1080p, 4K | 10s, 15s | 5000 |
rh-video-start-end | RunningHub 首尾帧生视频 | 720p, 1080p, 4K | 8s | 6000 |
veo3 | Veo 3 | - | - | 10000 |
注意:视频模型调用与图像模型使用相同的 API 端点(/api/v1/generate、/api/v1/chat/completions 等),系统会根据模型 category 自动路由到对应上游供应商。
视频生成额外参数:resolution(分辨率)、duration(时长秒数)、aspectRatio(16:9 / 9:16)。
/api/v1/me
账户信息
查询当前 API Key 关联的账户信息及积分余额。
curl -X GET https://your-domain.com/api/v1/me \
-H "Authorization: Bearer sk-grsai-xxx"
响应示例
{
"code": 0,
"data": {
"id": "user-xxx",
"email": "user@example.com",
"credits": 4800,
"balance": 0,
"plan": "free"
}
}
错误码
| HTTP 状态码 | 说明 | 解决方法 |
|---|---|---|
401 | 未认证 / API Key 无效 | 检查 Authorization 头是否正确 |
400 | 参数错误 | 检查请求参数是否完整 |
403 | 积分不足 / 账号被封禁 | 充值积分或联系管理员 |
500 | 上游 API 调用失败 | 稍后重试或联系技术支持 |
代码示例
Python (requests)
import requests resp = requests.post( "https://your-domain.com/api/v1/generate", headers={ "Authorization": "Bearer sk-grsai-xxx", "Content-Type": "application/json" }, json={ "model": "gpt-image-2-vip", "prompt": "A cute cat", "aspectRatio": "1:1" } ) data = resp.json() print(data["data"]["results"][0]["url"])
Node.js (fetch)
const resp = await fetch("https://your-domain.com/api/v1/generate", { method: "POST", headers: { "Authorization": "Bearer sk-grsai-xxx", "Content-Type": "application/json" }, body: JSON.stringify({ model: "gpt-image-2-vip", prompt: "A cute cat", aspectRatio: "1:1" }) }); const data = await resp.json(); console.log(data.data.results[0].url);
© 2024 Grsai API - 如有问题请联系 support@grsai.com