Skip to main content

Text to Image

Generate high-quality images from text prompts. Create anything from photorealistic images to artistic illustrations with state-of-the-art AI models.

Text to Image

Generate high-quality images from text prompts. Create anything from photorealistic images to artistic illustrations with state-of-the-art AI models.

Overview

Generate images from text descriptions using Flux, Nano Banana Pro, and other state-of-the-art AI models. This example walks you through the complete workflow from submitting a generation request to retrieving the final image.
Image generation is asynchronous. You’ll receive a job ID immediately, then poll for results until the image is ready.

Interactive Playground

Here’s a complete example in different languages:
import requests
import time

API_BASE = "https://api.krea.ai/"
API_TOKEN = "your-token-secret"

# Step 1: Create generation job
response = requests.post(
    f"{API_BASE}/generate/image/krea-1",
    headers={
        "Authorization": f"Bearer {API_TOKEN}",
        "Content-Type": "application/json"
    },
    json={
        "prompt": "a serene mountain landscape at sunset",
        "width": 1024,
        "height": 576,
        "steps": 28
    }
)
job = response.json()
job_id = job["job_id"]

# Step 2: Poll for completion
while True:
    response = requests.get(
        f"{API_BASE}/jobs/{job_id}",
        headers={"Authorization": f"Bearer {API_TOKEN}"}
    )
    job = response.json()

    if job.get("completed_at"):
        if job["status"] == "completed":
            image_url = job["result"]["urls"][0]
            print(f"Image ready: {image_url}")
            break
        else:
            raise Exception(f"Job failed: {job['status']}")

    print(f"Status: {job['status']}")
    time.sleep(2)
Replace with your API TokenTo replace the YOUR_API_TOKEN placeholder in the above examples, you’ll need to generate an API token in krea.ai/settings/api-tokens. Follow the instructions on the API Keys & Billing page if you need help.
To find all available models, see the Model APIs page.

Breakdown

Below, we’ll walk you through the complete workflow from submitting a generation request to retrieving the final image.

Step 1: Create an Image Generation Job

Make a POST request to /generate/image/krea-1 with your prompt and parameters. The API returns a job ID immediately—generation happens asynchronously.
curl -X POST https://api.krea.ai/generate/image/krea-1 \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "a serene mountain landscape at sunset",
    "width": 1024,
    "height": 576,
    "steps": 28
  }'
Example Response
{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "queued",
  "created_at": "2025-01-15T10:30:00.000Z"
}

Step 2: Poll for Results

Poll /jobs/{job_id} every 2 seconds until the job completes. The Krea API provides intermediate generation outputs for some models.
# Check job status
curl -X GET https://api.krea.ai/jobs/YOUR_JOB_ID \
  -H "Authorization: Bearer YOUR_API_TOKEN"
Webhooks available!Set up webhooks to receive notifications when jobs complete. See the Webhooks guide to get started.
For a list of detailed parameters for all models, see the Model APIs page.
Example Completed Response
{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "completed",
  "created_at": "2025-01-15T10:30:00.000Z",
  "completed_at": "2025-01-15T10:30:25.000Z",
  "result": {
    "urls": [
      "https://krea.ai/generations/your-image.png"
    ]
  }
}
To learn about all possible job statuses and the complete job lifecycle, check out the Job Lifecycle page.