> ## 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.

# Image Edit

export const OpenAIApiResponse = ({successJson, successTitle = "200 - Success", streaming = false}) => {
  const error400 = `{
    "error": {
        "code": "invalid_params",
        "message": "parameter 'ARGUMENT' is required",
        "param": null,
        "type": "invalid_request_error"
    }
}`;
  const error401 = `{
    "error": {
        "code": "auth_invalid",
        "message": "Invalid API Key",
        "param": null,
        "type": "authentication_error"
    }
}`;
  const error402 = `{
    "error": {
        "code": "insufficient_quota",
        "message": "You exceeded your current quota, please check your plan and billing details.",
        "param": null,
        "type": "insufficient_quota_error"
    }
}`;
  const error403 = `{
    "error": {
        "code": "permission_error",
        "message": "You have no permission to access the model.",
        "type": "permission_error",
        "param": null
    }
}`;
  const error404 = `{
    "error": {
        "code": "invalid_request_error",
        "message": "Invalid URL",
        "param": null,
        "type": "invalid_request_error"
    }
}`;
  const error429 = `{
    "error": {
        "code": "rate_limit_exceeded",
        "message": "Rate limit reached",
        "param": null,
        "type": "rate_limit_error"
    }
}`;
  const error500 = `{
    "error": {
        "code": "server_error",
        "message": "Internal server error",
        "param": null,
        "type": "server_error"
    }
}`;
  return <>
      <h2>Response Examples</h2>

      <CodeGroup>
        <CodeBlock language={streaming ? "text" : "json"} filename={streaming ? "200 - Streaming Response (SSE)" : successTitle}>
          {successJson}
        </CodeBlock>
        <CodeBlock language="json" filename="400 - Bad Request">
          {error400}
        </CodeBlock>
        <CodeBlock language="json" filename="401 - Unauthorized">
          {error401}
        </CodeBlock>
        <CodeBlock language="json" filename="402 - Insufficient Balance">
          {error402}
        </CodeBlock>
        <CodeBlock language="json" filename="403 - Permission Denied">
          {error403}
        </CodeBlock>
        <CodeBlock language="json" filename="404 - Invalid URL">
          {error404}
        </CodeBlock>
        <CodeBlock language="json" filename="429 - Too Many Requests">
          {error429}
        </CodeBlock>
        <CodeBlock language="json" filename="500 - Internal Server Error">
          {error500}
        </CodeBlock>
      </CodeGroup>
    </>;
};

export const OpenAIImageEdit = ({model}) => {
  const curlExample = `curl --location 'https://aiandgpu.com/v1/images/edits' \\
--header 'Authorization: Bearer <YOUR_API_KEY>' \\
--form 'model="${model}"' \\
--form 'image[]=@"/path/to/file"' \\
--form 'prompt="put a red hat on the role's head"'`;
  const pythonExample = `import requests

url = "https://aiandgpu.com/v1/images/edits"

with open("/path/to/file", "rb") as image_file:
    files = {"image[]": image_file}
    data = {
        "model": "${model}",
        "prompt": "put a red hat on the role's head",
    }
    headers = {"Authorization": "Bearer <YOUR_API_KEY>"}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())`;
  const jsExample = `const fs = require("fs");

const form = new FormData();
form.append("model", "${model}");
form.append("image[]", fs.createReadStream("/path/to/file"));
form.append("prompt", "put a red hat on the role's head");

const response = await fetch("https://aiandgpu.com/v1/images/edits", {
  method: "POST",
  headers: {
    Authorization: "Bearer <YOUR_API_KEY>",
    ...form.getHeaders(),
  },
  body: form,
});

const data = await response.json();
console.log(data);`;
  const goExample = `package main

import (
\t"bytes"
\t"fmt"
\t"io"
\t"mime/multipart"
\t"net/http"
\t"os"
\t"path/filepath"
)

func main() {
\tvar buf bytes.Buffer
\twriter := multipart.NewWriter(&buf)

\twriter.WriteField("model", "${model}")
\twriter.WriteField("prompt", "put a red hat on the role's head")

\tfile, _ := os.Open("/path/to/file")
\tdefer file.Close()
\tpart, _ := writer.CreateFormFile("image[]", filepath.Base("/path/to/file"))
\tio.Copy(part, file)
\twriter.Close()

\treq, _ := http.NewRequest("POST", "https://aiandgpu.com/v1/images/edits", &buf)
\treq.Header.Set("Authorization", "Bearer <YOUR_API_KEY>")
\treq.Header.Set("Content-Type", writer.FormDataContentType())

\tres, _ := http.DefaultClient.Do(req)
\tdefer res.Body.Close()
\tbody, _ := io.ReadAll(res.Body)
\tfmt.Println(string(body))
}`;
  const javaExample = `import okhttp3.*;
import java.io.*;

OkHttpClient client = new OkHttpClient();

RequestBody body = new MultipartBody.Builder()
    .setType(MultipartBody.FORM)
    .addFormDataPart("model", "${model}")
    .addFormDataPart("prompt", "put a red hat on the role's head")
    .addFormDataPart("image[]", "image.png",
        RequestBody.create(new File("/path/to/file"), MediaType.parse("image/png")))
    .build();

Request request = new Request.Builder()
    .url("https://aiandgpu.com/v1/images/edits")
    .header("Authorization", "Bearer <YOUR_API_KEY>")
    .post(body)
    .build();

try (Response response = client.newCall(request).execute()) {
    System.out.println(response.body().string());
}`;
  const phpExample = `<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://aiandgpu.com/v1/images/edits",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => [
        "model" => "${model}",
        "prompt" => "put a red hat on the role's head",
        "image[]" => new CURLFile("/path/to/file"),
    ],
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer <YOUR_API_KEY>",
    ],
]);

$response = curl_exec($curl);
curl_close($curl);

echo $response;`;
  const csharpExample = `using System.Net.Http;

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer <YOUR_API_KEY>");

var form = new MultipartFormDataContent();
form.Add(new StringContent("${model}"), "model");
form.Add(new StringContent("put a red hat on the role's head"), "prompt");

var fileBytes = await File.ReadAllBytesAsync("/path/to/file");
form.Add(new ByteArrayContent(fileBytes), "image[]", "file");

var response = await client.PostAsync("https://aiandgpu.com/v1/images/edits", form);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);`;
  return <>
            <h2>Request Examples</h2>

            <CodeGroup>
                <CodeBlock language="shellscript" filename="cURL">
                    {curlExample}
                </CodeBlock>
                <CodeBlock language="python" filename="Python">
                    {pythonExample}
                </CodeBlock>
                <CodeBlock language="javascript" filename="JavaScript">
                    {jsExample}
                </CodeBlock>
                <CodeBlock language="go" filename="Go">
                    {goExample}
                </CodeBlock>
                <CodeBlock language="java" filename="Java">
                    {javaExample}
                </CodeBlock>
                <CodeBlock language="php" filename="PHP">
                    {phpExample}
                </CodeBlock>
                <CodeBlock language="csharp" filename="C#">
                    {csharpExample}
                </CodeBlock>
            </CodeGroup>
        </>;
};

## 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 <strong>API Key</strong> is your <a href="https://developer.aiandgpu.com" target="_blank" rel="noopener noreferrer">AGCloud API KEY</a>

<OpenAIImageEdit model="gpt-image-2" />

<OpenAIApiResponse
  successJson={`{
"created": 1777262313,
"data": [
    {
        "url": "https://agcloud-gateway-1401727014.cos.accelerate.myqcloud.com/image/2026/04/27/48f554af-0d54-445a-be1a-1ac5d5b8cf64.png"
    }
],
"usage": {
    "input_tokens": 777,
    "input_tokens_details": {
        "image_tokens": 765,
        "text_tokens": 12
    },
    "output_tokens": 765,
    "total_tokens": 1542
}
}`}
/>

## Request Parameters

| Field                | Type    | Required | Default | Description                                                                                                                                                                                                                                                                    |
| :------------------- | :------ | :------- | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`              | string  | ✅        | -       | The model identifier to use for this request, e.g. `git-image-2`.                                                                                                                                                                                                              |
| `prompt`             | string  | ✅        | -       | A text description of the desired image edit.                                                                                                                                                                                                                                  |
| `image`              | file    | ✅        | -       | 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    | -        | -       | An additional image whose fully transparent areas indicate where the image should be edited.                                                                                                                                                                                   |
| `input_fidelity`     | file    | -        | -       | 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 | -        | 1       | The number of images to generate. Must be between 1 and 10.                                                                                                                                                                                                                    |
| `size`               | string  | -        | auto    | 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  | -        | auto    | The quality of the generated images. One of auto, low, medium, or high. Defaults to auto. Not supported by -plus suffixed models.                                                                                                                                              |
| `background`         | string  | -        | auto    | 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  | -        | auto    | Content moderation level for generated images. low is less restrictive, auto is the default.                                                                                                                                                                                   |
| `output_format`      | string  | -        | auto    | The output format of the generated image(s). Defaults to auto. jpeg is faster than png for latency-sensitive scenarios.                                                                                                                                                        |
| `output_compression` | string  | -        | 100     | The compression level (0-100%) for the output image. Only applicable with webp or jpeg format. Defaults to 100.                                                                                                                                                                |
| `stream`             | string  | -        | false   | Whether to stream the response in real-time. When enabled, partial images can be received during generation.                                                                                                                                                                   |
| `partial_images`     | string  | -        | -       | 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  | -        | -       | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.                                                                                                                                                                             |
