# Image Generation

> Generate and edit images from text prompts across all supported image models.

- Canonical: https://tchavi.com/en/docs/image-generation

---


<Endpoint method="POST" path="/v1/images/generations" />

Generate images from text prompts across all supported image models — Nano Banana, Imagen, GPT Image, DALL·E, and more. The same endpoint also handles image editing when you pass reference images (aliased as `POST /v1/images/edits`).

## Common request body

The fields below are shared by every image model. Model-specific options — `size`, `aspect_ratio`, `resolution`, `quality`, `output_format`, `negative_prompt`, `seed`, `background`, etc. — depend on the family. Open the model on [Models](/en/models) and switch to the **API** tab for the full parameter reference.

| Parameter         | Type     | Required | Description                                                                                                                            |
| ----------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `model`           | string   | Yes      | Any image model ID — e.g. `nano-banana-pro`, `imagen-4`, `gpt-image-1`, `dall-e-3`.                                                    |
| `prompt`          | string   | Yes      | Text description of the image to generate.                                                                                             |
| `n`               | integer  | No       | Number of images (1–4). Default: 1                                                                                                     |
| `response_format` | string   | No       | `b64_json` (default — base64 in response) or `url` (hosted URL). Model support varies.                                                 |
| `images`          | string[] | No       | Base64-encoded reference images for editing. The max number accepted depends on the model (e.g. 14 for Nano Banana, 16 for GPT Image). |
| `user`            | string   | No       | Optional end-user identifier for abuse monitoring.                                                                                     |

## Example

Swap `model` for any image model ID — parameters beyond those shown below must match that model's API tab.

<CodeTabs>

```tchavi
import Tchavi from '@tchavi/sdk';

const client = new Tchavi({ apiKey: 'YOUR_API_KEY' });

const result = await client.images.generations.create({
  model: 'YOUR_MODEL_ID',
  prompt: 'A colorful parrot on a branch, digital art',
});

console.log(result.data[0].b64_json);
console.log('Credits used:', result.tchavi.credits_used);
```

```javascript
const response = await fetch('https://tchavi.com/api/v1/images/generations', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer YOUR_API_KEY',
  },
  body: JSON.stringify({
    model: 'YOUR_MODEL_ID',
    prompt: 'A colorful parrot on a branch, digital art',
  }),
});

const data = await response.json();
// Decode base64 image
const imageData = data.data[0].b64_json;
console.log('Credits used:', data.tchavi.credits_used);
```

```python
import requests, base64

response = requests.post(
    "https://tchavi.com/api/v1/images/generations",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY",
    },
    json={
        "model": "YOUR_MODEL_ID",
        "prompt": "A colorful parrot on a branch, digital art",
    },
)

data = response.json()
image_bytes = base64.b64decode(data["data"][0]["b64_json"])
with open("image.png", "wb") as f:
    f.write(image_bytes)
```

```curl
curl -X POST https://tchavi.com/api/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "prompt": "A colorful parrot on a branch, digital art"
  }'
```

</CodeTabs>

The response contains base64-encoded image data in `data[0].b64_json`. Here's how to use it:

<CodeTabs>

```javascript
// Display the image in a browser
const img = document.createElement('img');
img.src = `data:image/png;base64,${data.data[0].b64_json}`;
document.body.appendChild(img);
```

```tchavi
// Save to disk in Node.js
import { writeFileSync } from 'fs';
writeFileSync('image.png', Buffer.from(data.data[0].b64_json, 'base64'));
```

```python
# Save to disk in Python
import base64
with open("image.png", "wb") as f:
    f.write(base64.b64decode(data["data"][0]["b64_json"]))
```

</CodeTabs>

