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

# Generating Images

> Turn text prompts into images with full control over size, quality, and format.

## Basic Generation

Generate an image by providing a model and a text prompt.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import os
    from openai import OpenAI

    client = OpenAI(
        base_url="https://api.routeway.ai/v1",
        api_key=os.getenv("ROUTEWAY_API_KEY"),
    )

    response = client.images.generate(
        model="gpt-image-1",
        prompt="A watercolor painting of a mountain lake at dawn",
    )

    print(response.data[0].url)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import OpenAI from "openai";

    const client = new OpenAI({
      baseURL: "https://api.routeway.ai/v1",
      apiKey: process.env.ROUTEWAY_API_KEY,
    });

    const response = await client.images.generate({
      model: "gpt-image-1",
      prompt: "A watercolor painting of a mountain lake at dawn",
    });

    console.log(response.data[0].url);
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://api.routeway.ai/v1/images/generations \
      -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-image-1",
        "prompt": "A watercolor painting of a mountain lake at dawn"
      }'
    ```
  </Tab>
</Tabs>

## Image Sizes

Control the output dimensions with the `size` parameter.

| Size        | Aspect Ratio | Best For                             |
| ----------- | ------------ | ------------------------------------ |
| `1024x1024` | 1:1          | Square images, avatars, icons        |
| `1792x1024` | 16:9         | Landscape, banners, headers          |
| `1024x1792` | 9:16         | Portrait, mobile wallpapers, stories |

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    response = client.images.generate(
        model="gpt-image-1",
        prompt="A panoramic view of a tropical beach",
        size="1792x1024",
    )
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const response = await client.images.generate({
      model: "gpt-image-1",
      prompt: "A panoramic view of a tropical beach",
      size: "1792x1024",
    });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://api.routeway.ai/v1/images/generations \
      -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-image-1",
        "prompt": "A panoramic view of a tropical beach",
        "size": "1792x1024"
      }'
    ```
  </Tab>
</Tabs>

## Quality Settings

The `quality` parameter controls the detail level and generation time.

| Quality  | Description                                            |
| -------- | ------------------------------------------------------ |
| `auto`   | Automatically selects the best quality for the prompt. |
| `low`    | Fastest generation, lower detail.                      |
| `medium` | Balanced speed and detail.                             |
| `high`   | Maximum detail, slower generation.                     |

<Tip>
  Use `auto` for most use cases. It provides the best balance without manual tuning.
</Tip>

## Generating Multiple Images

Set `n` to generate multiple images in a single request.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    response = client.images.generate(
        model="gpt-image-1",
        prompt="A minimalist logo for a coffee shop",
        n=4,
        size="1024x1024",
    )

    for i, image in enumerate(response.data):
        print(f"Image {i + 1}: {image.url}")
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const response = await client.images.generate({
      model: "gpt-image-1",
      prompt: "A minimalist logo for a coffee shop",
      n: 4,
      size: "1024x1024",
    });

    response.data.forEach((image, i) => {
      console.log(`Image ${i + 1}: ${image.url}`);
    });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://api.routeway.ai/v1/images/generations \
      -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-image-1",
        "prompt": "A minimalist logo for a coffee shop",
        "n": 4,
        "size": "1024x1024"
      }'
    ```
  </Tab>
</Tabs>

<Warning>
  Generating multiple images multiplies token/credit usage accordingly.
</Warning>

## Response Format

Choose between a temporary URL or base64-encoded image data.

| Format     | Use Case                                                                     |
| ---------- | ---------------------------------------------------------------------------- |
| `url`      | Default. Returns a short-lived URL to download the image.                    |
| `b64_json` | Returns the image as a base64-encoded string for direct embedding or saving. |

<Info>
  URLs are temporary and expire after a short period. If you need to persist the image, download it immediately or use `b64_json`.
</Info>

## Saving Images Locally

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import base64

    response = client.images.generate(
        model="gpt-image-1",
        prompt="A detailed sketch of a cat wearing a top hat",
        response_format="b64_json",
    )

    image_data = base64.b64decode(response.data[0].b64_json)

    with open("output.png", "wb") as f:
        f.write(image_data)

    print("Image saved to output.png")
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import fs from "fs";

    const response = await client.images.generate({
      model: "gpt-image-1",
      prompt: "A detailed sketch of a cat wearing a top hat",
      response_format: "b64_json",
    });

    const imageBuffer = Buffer.from(response.data[0].b64_json, "base64");
    fs.writeFileSync("output.png", imageBuffer);

    console.log("Image saved to output.png");
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://api.routeway.ai/v1/images/generations \
      -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-image-1",
        "prompt": "A detailed sketch of a cat wearing a top hat",
        "response_format": "b64_json"
      }' | jq -r '.data[0].b64_json' | base64 -d > output.png
    ```
  </Tab>
</Tabs>

## Tips for Better Prompts

<AccordionGroup>
  <Accordion title="Be specific and descriptive">
    Instead of "a dog", try "a golden retriever sitting in a sunlit meadow, photorealistic, soft bokeh background". More detail gives the model stronger guidance.
  </Accordion>

  <Accordion title="Specify a style">
    Include style cues like "watercolor", "3D render", "pixel art", "oil painting", or "studio photography" to steer the aesthetic.
  </Accordion>

  <Accordion title="Describe composition">
    Mention framing details such as "close-up", "bird's-eye view", "centered", or "rule of thirds" for more intentional compositions.
  </Accordion>
</AccordionGroup>
