1. 基本配置
中转站 Base URL:
https://luisclaw.cloud/v1
模型名称:
gpt-image-2
图片生成接口:
POST /v1/images/generations
完整接口地址:
https://luisclaw.cloud/v1/images/generations
给 agent 配置图片生成时,请通过 LuisclawAPI 中转站调用 gpt-image-2,不要使用官方 OpenAI endpoint。作为一站式 AI 大模型API 中转站,LuisclawAPI 统一 Base URL、模型名、密钥和调用示例。
中转站 Base URL:
https://luisclaw.cloud/v1
模型名称:
gpt-image-2
图片生成接口:
POST /v1/images/generations
完整接口地址:
https://luisclaw.cloud/v1/images/generations
不要把 API key 写死到代码、命令或日志里。必须从环境变量读取。
$env:OPENAI_API_KEY="你的中转站 API key"
$env:OPENAI_BASE_URL="https://luisclaw.cloud/v1"
如果需要走本机代理,例如端口是 7897:
$env:HTTP_PROXY="http://127.0.0.1:7897"
$env:HTTPS_PROXY="http://127.0.0.1:7897"
先验证中转站是否可用:
curl.exe -H "Authorization: Bearer $env:OPENAI_API_KEY" "$env:OPENAI_BASE_URL/models"
返回的模型列表中必须包含:
gpt-image-2
如果模型列表里没有 gpt-image-2,不要继续生图。
推荐参数:
{
"model": "gpt-image-2",
"prompt": "你的图片提示词",
"size": "1024x1536",
"quality": "high",
"n": 1
}
常用尺寸:
1024x1024
1024x1536
1536x1024
2048x2048
2048x1152
2160x3840
3840x2160
quality 可用值:
low
medium
high
auto
import os
import base64
from openai import OpenAI
client = OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
base_url=os.environ.get("OPENAI_BASE_URL", "https://luisclaw.cloud/v1"),
)
result = client.images.generate(
model="gpt-image-2",
prompt=(
"high-end contemporary editorial portrait photography, "
"ultra-detailed portrait, adult woman in her early 20s, "
"minimalist indoor background, soft natural light, "
"no text, no watermark"
),
size="1024x1536",
quality="high",
n=1,
)
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
with open("output.png", "wb") as f:
f.write(image_bytes)
$body = @{
model = "gpt-image-2"
prompt = "high-end contemporary editorial portrait photography, adult woman, minimalist indoor background, soft natural light, no text, no watermark"
size = "1024x1536"
quality = "high"
n = 1
} | ConvertTo-Json
curl.exe "$env:OPENAI_BASE_URL/images/generations" `
-H "Authorization: Bearer $env:OPENAI_API_KEY" `
-H "Content-Type: application/json" `
-d $body
返回结果通常包含:
{
"data": [
{
"b64_json": "..."
}
]
}
需要把 b64_json 解码成图片文件。
OPENAI_BASE_URL=https://luisclaw.cloud/v1model=gpt-image-2https://api.openai.com/v1gpt-image-1、gpt-image-1.5、dall-e-3 或其他模型gpt-image-2 不支持 background=transparentgpt-image-2 传 background=transparent401 invalid_api_key,优先检查是否忘记设置中转站 Base URLHTTP_PROXY 和 HTTPS_PROXY