> For the complete documentation index, see [llms.txt](https://docs.cortecs.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cortecs.ai/examples/image-generation.md).

# Image Generation

**Image generation** creates images from natural-language prompts, enabling applications such as illustrations, product concepts, marketing assets, and visual prototypes.

To explore available models, visit [cortecs.ai](https://cortecs.ai/serverlessModels?tags=Image-Gen) and filter by the **Image-Gen** tag.

### Example usage

{% tabs %}
{% tab title="Python" %}

```python
import base64
from pathlib import Path

from openai import OpenAI

client = OpenAI(
    base_url="https://api.cortecs.ai/v1",
    api_key="<API_KEY>",
)

response = client.images.generate(
    model="gemini-2.5-flash-image",
    prompt="Generate an image of a blue circle on a white background.",
)

image_base64 = next(
    (image.b64_json for image in response.data if image.b64_json),
    None,
)

if image_base64 is None:
    raise RuntimeError("The response did not contain a Base64-encoded image.")

output_path = Path("generated-image.png")
output_path.write_bytes(base64.b64decode(image_base64))
print(f"Saved image to {output_path.resolve()}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
import fs from "fs";
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://api.cortecs.ai/v1",
  apiKey: "<API_KEY>"
});

const response = await openai.images.generate({
  model: "gemini-2.5-flash-image",
  prompt: "Generate an image of a blue circle on a white background."
});

const imageBase64 = response.data.find((image) => image.b64_json)?.b64_json;

if (!imageBase64) {
  throw new Error("The response did not contain a Base64-encoded image.");
}

await fs.promises.writeFile(
  "generated-image.png",
  Buffer.from(imageBase64, "base64")
);

console.log("Saved image to generated-image.png");
```

{% endtab %}

{% tab title="Curl" %}

```bash
curl 'https://api.cortecs.ai/v1/images/generations' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API_KEY>' \
  -d '{
    "model": "gemini-2.5-flash-image",
    "prompt": "Generate an image of a blue circle on a white background."
  }' \
  | jq -r '.data[] | select(.b64_json != null) | .b64_json' \
  | base64 --decode > generated-image.png
```

{% endtab %}
{% endtabs %}
