GPT-4o Image Generation API
Use Cases
Pricing
Important Notice
gpt-4o-image-preview
stream
modeRequest Examples
Simple Text to Image
curl --location 'https://api.piapi.ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: {your-api-key}' \
--data '{
"model": "gpt-4o-image-preview",
"messages": [
{
"role": "user",
"content": "Make an image of a four‑panel strip, with some padding around the border:\n\nA little snail is at the counter of a flashy car showroom. The salesman has leaned way over the desk to even see him.\n\nClose‑up on the snail looking very serious. He says, “I want your fastest sports car… and I want you to paint big letter ‘S’s on the doors, the hood and the roof.”\n\nThe salesman is scratching his head. “Um… we can do that, but why the S’s?”\n\nSmash cut to a red blur roaring down the highway. The sports car is covered in giant S’s. People on the sidewalk are pointing and laughing: “WOW! LOOK AT THAT S‑CAR GO!”"
}
],
"stream": true
}'
Simple Image to Image
curl --location 'https://api.piapi.ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your-api-key}' \
--data '{
"model": "gpt-4o-image-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://images.ctfassets.net/kftzwdyauwt9/21orfxKx8HXXGKH8cTOq60/1eb34535ddce9c9e91fab0fad77bc158/minnias_cat_input.png?w=640&q=90&fm=webp"
}
},
{
"type": "text",
"text": "Give this cat a detective hat and a monocle"
}
]
}
],
"stream": true
}'
Multiple Rounds Conversation
1st Request
curl --location 'https://api.piapi.ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your-api-key}' \
--data '{
"model": "gpt-4o-image-preview",
"messages": [
{
"role": "user",
"content": "an photorealistic image of a blue chainsaw"
}
],
"stream": true
}'
1st Response
{
"id": "chatcmpl-89DUFLZV9Ag7HbeoFtKmVyof66666",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "```\n{\n \"prompt\": \"A photorealistic image of a blue chainsaw\",\n \"ratio\": \"1:1\"\n}\n```\n\n\n\n> ID: `task_01jqv3bxzrfvprt0nwhmv6vb5t`\n> Queuing.\n> Generating.....\n> Progress 12%.\n> Progress 23%..\n> Progress 34%..\n> Progress 46%.\n> Progress 57%..\n> Progress 69%.\n> Generation complete ✅\n\n> gen_id: `gen_01jqv3ed9zfpvr2rcrza0d0rzd`\n\n"
},
"finish_reason": "stop"
}
]
}
2nd Request
curl --location 'https://api.piapi.ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your-api-key}' \
--data '{
"model": "gpt-4o-image-preview",
"messages": [
{
"role": "user",
"content": "an photorealistic image of a blue chainsaw"
},
{
"role": "assistant",
"content": "```\n{\n \"prompt\": \"A photorealistic image of a blue chainsaw\",\n \"ratio\": \"1:1\"\n}\n```\n\n\n\n> ID: `task_01jqv3bxzrfvprt0nwhmv6vb5t`\n> Queuing.\n> Generating.....\n> Progress 12%.\n> Progress 23%..\n> Progress 34%..\n> Progress 46%.\n> Progress 57%..\n> Progress 69%.\n> Generation complete ✅\n\n> gen_id: `gen_01jqv3ed9zfpvr2rcrza0d0rzd`\n\n"
},
{
"role": "user",
"content": "make an ad for this chainsaw, of a grandma carving turkey at thanksgiving dinner table. add a tag line"
}
],
"stream": true
}'
Modified at 2025-04-03 05:42:55