官方能力边界
- Anthropic 官方 API 没有独立的图片生成 endpoint
- Claude 官方强项是图像理解,而不是直接产出图片资产
推荐工作流
- 用 Claude /v1/messages 生成或改写图片提示词
- 将整理后的 prompt 交给支持生图的 provider
- 再用 Claude 做图片审核、解释或二次改写
最小请求
{
"model": "claude-sonnet-4-20250514",
"max_tokens": 600,
"system": "You turn product briefs into image-generation prompts.",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "把这段需求整理成适合生图模型的英文 prompt:为 Api.Go 做一张简洁、科技感、浅色背景的产品海报。"
}
]
}
]
}
cURL 示例
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 600,
"system": "You turn product briefs into image-generation prompts.",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "把这段需求整理成适合生图模型的英文 prompt:为 Api.Go 做一张简洁、科技感、浅色背景的产品海报。"
}
]
}
]
}'
Python 示例
from anthropic import Anthropic
client = Anthropic(api_key="<ANTHROPIC_API_KEY>")
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=600,
system="You turn product briefs into image-generation prompts.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "把这段需求整理成适合生图模型的英文 prompt:为 Api.Go 做一张简洁、科技感、浅色背景的产品海报。",
}
],
}
],
)
print(response.content[0].text)
Node.js 示例
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const response = await client.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 600,
system: "You turn product briefs into image-generation prompts.",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "把这段需求整理成适合生图模型的英文 prompt:为 Api.Go 做一张简洁、科技感、浅色背景的产品海报。"
}
]
}
]
});
console.log(response.content[0].text);
最佳实践
- 不要伪造一个“Claude 生图接口”给前端
- Claude 更适合做 prompt refinement、素材审核和视觉理解
- 生成链路和理解链路应拆成两条后端流程
