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

# Image generation and editing APIs

> Choose RunBridge AI image generation and editing routes for GPT Image, Google Nano Banana, and Grok.

Use GPT Image, Google Nano Banana, or Grok to generate and edit images. Choose the model family, then follow its request format and image response handling.

## Choose an image API

<CardGroup cols={2}>
  <Card title="Generate GPT images" icon="image" href="/api/image/openai/images">
    Generate GPT images and read the Base64 image data.
  </Card>

  <Card title="Edit GPT images" icon="sparkles" href="/api/image/openai/image-editing">
    Upload source images and request a prompt-driven edit.
  </Card>

  <Card title="Generate Nano Banana images" icon="image" href="/api/image/gemini/gemini-generates-image">
    Generate or edit images with Gemini generateContent.
  </Card>

  <Card title="Generate Grok images" icon="image" href="/api/image/grok/image-generation">
    Generate Grok images with URL or Base64 results.
  </Card>

  <Card title="Edit Grok images" icon="sparkles" href="/api/image/grok/image-editing">
    Send source image URLs or data URIs in a JSON request.
  </Card>

  <Card title="Retrieve a GPT image task" icon="clock" href="/api/image/openai/image-generation-task">
    Poll a GPT image request submitted with async enabled.
  </Card>
</CardGroup>

## Generate an image

The examples below generate one GPT image with `gpt-image-2`. For Nano Banana or Grok, use the corresponding reference above.

<Tip>
  Open [Create an image](/api/image/openai/images) to use the playground and endpoint schema.
</Tip>

<CodeGroup>
  ```python Python theme={null}
  import os
  import requests

  response = requests.post(
      "https://api.runbridge.ai/v1/images/generations",
      headers={
          "Authorization": "Bearer " + os.environ["RUNBRIDGE_API_KEY"],
          "Content-Type": "application/json",
      },
      json={
          "model": "gpt-image-2",
          "prompt": "A clean product photo of a glass teapot on a white table",
          "quality": "low",
          "size": "1024x1024",
          "output_format": "jpeg",
      },
      timeout=120,
  )

  response.raise_for_status()
  result = response.json()
  print(result["data"][0].keys())
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.runbridge.ai/v1/images/generations", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.RUNBRIDGE_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "gpt-image-2",
      prompt: "A clean product photo of a glass teapot on a white table",
      quality: "low",
      size: "1024x1024",
      output_format: "jpeg",
    }),
  });

  if (!response.ok) {
    throw new Error(await response.text());
  }

  const result = await response.json();
  console.log(Object.keys(result.data[0]));
  ```

  ```bash cURL theme={null}
  curl https://api.runbridge.ai/v1/images/generations \
    -H "Authorization: Bearer $RUNBRIDGE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-image-2",
      "prompt": "A clean product photo of a glass teapot on a white table",
      "quality": "low",
      "size": "1024x1024",
      "output_format": "jpeg"
    }'
  ```
</CodeGroup>

## Response example

GPT Image returns Base64 image data in `data[].b64_json`. Decode that value and save the image bytes. The response uses this shape:

```json theme={null}
{
  "created": 1779872000,
  "background": "opaque",
  "data": [
    {
      "b64_json": "<base64-encoded-jpeg>"
    }
  ],
  "output_format": "jpeg",
  "quality": "low",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 19,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 19
    },
    "output_tokens": 196,
    "output_tokens_details": {
      "image_tokens": 196,
      "text_tokens": 0
    },
    "total_tokens": 215
  }
}
```

## Common errors

<AccordionGroup>
  <Accordion title="Invalid model ID">
    Choose an image-capable model from the [Models page](/overview/models).
  </Accordion>

  <Accordion title="Unsupported size">
    Use a size that the selected image endpoint accepts.
  </Accordion>

  <Accordion title="Expired result URL">
    Download Grok URL results promptly after generation completes.
  </Accordion>

  <Accordion title="Upload too large">
    Reduce the source image file size before sending the request again.
  </Accordion>

  <Accordion title="Missing image data">
    Read `b64_json` for GPT Image, final `inlineData` for Nano Banana, or the requested URL or Base64 field for Grok.
  </Accordion>
</AccordionGroup>

## Error codes and retry strategy

<AccordionGroup>
  <Accordion title="400">
    Do not retry until the prompt, size, or image input is fixed.
  </Accordion>

  <Accordion title="401">
    Do not retry until the API key is present and valid.
  </Accordion>

  <Accordion title="404">
    Check the base URL, path, and model ID before retrying.
  </Accordion>

  <Accordion title="413">
    Reduce upload size before retrying.
  </Accordion>

  <Accordion title="429">
    Retry with exponential backoff and reduce concurrency.
  </Accordion>

  <Accordion title="500 or 503">
    Retry with backoff for transient service errors.
  </Accordion>
</AccordionGroup>

<Tip>
  For implementation patterns, see [Error codes and retry strategy](/guides/error-codes-and-retry-strategy) and [Rate limits and concurrency](/guides/rate-limits-and-concurrency).
</Tip>

## Pricing and model directory

<CardGroup cols={3}>
  <Card title="Models page" icon="list" href="/overview/models">
    Read how RunBridge AI exposes model IDs in the docs.
  </Card>

  <Card title="Model directory" icon="puzzle-piece" href="https://runbridge.ai/models/">
    Browse model availability and capabilities.
  </Card>

  <Card title="Pricing" icon="tag" href="https://runbridge.ai/pricing/">
    Check pricing before you call a model.
  </Card>
</CardGroup>


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