背景
我在本地部署了 CLIProxyAPI(CPA)作为所有上游 AI 服务的统一中转。文本模型 agnes-2.0-flash 别名设为 flash,运行稳定。今天想在 CPA 中接入生图模型 agnes-image-2.1-flash,结果踩了一整天的坑。
最终结论很简洁:生图必须走 /images/generations 端点 + 模型名必须用 gpt-image-2,因为 CPA 把 agnes-image-2.1-flash 别名注册为了 gpt-image-2。
踩坑过程
❌ 直接调 agnes-image-2.1-flash,两个端点都失败
方案 A:走 /chat/completions
HTTP 503: "auth_unavailable: no auth available (providers=agnes, model=agnes-image-2.1-flash)"
CPA 找不到 agnes provider 的认证信息(因为别名注册的是 gpt-image-2,不是 agnes)。
方案 B:走 /images/generations
HTTP 400: "Model agnes-image-2.1-flash is not supported on /v1/images/generations. Use gpt-image-2, grok-imagine-image, grok-imagine-image-quality, or a configured openai-compatibility image model."
CPA 的 /images/generations 端点只认识 gpt-image-2 等受认可的模型名,不认识 agnes-image-2.1-flash。
❌ 用 gpt-image-2 走 /chat/completions
HTTP 503: "model gpt-image-2 is only supported on /v1/images/generations and /v1/images/edits"
CPA 限制了 gpt-image-2 只能在图片端点使用。
❌ 在 /images/generations 请求中加 tools: [{"type": "image_generation"}]
HTTP 400: "Tool choice 'image_generation' not found in 'tools' parameter."
OpenAI 标准图片生成 API 不需要 tools 参数,CPA 也没做兼容。
真相大白:open-webui 的对照测试
| open-webui 生图模型配置 | 实际调用端点 | CPA 日志 | 结果 |
|---|---|---|---|
agnes-image-2.1-flash | /chat/completions | 未知 provider | ❌ 失败 |
gpt-image-2 | /images/generations | 别名路由到 agnes-image-2.1-flash | ✅ 成功 |
关键发现:你在 open-webui 里把 CPA 中的 agnes-image-2.1-flash 别名设为了 gpt-image-2,open-webui 调用 /images/generations + gpt-image-2 时,CPA 内部将其路由到真正的 agnes-image-2.1-flash,生图成功。
正确调用方式
curl -X POST "http://192.168.110.10:8317/v1/images/generations" \
-H "Authorization: Bearer $CPA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A stunningly beautiful woman, photorealistic, cinematic lighting",
"size": "1024x1024"
}'
核心要点:
- 端点:
/v1/images/generations(不是/chat/completions) - 模型:
gpt-image-2(不是agnes-image-2.1-flash) - 不需要
tools参数 - CPA 内部会自动将
gpt-image-2路由到agnes-image-2.1-flash
后续:创建了 CPA 生图 Skill
为了方便后续使用,我封装了一个 Skill:
python skills/cpa-image-gen/scripts/gen_image.py --prompt "A cute cat wearing a Santa hat, oil painting style"
生成的图片会自动保存到本地,随后可通过 view_image 或 send_file_to_user 展示。
总结
| 错误类型 | 触发原因 | 解决 |
|---|---|---|
auth_unavailable (503) | 走 /chat/completions + 非 gpt-image-2 | 改走 /images/generations |
not supported on /images/generations (400) | 用了 agnes-image-2.1-flash 模型名 | 改用 gpt-image-2 |
tool_choice not found (400) | 在 /images/generations 加了 tools 参数 | 去掉 tools |
only supported on /images/generations (503) | 用 gpt-image-2 走 /chat/completions | 改端点 |
记住一句话:CPA 里生图 = /images/generations + gpt-image-2。