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

# GPT-4o-Image - Text To Image

> Stunning gpt 4o image text to image. Rapidly generate beautiful AI visuals and photography from your text prompts.

## Authentication

1. Sign up for a GPTProto account at [https://gptproto.com](https://gptproto.com)
2. Navigate to the API Keys section in your dashboard
3. Generate a new API key (sk-xxxxx)
4. Copy and securely store your API key
   For authentication details, please refer to the [Authentication](https://docs.gptproto.com/authentication) section.

## Initiate Request

<CodeGroup>
  ```bash cURL theme={null}
  curl --location 'https://gptproto.com/v1/images/generations' \
  --header 'Authorization: GPTPROTO_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-4o-image",
    "prompt": "a cat",
    "size": "1024x1024"
  }'

  ```

  ```javascript JavaScript theme={null}
  const axios = require('axios');
  let data = JSON.stringify({
    "model": "gpt-4o-image",
    "prompt": "a cat",
    "size": "1024x1024"
  });

  let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'https://gptproto.com/v1/images/generations',
    headers: { 
      'Authorization': 'GPTPROTO_API_KEY', 
      'Content-Type': 'application/json'
    },
    data : data
  };

  axios.request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });


  ```

  ```python Python theme={null}
  import requests
  import json

  url = "https://gptproto.com/v1/images/generations"

  payload = json.dumps({
    "model": "gpt-4o-image",
    "prompt": "a cat",
    "size": "1024x1024"
  })
  headers = {
    'Authorization': 'GPTPROTO_API_KEY',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)


  ```

  ```go Go theme={null}
  package main

  import (
    "fmt"
    "strings"
    "net/http"
    "io"
  )

  func main() {

    url := "https://gptproto.com/v1/images/generations"
    method := "POST"

    payload := strings.NewReader(`{
    "model": "gpt-4o-image",
    "prompt": "a cat",
    "size": "1024x1024"
  }`)

    client := &http.Client {
    }
    req, err := http.NewRequest(method, url, payload)

    if err != nil {
      fmt.Println(err)
      return
    }
    req.Header.Add("Authorization", "GPTPROTO_API_KEY")
    req.Header.Add("Content-Type", "application/json")

    res, err := client.Do(req)
    if err != nil {
      fmt.Println(err)
      return
    }
    defer res.Body.Close()

    body, err := io.ReadAll(res.Body)
    if err != nil {
      fmt.Println(err)
      return
    }
    fmt.Println(string(body))
  }

  ```
</CodeGroup>

<Accordion title="Response Example">
  ```json theme={null}
  {
    "created": 1776843003,
    "background": "opaque",
    "data": [
      {
        "b64_json": "<BASE64_DATA>"
      }
    ],
    "output_format": "png",
    "quality": "low",
    "size": "1024x1024",
    "usage": {
      "input_tokens": 8,
      "input_tokens_details": {
        "image_tokens": 0,
        "text_tokens": 8
      },
      "output_tokens": 196,
      "output_tokens_details": {
        "image_tokens": 196,
        "text_tokens": 0
      },
      "total_tokens": 204
    }
  }
  ```
</Accordion>

## Parameters

<Tabs>
  <Tab title="Text to Image" icon="image">
    | Parameter            | Type    | Required | Default       | Range                                                                                                                                                         | Description                                                                                                                                                                                                                                                                                                                             |
    | -------------------- | ------- | -------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | `model`              | string  | ✅ Yes    | `gpt-image-1` | `gpt-image-1`<br />`gpt-image-1-mini`<br />`gpt-image-1.5`<br />`gpt-image-2`                                                                                 | The model to use for image generation. Defaults to gpt-image-1.                                                                                                                                                                                                                                                                         |
    | `prompt`             | string  | ✅ Yes    | -             | -                                                                                                                                                             | A text description of the desired image(s). The maximum length is 32000 characters.                                                                                                                                                                                                                                                     |
    | `n`                  | integer | ❌ No     | `1`           | `1-10`                                                                                                                                                        | The number of images to generate. Must be between 1 and 10.                                                                                                                                                                                                                                                                             |
    | `size`               | string  | ❌ No     | `auto`        | `auto`<br />`1024x1024`<br />`1536x1024`<br />`1024x1536`<br />`2048x2048`<br />`2048x1152`<br />`3840x2160`<br />`2160x3840`<br />*or any valid custom size* | The size of the generated images. For gpt-image-1: one of auto, 1024x1024, 1536x1024, or 1024x1536. For gpt-image-2: supports arbitrary resolutions (max edge ≤ 3840px, both sides must be multiples of 16px, aspect ratio ≤ 3:1, total pixels between 655,360 and 8,294,400). Outputs exceeding 2560×1440 are considered experimental. |
    | `quality`            | string  | ❌ No     | `auto`        | `auto`<br />`high`<br />`medium`<br />`low`                                                                                                                   | The quality of the generated images. One of auto, low, medium, or high. Defaults to auto. Not supported by `-plus` suffixed models.                                                                                                                                                                                                     |
    | `background`         | string  | ❌ No     | `auto`        | `opaque`<br />`auto`<br />`transparent`                                                                                                                       | Allows to set transparency for the background of the generated image(s). `transparent` is only supported by gpt-image-1 (not gpt-image-2) and requires output\_format to be png or webp. When auto is used, the model will automatically determine the best background.                                                                 |
    | `moderation`         | string  | ❌ No     | `auto`        | `low`<br />`auto`                                                                                                                                             | Content moderation level for generated images. `low` is less restrictive, `auto` is the default.                                                                                                                                                                                                                                        |
    | `output_format`      | string  | ❌ No     | `auto`        | `auto`<br />`png`<br />`jpeg`<br />`webp`                                                                                                                     | The output format of the generated image(s). Defaults to auto. jpeg is faster than png for latency-sensitive scenarios.                                                                                                                                                                                                                 |
    | `output_compression` | integer | ❌ No     | `100`         | `0-100`                                                                                                                                                       | The compression level (0-100%) for the output image. Only applicable with webp or jpeg format. Defaults to 100.                                                                                                                                                                                                                         |
    | `stream`             | boolean | ❌ No     | `false`       | `true`<br />`false`                                                                                                                                           | Whether to stream the response in real-time. When enabled, partial images can be received during generation.                                                                                                                                                                                                                            |
    | `partial_images`     | integer | ❌ No     | -             | `0-3`                                                                                                                                                         | The number of partial images to receive during streaming. Only used when stream is true. Each partial image incurs an additional 100 image output tokens.                                                                                                                                                                               |
    | `user`               | string  | ❌ No     | -             | -                                                                                                                                                             | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.                                                                                                                                                                                                                                      |
  </Tab>

  <Tab title="Image Edit" icon="pencil">
    | Parameter            | Type    | Required | Default       | Range                                                                                                                                                         | Description                                                                                                                                                                                                                                                                    |
    | -------------------- | ------- | -------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
    | `model`              | string  | ✅ Yes    | `gpt-image-1` | `gpt-image-1`<br />`gpt-image-1-mini`<br />`gpt-image-1.5`<br />`gpt-image-2`                                                                                 | The model to use for image editing. Defaults to gpt-image-1.                                                                                                                                                                                                                   |
    | `prompt`             | string  | ✅ Yes    | -             | 1–32000 chars                                                                                                                                                 | A text description of the desired image edit.                                                                                                                                                                                                                                  |
    | `images`             | file    | ✅ Yes    | -             | max 16 images<br />\< 50MB each                                                                                                                               | The input image(s) to edit. Each image should be a png, webp, or jpg file. You can provide up to 16 images.                                                                                                                                                                    |
    | `mask`               | file    | ❌ No     | -             | -                                                                                                                                                             | An additional image whose fully transparent areas indicate where the image should be edited.                                                                                                                                                                                   |
    | `input_fidelity`     | string  | ❌ No     | -             | `high`<br />`low`                                                                                                                                             | Controls how faithfully the model preserves the original input image. Only supported by gpt-image-1. gpt-image-2 always uses high fidelity.                                                                                                                                    |
    | `n`                  | integer | ❌ No     | `1`           | `1-10`                                                                                                                                                        | The number of images to generate. Must be between 1 and 10.                                                                                                                                                                                                                    |
    | `size`               | string  | ❌ No     | `auto`        | `auto`<br />`1024x1024`<br />`1536x1024`<br />`1024x1536`<br />`2048x2048`<br />`2048x1152`<br />`3840x2160`<br />`2160x3840`<br />*or any valid custom size* | The size of the generated images. For gpt-image-1: one of auto, 1024x1024, 1536x1024, or 1024x1536. For gpt-image-2: supports arbitrary resolutions (max edge ≤ 3840px, both sides must be multiples of 16px, aspect ratio ≤ 3:1, total pixels between 655,360 and 8,294,400). |
    | `quality`            | string  | ❌ No     | `auto`        | `auto`<br />`high`<br />`medium`<br />`low`                                                                                                                   | The quality of the generated images. One of auto, low, medium, or high. Defaults to auto. Not supported by `-plus` suffixed models.                                                                                                                                            |
    | `background`         | string  | ❌ No     | `auto`        | `opaque`<br />`auto`<br />`transparent`                                                                                                                       | Allows to set transparency for the background of the generated image(s). `transparent` is only supported by gpt-image-1 (not gpt-image-2) and requires output\_format to be png or webp.                                                                                       |
    | `moderation`         | string  | ❌ No     | `auto`        | `low`<br />`auto`                                                                                                                                             | Content moderation level for generated images. `low` is less restrictive, `auto` is the default.                                                                                                                                                                               |
    | `output_format`      | string  | ❌ No     | `auto`        | `auto`<br />`png`<br />`jpeg`<br />`webp`                                                                                                                     | The output format of the generated image(s). Defaults to auto. jpeg is faster than png for latency-sensitive scenarios.                                                                                                                                                        |
    | `output_compression` | integer | ❌ No     | `100`         | `0-100`                                                                                                                                                       | The compression level (0-100%) for the output image. Only applicable with webp or jpeg format. Defaults to 100.                                                                                                                                                                |
    | `stream`             | boolean | ❌ No     | `false`       | `true`<br />`false`                                                                                                                                           | Whether to stream the response in real-time. When enabled, partial images can be received during generation.                                                                                                                                                                   |
    | `partial_images`     | integer | ❌ No     | -             | `0-3`                                                                                                                                                         | The number of partial images to receive during streaming. Only used when stream is true. Set to 0 for a single streaming event with the complete image. Each partial image incurs an additional 100 image output tokens.                                                       |
    | `user`               | string  | ❌ No     | -             | -                                                                                                                                                             | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.                                                                                                                                                                             |
  </Tab>
</Tabs>

## Error Codes

### Common Error Codes

| Error Code | Error Name               | Description                                                                                                       |
| ---------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------- |
| 401        | Unauthorized             | API key is missing or invalid                                                                                     |
| 403        | Forbidden                | Your API key doesn't have permission to access this resource, or insufficient balance for the requested operation |
| 429        | Too Many Requests        | You've exceeded your rate limit                                                                                   |
| 500        | Internal server error    | An internal server error occurred                                                                                 |
| 503        | Content policy violation | Content blocked due to safety concerns (actual status code is 400)                                                |
