最近在用 Yuan Image 做文生图,把一套可直接跑的 curl 流程记下来,方便自己以后复用,也给同样走 API 的同学参考。
相关入口(只用这三个):
官网 API:https://api.apixhm.com
文生图:https://image.apixhm.com
文档:https://doc.apixhm.com
说明:下面 Key 写成 YOUR_KEY;模型名如 dall-e-3 / gpt-4o-mini 以控制台实际开通为准。Base URL 记得带 /v1。
一、直接用 curl 调文生图
文生图接口:POST https://image.apixhm.com/v1/images/generations
curl [url]https://image.apixhm.com/v1/images/generations[/url] \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dall-e-3",
"prompt": "A quiet Tokyo alley at night, neon reflections on wet pavement, cinematic lighting",
"n": 1,
"size": "1024x1024"
}'
成功时响应里一般会有图片 URL 或 b64 数据,按你控制台开通的返回格式取即可。若 401/403,先核对 Key 与是否开通了对应模型。
二、先用对话模型写英文提示词,再塞进文生图请求
提示词质量直接影响出图。可以让对话模型先帮你把中文需求翻译/扩写成适合文生图的英文 prompt。
对话接口:POST https://api.apixhm.com/v1/chat/completions
curl [url]https://api.apixhm.com/v1/chat/completions[/url] \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You write concise English prompts for text-to-image models. Output only the prompt."
},
{
"role": "user",
"content": "画一张雨夜东京小巷,霓虹倒映在湿润路面,电影感光影"
}
]
}'
把返回的 content 当作 prompt,再请求文生图:
PROMPT='A quiet Tokyo alley in the rain at night, neon reflections on wet pavement, cinematic lighting'
curl [url]https://image.apixhm.com/v1/images/generations[/url] \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d "{
"model": "dall-e-3",
"prompt": "$PROMPT",
"n": 1,
"size": "1024x1024"
}"
这样「对话写提示词 → 文生图出图」两条链路就串起来了,本地脚本也好包一层。
三、排错时看这三处
1) 文档:先对照 https://doc.apixhm.com 里的字段、鉴权与示例,确认路径是 /v1/...,别漏掉 /v1。
2) Key:Authorization 用 Bearer YOUR_KEY;无效 Key、过期或未开通模型时最常见。
3) Base URL:对话走 https://api.apixhm.com/v1 ,文生图走 https://image.apixhm.com/v1 ;混用域名或少写 /v1 会直接 404/路由错误。
模型名以控制台开通列表为准,dall-e-3、gpt-4o-mini 只是常见示例。有报错把 HTTP 状态码和响应 body 对着文档核对,一般很快就能定位。
以上是我这边目前稳定能跑通的路径,欢迎补充你们控制台里实际可用的模型组合。
|