文生图
本页示例一个 “Images Generate” 风格的 API 文档页面。
创建图片
POST /v1/images/generations
bash
curl https://api.example.com/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "image-1",
"prompt": "A minimal neon cyberpunk logo, dark background, soft glow"
}'TypeScript 示例
ts
type ImageGenerationRequest = {
model: string
prompt: string
size?: '1024x1024' | '1024x1536' | '1536x1024'
}
export async function generateImage(apiKey: string, req: ImageGenerationRequest) {
const res = await fetch('https://api.example.com/v1/images/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
})
if (!res.ok) throw new Error(await res.text())
return res.json()
}返回格式(示意)
json
{
"created": 1710000000,
"data": [
{ "url": "https://cdn.example.com/images/xxxx.png" }
]
}