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

# Image Generation

> The Prisma AIRS AI Gateway's AI gateway supports image generation capabilities that many foundational model providers offer.

The most common use case is that of **text-to-image** where the user sends a prompt which the image model processes and returns an image.

<Info>
  The guide for vision models is [available here](/docs/aigw/product/ai-gateway/multimodal-capabilities/vision).
</Info>

## Text-to-Image Usage

The AI Gateway supports the OpenAI signature to make text-to-image requests.

<Tabs>
  <Tab title="OpenAI NodeJS">
    ```js theme={"system"}
    import OpenAI from 'openai'; // We're using the v4 SDK

    const openai = new OpenAI({
      apiKey: "PORTKEY_API_KEY",  // defaults to process.env["PORTKEY_API_KEY"]
      baseURL: "https://aigw.portkey.ai/v1",
      defaultHeaders: {
      }
    });

    async function main() {
      const image = await openai.images.generate({
        model: "@openai/dall-e-3",
        prompt: "Lucy in the sky with diamonds"
      });

      console.log(image.data);
    }

    main();
    ```
  </Tab>

  <Tab title="OpenAI Python">
    ```py theme={"system"}
    from openai import OpenAI
    from IPython.display import display, Image

    client = OpenAI(
        api_key="PORTKEY_API_KEY",
        base_url="https://aigw.portkey.ai/v1",
    )

    image = client.images.generate(
      model="@openai/dall-e-3",
      prompt="Lucy in the sky with diamonds",
      n=1,
      size="1024x1024"
    )

    # Display the image
    display(Image(url=image.data[0].url))
    ```
  </Tab>

  <Tab title="cURL">
    ```sh theme={"system"}
    curl "https://aigw.portkey.ai/v1/images/generations" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $PORTKEY_API_KEY" \
      -H "x-portkey-provider: $OPENAI_PROVIDER" \
      -d '{
        "model": "dall-e-3",
        "prompt": "Lucy in the sky with diamonds"
      }'
    ```
  </Tab>
</Tabs>

## Image Editing

The AI Gateway supports the OpenAI signature to make image edit requests using multipart form data.

<Note>
  Image edit models currently do not support provider-prefixed model slugs in the request body. Pass the provider in headers and keep `model` as the raw provider model name.
</Note>

### API Reference

* [Create Image](/docs/provider-endpoints/images/create-image)
* [Create Image Edit](/docs/provider-endpoints/images/create-image-edit)

### OpenAI gpt-image-1 Parameters

For OpenAI's `gpt-image-1` model, additional parameters are supported:

| Parameter            | Type    | Description                                    |
| -------------------- | ------- | ---------------------------------------------- |
| `moderation`         | string  | Content moderation level for generated images  |
| `output_format`      | string  | Output format for the generated image          |
| `output_compression` | number  | Compression level (0-100) for the output image |
| `background`         | string  | Background style for the generated image       |
| `partial_images`     | number  | Number of partial images to return (0-3)       |
| `stream`             | boolean | Whether to stream partial image results        |

On completion, the request will get logged in the logs UI where the image can be viewed.

(*Note that providers may remove the hosted image after a period of time, so some logs might only contain the url*)

## Cookbook

[**Here's a detailed cookbook on image generation using the AI Gateway**](https://github.com/Portkey-AI/portkey-cookbook/blob/main/examples/image-generation.ipynb) which demonstrates the use of multiple providers and routing between them through Configs.


## Related topics

- [Azure OpenAI](/docs/aigw/integrations/llms/azure-openai/azure-openai.md)
- [Z.AI](/docs/aigw/integrations/llms/z-ai.md)
- [ZhipuAI / ChatGLM / BigModel](/docs/aigw/integrations/llms/zhipu.md)
- [BytePlus ModelArk](/docs/aigw/integrations/llms/byteplus.md)
- [Open WebUI](/docs/aigw/integrations/libraries/openwebui.md)
