> ## Documentation Index
> Fetch the complete documentation index at: https://www.krea.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Text to Image

> Compare Krea API text-to-image models — Krea 3, Krea 2, Flux, and more — with pricing, capabilities, and code samples to pick the right one.

![](https://s.krea.ai/docs-text-to-image.webp)

# 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.

## Popular Models

Krea 3 logo

### [Krea 3](https://www.krea.ai/docs/developers/krea-3/overview.md)

Krea's newest image model — fast generation and editing at native 2K.

Krea 2 logo

### [Krea 2](https://www.krea.ai/docs/developers/krea-2/overview.md)

Krea's foundation model — style transfer, moodboards, and tunable creativity.

Flux logo

### [Flux](https://www.krea.ai/docs/api-reference/image/flux)

Fast, versatile generation with extensive style support and custom ratios.

Nano Banana Pro logo

### [Nano Banana Pro](https://www.krea.ai/docs/api-reference/image/nano-banana-pro.md)

Google's latest model with superior typography and photorealistic detail.

Seedream 4 logo

### [Seedream 4](https://www.krea.ai/docs/api-reference/image/seedream-4.md)

High quality text-to-image and image-to-image, photorealistic detail and flexible resolution.

GPT Image 2 logo

### [GPT Image 2](https://www.krea.ai/docs/api-reference/image/chatgpt-2.md)

OpenAI's latest image model for high-quality generation and editing.

***

## 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.

> [!NOTE]
>
> 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:

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

const result = await krea.subscribe("image/bfl/flux-1-dev", {
  input: {
    prompt: "a serene mountain landscape at sunset",
    width: 1024,
    height: 576,
    steps: 28
  }
});

console.log(`Image ready: ${result.data?.urls[0]}`);
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
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/bfl/flux-1-dev",
    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["status"] == "completed":
        image_url = job["result"]["urls"][0]
        print(f"Image ready: {image_url}")
        break
    if job["status"] in ("failed", "cancelled"):
        raise Exception(f"Job failed: {job['status']}")

    print(f"Status: {job['status']}")
    time.sleep(2)
```

```go Go theme={"theme":{"light":"github-light-default","dark":"vesper"}}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "time"
)

func main() {
    apiBase := "https://api.krea.ai"
    apiToken := "your-token-secret"
    client := &http.Client{}

    // Step 1: Create generation job
    payload := map[string]interface{}{
        "prompt": "a serene mountain landscape at sunset",
        "width":  1024,
        "height": 576,
        "steps":  28,
    }
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", apiBase+"/generate/image/bfl/flux-1-dev", bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer "+apiToken)
    req.Header.Set("Content-Type", "application/json")

    resp, _ := client.Do(req)
    var job map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&job)
    resp.Body.Close()

    jobID := job["job_id"].(string)

    // Step 2: Poll for completion
    for {
        req, _ := http.NewRequest("GET", apiBase+"/jobs/"+jobID, nil)
        req.Header.Set("Authorization", "Bearer "+apiToken)

        resp, _ := client.Do(req)
        var jobStatus map[string]interface{}
        json.NewDecoder(resp.Body).Decode(&jobStatus)
        resp.Body.Close()

        switch jobStatus["status"] {
        case "completed":
            result := jobStatus["result"].(map[string]interface{})
            imageURL := result["urls"].([]interface{})[0].(string)
            fmt.Printf("Image ready: %s\n", imageURL)
            return
        case "failed", "cancelled":
            fmt.Printf("Job failed: %s\n", jobStatus["status"])
            return
        }

        fmt.Printf("Status: %s\n", jobStatus["status"])
        time.Sleep(2 * time.Second)
    }
}
```

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
# Step 1: Create generation job
curl -X POST https://api.krea.ai/generate/image/bfl/flux-1-dev \
  -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
  }'

# Response: {"job_id": "550e8400-e29b-41d4-a716-446655440000", ...}

# Step 2: Poll for completion (repeat until completed)
curl -X GET https://api.krea.ai/jobs/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer YOUR_API_TOKEN"
```

> [!NOTE]
>
> **Replace with your API Token**
>
> To replace the YOUR\_API\_TOKEN placeholder in the above examples, you'll need to generate an API token in [krea.ai/settings/api-tokens](https://www.krea.ai/settings/api-tokens). Follow the instructions on the [API Keys & Billing](https://www.krea.ai/docs/developers/api-keys-and-billing.md) page if you need help.

To find all available models, see the [Model APIs](https://www.krea.ai/docs/api-reference/introduction.md) 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/bfl/flux-1-dev` with your prompt and parameters. The API returns a job ID immediately—generation happens asynchronously.

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

const job = await krea.image("bfl/flux-1-dev", {
  prompt: "a serene mountain landscape at sunset",
  width: 1024,
  height: 576,
  steps: 28
});

console.log(`Job ID: ${job.job_id}`);
```

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl -X POST https://api.krea.ai/generate/image/bfl/flux-1-dev \
  -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
  }'
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
import requests

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

response = requests.post(
    f"{API_BASE}/generate/image/bfl/flux-1-dev",
    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()
print(f"Job ID: {job['job_id']}")
```

```go Go theme={"theme":{"light":"github-light-default","dark":"vesper"}}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    apiBase := "https://api.krea.ai"
    apiToken := "your-token-secret"

    payload := map[string]interface{}{
        "prompt": "a serene mountain landscape at sunset",
        "width": 1024,
        "height": 576,
        "steps": 28,
    }

    jsonData, _ := json.Marshal(payload)
    req, _ := http.NewRequest("POST", apiBase+"/generate/image/bfl/flux-1-dev", bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer "+apiToken)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    var job map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&job)
    fmt.Printf("Job ID: %s\n", job["job_id"])
}
```

**Example Response**

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "scheduled",
  "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.

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

async function waitForJob(jobId) {
  const completed = await krea.jobs.wait(jobId, { intervalMs: 2000 });
  return completed.result.urls[0];
}

const imageUrl = await waitForJob(job.job_id);
console.log(`Image ready: ${imageUrl}`);
```

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
# Check job status
curl -X GET https://api.krea.ai/jobs/YOUR_JOB_ID \
  -H "Authorization: Bearer YOUR_API_TOKEN"
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
import time

def wait_for_job(job_id):
    while True:
        response = requests.get(
            f"{API_BASE}/jobs/{job_id}",
            headers={"Authorization": f"Bearer {API_TOKEN}"}
        )
        job = response.json()

        if job["status"] == "completed":
            return job["result"]["urls"][0]
        if job["status"] in ("failed", "cancelled"):
            raise Exception(f"Job failed: {job['status']}")

        print(f"Status: {job['status']}")
        time.sleep(2)

image_url = wait_for_job(job["job_id"])
print(f"Image ready: {image_url}")
```

```go Go theme={"theme":{"light":"github-light-default","dark":"vesper"}}
func waitForJob(jobID string) (string, error) {
    for {
        req, _ := http.NewRequest("GET", apiBase+"/jobs/"+jobID, nil)
        req.Header.Set("Authorization", "Bearer "+apiToken)

        resp, _ := client.Do(req)
        var job map[string]interface{}
        json.NewDecoder(resp.Body).Decode(&job)
        resp.Body.Close()

        switch job["status"] {
        case "completed":
            result := job["result"].(map[string]interface{})
            urls := result["urls"].([]interface{})
            return urls[0].(string), nil
        case "failed", "cancelled":
            return "", fmt.Errorf("job failed: %s", job["status"])
        }

        fmt.Printf("Status: %s\n", job["status"])
        time.Sleep(2 * time.Second)
    }
}
```

> [!NOTE]
>
> **Webhooks available!**
>
> Set up webhooks to receive notifications when jobs complete. See the [Webhooks guide](https://www.krea.ai/docs/developers/webhooks.md) to get started.

> [!TIP]
>
> For a list of detailed parameters for all models, see the [Model APIs](https://www.krea.ai/docs/api-reference/introduction.md) page.

**Example Completed Response**

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "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"
    ]
  }
}
```

> [!TIP]
>
> To learn about all possible job statuses and the complete job lifecycle, check out the [Job Lifecycle](https://www.krea.ai/docs/developers/job-lifecycle.md) page.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.