同步生成与编辑
同步接口使用普通模型 API Token。默认响应为 URL;需要把图片直接放入响应时,设置 response_format=b64_json。
bash
export SUPERTOKEN_BASE_URL="https://api.supertoken.cc"
export SUPERTOKEN_KEY="YOUR_MODEL_API_TOKEN"
export IMAGE_MODEL="gemini-3.1-flash-image"文生图
bash
curl -sS "$SUPERTOKEN_BASE_URL/v1/images/generations" \
-H "Authorization: Bearer $SUPERTOKEN_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$IMAGE_MODEL"'",
"prompt": "雨夜霓虹街道的电影概念图,广角构图",
"n": 1,
"aspect_ratio": "16:9",
"resolution": "4K",
"quality": "auto",
"output_format": "png",
"provider_options": {
"google": {
"generationConfig": {
"temperature": 0.8,
"thinkingConfig": {
"thinkingLevel": "HIGH"
}
}
}
}
}' | jq .成功响应:
json
{
"created": 1784682038,
"data": [
{
"url": "https://img.example.com/images/result.png"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 1680,
"total_tokens": 1705,
"input_tokens": 25,
"output_tokens": 1680
}
}Base64 响应
bash
curl -sS "$SUPERTOKEN_BASE_URL/v1/images/generations" \
-H "Authorization: Bearer $SUPERTOKEN_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$IMAGE_MODEL"'",
"prompt": "一个极简闪电图标",
"n": 1,
"aspect_ratio": "1:1",
"resolution": "1K",
"response_format": "b64_json"
}' | jq -r '.data[0].b64_json' > image.b64Base64 是临时响应,不进入资源中心。需要持久 URL、任务查询或 Webhook 时使用异步任务。
URL 图片编辑
Gemini 编辑不支持 Mask。JSON 请求的参考图放在顶层 image:
bash
curl -sS "$SUPERTOKEN_BASE_URL/v1/images/edits" \
-H "Authorization: Bearer $SUPERTOKEN_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-pro-image-count",
"prompt": "保留主体,把背景改成自然光摄影棚",
"image": ["https://img.example.com/reference.png"],
"n": 1,
"aspect_ratio": "1:1",
"resolution": "2K",
"quality": "auto",
"output_format": "png"
}' | jq .本地文件编辑
multipart 中的 provider_options 是 JSON 字符串:
bash
curl -sS "$SUPERTOKEN_BASE_URL/v1/images/edits" \
-H "Authorization: Bearer $SUPERTOKEN_KEY" \
-F "model=$IMAGE_MODEL" \
-F "prompt=保留主体,把背景改成白色摄影棚" \
-F "image=@./reference.png" \
-F "n=1" \
-F "aspect_ratio=4:3" \
-F "resolution=2K" \
-F "quality=auto" \
-F "output_format=png" \
-F 'provider_options={"google":{"generationConfig":{"temperature":0.8}}}' | jq .不要提交 mask。服务会在调用上游前返回 unsupported_mask。
aspect_ratio 和 resolution 是推荐的公开参数。旧 size 仍可使用,但它只映射 Gemini 的比例和分辨率档位,不保证返回精确像素。
Usage 与计费
prompt_tokens/input_tokens 表示输入用量,completion_tokens/output_tokens 表示生成与思考用量,total_tokens 表示总量。输入图片 Token 会出现在输入明细中,输出图片 Token 只计入 completion,避免重复计数。
固定价格模型仍按次计费,但 usage 会照常返回;配置为 Token 价格时,系统先预扣,任务完成后根据实际 usage 多退少补。