快速开始
用一个 API Key,发起你的第一次图像生成请求。
连接 Exgravity ai
所有请求通过 HTTPS 发送。使用下面的 Base URL;兼容客户端如果会自动补全接口路径,填到 /v1 即可。
https://api.sanzhilang.online/v1准备密钥与模型
发送第一次请求
/v1/images/generations示例使用 gpt-image-2、单张图片与 2048x2048 尺寸。请按你的分组权限和模型目录调整模型与尺寸。
curl https://api.sanzhilang.online/v1/images/generations \
-H "Authorization: Bearer $EXGRAVITY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A white ceramic vase on a pale background, soft natural light",
"n": 1,
"size": "2048x2048"
}'import json
import os
from urllib.request import Request, urlopen
payload = {
"model": "gpt-image-2",
"prompt": "A white ceramic vase on a pale background, soft natural light",
"n": 1,
"size": "2048x2048"
}
request = Request(
"https://api.sanzhilang.online/v1/images/generations",
data=json.dumps(payload).encode(),
headers={
"Authorization": f"Bearer {os.environ['EXGRAVITY_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
)
with urlopen(request, timeout=180) as response:
result = json.load(response)
print(result["data"])const response = await fetch(
"https://api.sanzhilang.online/v1/images/generations",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.EXGRAVITY_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model": "gpt-image-2",
"prompt": "A white ceramic vase on a pale background, soft natural light",
"n": 1,
"size": "2048x2048"
}),
signal: AbortSignal.timeout(180_000),
},
);
const result = await response.json();
if (!response.ok) throw new Error(result.error?.message ?? response.statusText);
console.log(result.data);读取生成结果
结果位于 data 数组中。图片可能通过 b64_json 或 url 返回,具体取决于模型和返回格式。收到 Base64 时解码为图片文件;收到链接时及时下载保存。
{
"created": 1792324800,
"data": [
{
"b64_json": "<base64-encoded image>"
}
]
}





















































