接口地址
POST https://img.tidaloath.kdns.fr/v1/generate
鉴权(任选其一):
- 请求头
Authorization: Bearer <api_key> - 请求头
X-API-Key: <api_key>
请求体
| 字段 | 说明 |
|---|---|
prompt | 必填。提示词,支持中文(会自动翻译)。 |
width | 可选,默认 1024,会就近映射。 |
height | 可选,默认 1024,会就近映射。 |
steps | 可选,会被忽略。 |
成功响应
{
"ok": true,
"url": "https://img.tidaloath.kdns.fr/v1/images/<id>",
"base64": "...",
"mime": "image/jpeg",
"width": 768,
"height": 768,
"steps_ignored": true,
"prompt": "一只橘色的猫",
"translated_prompt": "an orange cat"
}
常见错误
- 401 未授权:API 密钥无效或已吊销。
- 429 请求过于频繁,请稍后再试。
- 503 桥接页未连接(需要管理员保持桥接生成器打开)。
curl 示例
curl -sS -X POST https://img.tidaloath.kdns.fr/v1/generate \
-H "Authorization: Bearer 你的API密钥" \
-H "Content-Type: application/json" \
-d '{"prompt":"一只橘色的猫","width":768,"height":768,"steps":20}' \
--max-time 200
Python 示例
部分防护会拦截默认的 Python-urllib 标识。请像下面这样设置 User-Agent(使用 requests 库时一般不必改)。curl 可直接调用。
import json, base64, urllib.request
req = urllib.request.Request(
"https://img.tidaloath.kdns.fr/v1/generate",
data=json.dumps({
"prompt": "一只橘色的猫",
"width": 768,
"height": 768,
"steps": 20,
}).encode(),
headers={
"Authorization": "Bearer 你的API密钥",
"Content-Type": "application/json",
"User-Agent": "PictureCreatorAPI/1.0",
},
method="POST",
)
with urllib.request.urlopen(req, timeout=200) as r:
data = json.loads(r.read().decode())
print("url:", data.get("url"))
if data.get("base64"):
with open("out.jpg", "wb") as f:
f.write(base64.b64decode(data["base64"]))