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

# Image Generation

> Generate images from text descriptions, compatible with the OpenAI Images API format.

Creates an image given a prompt. [Learn more](https://platform.openai.com/docs/guides/images).

## Headers

**Authorization** `string` *required*

Bearer token authentication. Format: `Bearer <token>`

## Body

Format: `application/json`

**model** `string`

The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or `gpt-image-1`. Defaults to `dall-e-2` unless a parameter specific to `gpt-image-1` is used.

**prompt** `string` *required*

A text description of the desired image. Maximum length is 32,000 characters for `gpt-image-1`, 1,000 characters for `dall-e-2`, and 4,000 characters for `dall-e-3`.

**n** `integer`

The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.

**size** `string`

The size of the generated image. For `gpt-image-1`, must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or `auto` (default); for `dall-e-2`, must be one of `256x256`, `512x512`, or `1024x1024`; for `dall-e-3`, must be one of `1024x1024`, `1792x1024`, or `1024x1792`.

**background** `string`

Allows setting transparency for the background of the generated image. This parameter is only supported for `gpt-image-1`. Must be one of `transparent`, `opaque`, or `auto` (default). When set to `auto`, the model will automatically determine the best background for the image.

If the background is transparent, the output format must support transparency, so it should be set to `png` (default) or `webp`.

**moderation** `string`

Controls the content moderation level for images generated by `gpt-image-1`. Must be `low` (less restrictive filtering) or `auto` (default).

**quality** `string`

The quality of the generated image.

**stream** `string`

Whether to stream the response.

**style** `string`

The style of the generated image.

**user** `string`

A unique identifier representing the end user.

## Response

### 200

Format: `application/json`

**created** `integer` *required*

Creation timestamp (Unix time).

**data** `object[]` *required*

List of generated images.

**Properties**

**b64\_json** `string`

Base64-encoded image data.

**url** `string` *required*

Image URL.

**usage** `object` *required*

Token usage statistics for the image generation process.

**Properties**

**total\_tokens** `integer` *required*

Total token count.

**input\_tokens** `integer` *required*

Input token count.

**output\_tokens** `integer` *required*

Output token count.

**input\_tokens\_details** `object` *required*

Input token breakdown.

**Properties**

**text\_tokens** `integer`

Text token count.

**image\_tokens** `integer`

Image token count.

```bash cURL theme={"dark"}
curl -X POST "https://t.ato2.nodesms.com/v1/images/generations" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dall-e-3",
    "prompt": "A cute baby sea otter wearing a beret",
    "n": 1,
    "size": "1024x1024"
  }'
```

```python Python theme={"dark"}
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxxxx",
    base_url="https://t.ato2.nodesms.com/v1"
)

response = client.images.generate(
    model="dall-e-3",
    prompt="A cute baby sea otter wearing a beret",
    n=1,
    size="1024x1024"
)
print(response.data[0].url)
```

```json 200 theme={"dark"}
{
  "created": 1719123456,
  "data": [
    {
      "url": "https://example.com/image.png"
    }
  ],
  "usage": {
    "total_tokens": 500,
    "input_tokens": 300,
    "output_tokens": 200,
    "input_tokens_details": {
      "text_tokens": 300,
      "image_tokens": 0
    }
  }
}
```


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