Skip to main content

Image Generation API

Generate images using state-of-the-art models including DALL-E 3, Stable Diffusion 3, Flux, and Ideogram. The API follows the OpenAI Images API format for easy integration.

Endpoint

POST https://api.withperf.pro/v1/images/generations

Authentication

Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY

Request Body

Required Parameters

ParameterTypeDescription
promptstringA text description of the desired image (max 4000 chars)

Optional Parameters

ParameterTypeDefaultDescription
modelstringdall-e-3Model to use for generation
nnumber1Number of images to generate (1 for DALL-E 3, 1-10 for others)
sizestring1024x1024Image dimensions
qualitystringstandardQuality level (standard or hd, DALL-E 3 only)
stylestringvividStyle preset (vivid or natural, DALL-E 3 only)
response_formatstringurlReturn format (url or b64_json)

Supported Models

ModelProviderSizesMax ImagesPricing
dall-e-3OpenAI1024x1024, 1792x1024, 1024x179210.040/image(standard),0.040/image (standard), 0.080/image (HD)
dall-e-2OpenAI256x256, 512x512, 1024x102410$0.016-0.020/image
stable-diffusion-3Stability AI1024x1024, custom4$0.035/image
flux-proBlack Forest Labs1024x1024, custom4$0.055/image
flux-devBlack Forest Labs1024x1024, custom4$0.025/image
ideogram-2Ideogram1024x1024, custom4$0.040/image
imagen-3Google1024x10244$0.040/image

Request Examples

cURL

curl -X POST https://api.withperf.pro/v1/images/generations \
  -H "Authorization: Bearer pk_live_abc123" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A serene Japanese garden with cherry blossoms at sunset, photorealistic",
    "model": "dall-e-3",
    "size": "1024x1024",
    "quality": "hd",
    "style": "vivid"
  }'

JavaScript

const response = await fetch('https://api.withperf.pro/v1/images/generations', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer pk_live_abc123',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'A serene Japanese garden with cherry blossoms at sunset, photorealistic',
    model: 'dall-e-3',
    size: '1024x1024',
    quality: 'hd'
  })
});

const data = await response.json();
console.log(data.data[0].url);

Python

import requests

response = requests.post(
    'https://api.withperf.pro/v1/images/generations',
    headers={
        'Authorization': 'Bearer pk_live_abc123',
        'Content-Type': 'application/json'
    },
    json={
        'prompt': 'A serene Japanese garden with cherry blossoms at sunset, photorealistic',
        'model': 'dall-e-3',
        'size': '1024x1024',
        'quality': 'hd'
    }
)

data = response.json()
print(data['data'][0]['url'])

Response

Success Response (200 OK)

{
  "created": 1706123456,
  "data": [
    {
      "url": "https://storage.withperf.pro/images/abc123.png",
      "revised_prompt": "A serene traditional Japanese garden featuring pink cherry blossom trees in full bloom, with petals gently falling over a stone path and koi pond, bathed in warm golden sunset light, photorealistic style"
    }
  ],
  "perf": {
    "request_id": "req_img_abc123",
    "model_used": "dall-e-3",
    "size": "1024x1024",
    "quality": "hd",
    "cost_usd": 0.080,
    "latency_ms": 5234
  }
}

Response Fields

FieldTypeDescription
creatednumberUnix timestamp of generation
dataarrayArray of generated images
data[].urlstringURL to the generated image (expires after 1 hour)
data[].b64_jsonstringBase64-encoded image (if response_format: "b64_json")
data[].revised_promptstringThe actual prompt used (DALL-E 3 rewrites prompts)
perf.request_idstringUnique request identifier for tracking
perf.model_usedstringModel that generated the image
perf.sizestringImage dimensions
perf.qualitystringQuality level used
perf.cost_usdnumberCost of this generation
perf.latency_msnumberGeneration time in milliseconds

Prompt Best Practices

Be Specific

{
  "prompt": "A red 1965 Ford Mustang convertible parked in front of a neon-lit diner at night, rain-wet street reflecting the lights, cinematic photography style"
}

Specify Style

{
  "prompt": "Portrait of a wise elderly wizard with a long white beard, oil painting style, dramatic lighting, renaissance art influence"
}

Use Negative Guidance

For models that support it, describe what you don’t want:
{
  "prompt": "A clean modern kitchen interior, minimalist design, no people, no text, professional architectural photography"
}

Error Responses

400 Bad Request

{
  "error": {
    "type": "invalid_request",
    "message": "prompt is required",
    "param": "prompt"
  }
}

400 Content Policy Violation

{
  "error": {
    "type": "content_policy_violation",
    "message": "Your request was rejected as a result of our safety system."
  }
}

429 Rate Limit

{
  "error": {
    "type": "rate_limit_exceeded",
    "message": "Rate limit exceeded for image generation",
    "retry_after": 60
  }
}

Rate Limits

TierImages/MinuteImages/Day
Free550
Pro301,000
EnterpriseCustomCustom