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

# Text to Image

## Authorization

* **Auth Type**: `Bearer Auth` (In: `header`)
* **Format**: `Authorization: Bearer <YOUR_API_KEY>`
* **Description**: Use `Bearer <YOUR_API_KEY>`. Format: `Authorization: Bearer sk-xxxxxx.`
* **API Key**: where **API Key** is your [AGCloud API KEY](https://developer.aiandgpu.com)

Generate images from a text prompt using `gpt-image-2.6-sunburst`. Send a JSON request to `https://aiandgpu.com/v1/images/generations`.

## Request Examples

```bash cURL theme={null}
curl --location 'https://aiandgpu.com/v1/images/generations' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2.6-sunburst",
    "prompt": "Draw a watercolor illustration of a red panda reading under a maple tree.",
    "n": 1,
    "size": "1024x1024",
    "quality": "medium",
    "output_format": "png"
  }'
```

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

response = requests.post(
    "https://aiandgpu.com/v1/images/generations",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json={
        "model": "gpt-image-2.6-sunburst",
        "prompt": "Draw a watercolor illustration of a red panda reading under a maple tree.",
        "n": 1,
        "size": "1024x1024",
        "quality": "medium",
        "output_format": "png",
    },
    timeout=600,
)
response.raise_for_status()
data = response.json()
with open("generated.png", "wb") as image_file:
    image_file.write(base64.b64decode(data["data"][0]["b64_json"]))
```

```javascript JavaScript theme={null}
// Node.js 18+; save as an .mjs file.
import { writeFile } from "node:fs/promises";

const response = await fetch("https://aiandgpu.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gpt-image-2.6-sunburst",
    prompt: "Draw a watercolor illustration of a red panda reading under a maple tree.",
    n: 1,
    size: "1024x1024",
    quality: "medium",
    output_format: "png",
  }),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
await writeFile("generated.png", Buffer.from(data.data[0].b64_json, "base64"));
```

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

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "time"
)

func main() {
    body, err := json.Marshal(map[string]any{
        "model": "gpt-image-2.6-sunburst",
        "prompt": "Draw a watercolor illustration of a red panda reading under a maple tree.",
        "n": 1,
        "size": "1024x1024",
        "quality": "medium",
        "output_format": "png",
    })
    if err != nil { panic(err) }
    req, err := http.NewRequest("POST", "https://aiandgpu.com/v1/images/generations", bytes.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer <YOUR_API_KEY>")
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 10 * time.Minute}
    res, err := client.Do(req)
    if err != nil { panic(err) }
    defer res.Body.Close()
    result, err := io.ReadAll(res.Body)
    if err != nil { panic(err) }
    if res.StatusCode >= 400 { panic(string(result)) }
    fmt.Println(string(result))
}
```

```java Java theme={null}
// Java 11+; save as GenerateImage.java.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class GenerateImage {
    public static void main(String[] args) throws Exception {
        String body = "{\"model\":\"gpt-image-2.6-sunburst\","
            + "\"prompt\":\"Draw a watercolor illustration of a red panda reading under a maple tree.\","
            + "\"n\":1,\"size\":\"1024x1024\",\"quality\":\"medium\",\"output_format\":\"png\"}";
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://aiandgpu.com/v1/images/generations"))
            .timeout(Duration.ofMinutes(10))
            .header("Authorization", "Bearer <YOUR_API_KEY>")
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build();
        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        if (response.statusCode() >= 400) throw new RuntimeException(response.body());
        System.out.println(response.body());
    }
}
```

```php PHP theme={null}
<?php

$curl = curl_init("https://aiandgpu.com/v1/images/generations");
curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_TIMEOUT => 600,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer <YOUR_API_KEY>",
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "model" => "gpt-image-2.6-sunburst",
        "prompt" => "Draw a watercolor illustration of a red panda reading under a maple tree.",
        "n" => 1,
        "size" => "1024x1024",
        "quality" => "medium",
        "output_format" => "png",
    ]),
]);
$response = curl_exec($curl);
if ($response === false) throw new RuntimeException(curl_error($curl));
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($status >= 400) throw new RuntimeException($response);
echo $response;
```

```csharp C# theme={null}
// .NET 6+
using System;
using System.Net.Http;
using System.Net.Http.Json;

using var client = new HttpClient { Timeout = TimeSpan.FromMinutes(10) };
client.DefaultRequestHeaders.Add("Authorization", "Bearer <YOUR_API_KEY>");
using var response = await client.PostAsJsonAsync(
    "https://aiandgpu.com/v1/images/generations",
    new {
        model = "gpt-image-2.6-sunburst",
        prompt = "Draw a watercolor illustration of a red panda reading under a maple tree.",
        n = 1,
        size = "1024x1024",
        quality = "medium",
        output_format = "png"
    }
);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

## Response Examples

\{
"created": 1777262313,
"data": \[
\{
"b64\_json": "\<BASE64\_ENCODED\_IMAGE>"
}
],
"background": "opaque",
"output\_format": "png",
"quality": "medium",
"size": "1024x1024",
"usage": \{
"total\_tokens": 100,
"input\_tokens": 50,
"output\_tokens": 50,
"input\_tokens\_details": \{
"text\_tokens": 10,
"image\_tokens": 40
}
}
}

\{
"error": \{
"code": "invalid\_params",
"message": "parameter 'ARGUMENT' is required",
"param": null,
"type": "invalid\_request\_error"
}
}

\{
"error": \{
"code": "auth\_invalid",
"message": "Invalid API Key",
"param": null,
"type": "authentication\_error"
}
}

\{
"error": \{
"code": "insufficient\_quota",
"message": "You exceeded your current quota, please check your plan and billing details.",
"param": null,
"type": "insufficient\_quota\_error"
}
}

\{
"error": \{
"code": "permission\_error",
"message": "You have no permission to access the model.",
"type": "permission\_error",
"param": null
}
}

\{
"error": \{
"code": "invalid\_request\_error",
"message": "Invalid URL",
"param": null,
"type": "invalid\_request\_error"
}
}

\{
"error": \{
"code": "rate\_limit\_exceeded",
"message": "Rate limit reached",
"param": null,
"type": "rate\_limit\_error"
}
}

\{
"error": \{
"code": "server\_error",
"message": "Internal server error",
"param": null,
"type": "server\_error"
}
}

The success response is illustrative; replace the Base64 placeholder with actual image data before decoding. OpenAI GPT Image responses use `data[].b64_json`, not image URLs. Do not send `response_format` or `style`; describe the desired style in `prompt`.

## Request Parameters

Checked against the [OpenAI generation reference](https://developers.openai.com/api/reference/resources/images/methods/generate) and [image guide](https://developers.openai.com/api/docs/guides/image-generation) on November 12, 2026. These are upstream parameters; gateway availability depends on the enabled route.

| Field | Type | Required | Default | Description |
| :- | :- | :- | :- | :- |
| `model` | string | ✅ | - | `gpt-image-2.6-sunburst`. |
| `prompt` | string | ✅ | - | up to 32,000 characters. |
| `n` | integer | - | `1` | 1–10; default `1`. |
| `size` | string | - | `auto` | default `auto`; standard sizes include `1024x1024`, `1536x1024`, `1024x1536`. |
| `quality` | string | - | `auto` | `auto` (default), `low`, `medium`, `high`. |
| `background` | string | - | `auto` | `auto` (default), `opaque`, `transparent`; transparency requires PNG/WebP. |
| `output_format` | string | - | `png` | `png` (default), `jpeg`, `webp`, `gif`, `svg`; see format restrictions below. |
| `output_compression` | integer | - | `100` | 0–100, JPEG/WebP only; generation default `100`. |
| `moderation` | string | - | `auto` | `auto` (default) or `low`. |
| `stream` | boolean | - | `false` | default `false`; consume SSE rather than a single JSON document when enabled. |
| `partial_images` | integer | - | `0` | 0–3, default `0`; streaming previews may be fewer than requested. |
| `safety_identifier` | string | - | - | privacy-preserving end-user identifier, at most 128 characters. |
| `user` | string | - | - | deprecated fallback; prefer `safety_identifier`. |

### GPT Image 2.6 controls

| Field | Type | Required | Default | Description |
| :- | :- | :- | :- | :- |
| `complexity` | string | - | `high` | `low`, `medium`, `high`; default `high`. Planning effort is separate from rendering `quality`. |
| `frame_count` | integer | - | `9` | GIF only, integer 2–16, default `9`. |
| `frame_duration_ms` | integer | - | `200` | GIF only, integer, default `200`. The guide specifies 20–2000 ms and 10 ms rounding; the reference specifies a minimum of 20 and an encoded delay cap, which is not a confirmed request maximum. Use the guide range. |
| `svg` | object | - | - | optional author-selection object. Send only when SVG model selection is enabled; then supply `svg.model`. Optional `svg.reasoning.effort` uses the author's supported subset of `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. Otherwise omit `svg`. |

GIF requires preview access and cannot use streaming, partial images, masks, or custom compression. Use `size: "auto"` unless the model's GIF pixel limits are known. SVG generation requires `n: 1` and cannot use streaming, partial images, custom compression, or `prompt_rewriter`.

### Official documentation boundaries

The reference explicitly associates `xhigh`/`max` quality and custom static-image dimensions with earlier named models, without clearly listing 2.6. Do not infer 2.6 support from a cross-model enum. Examples use standard sizes and `medium` quality.

The edit reference lists SVG fields, but the guide says SVG output is not supported by the edit endpoint. Use the generation endpoint for SVG until this discrepancy is resolved. Do not send `response_format`, `style`, or unconfirmed `input_fidelity` settings for this model.


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