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

# Edit Image

> Edit existing images using inpainting or variation

Modify an image based on a text prompt. You can perform inpainting (if a mask is provided) or generate variations of the input image.

### Headers

<ParamField header="x-api-key" type="string" required>
  Your Apollo AI API key.
</ParamField>

### Body Parameters

<ParamField body="prompt" type="string" required>
  The text description of the desired edit or variation.
</ParamField>

<ParamField body="image" type="string" required>
  Base64 encoded string of the source image.
</ParamField>

<ParamField body="mask" type="string">
  Base64 encoded string of the mask image (for inpainting). White pixels indicate areas to modify. If omitted, the request is treated as an image variation.
</ParamField>

<ParamField body="size" type="string" default="1024x1024">
  The dimensions of the generated image. Supported values: "1024x1024", "512x512".
</ParamField>

<ParamField body="n" type="integer" default="1">
  The number of variation images to generate.
</ParamField>

### Response

<ResponseField name="created" type="integer">
  Timestamp of generation.
</ResponseField>

<ResponseField name="data" type="array">
  Array of objects containing the image data.

  <Expandable title="Item">
    <ResponseField name="b64_json" type="string">
      The Base64 encoded image data.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash Curl theme={null}
  curl -X POST "https://apolloai.lol/v1/generation/image/edit" \
    -H "x-api-key: <api_key>" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "A futuristic city skyline with flying cars",
      "image": "<base64_image_data>",
      "mask": "<base64_mask_data>",
      "size": "1024x1024",
      "n": 1
    }'
  ```

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

  # For local development, use: http://localhost:3000/v1/generation/image/edit
  url = "https://apolloai.lol/v1/generation/image/edit"

  headers = {
      "x-api-key": "<api_key>",
      "Content-Type": "application/json"
  }
  data = {
      "prompt": "A futuristic city skyline with flying cars",
      "image": "<base64_image_data>",
      "mask": "<base64_mask_data>", 
      "size": "1024x1024",
      "n": 1
  }

  try:
      response = requests.post(url, headers=headers, json=data)
      response.raise_for_status()
      print(response.json())
  except requests.exceptions.HTTPError as err:
      print(f"HTTP Error: {err}")
      print(f"Response Body: {response.text}")
  except Exception as err:
      print(f"Error: {err}")
  ```

  ```javascript JavaScript theme={null}
  const url = "https://apolloai.lol/v1/generation/image/edit";
  const headers = {
    "x-api-key": "<api_key>",
    "Content-Type": "application/json"
  };
  const body = JSON.stringify({
    prompt: "A futuristic city skyline with flying cars",
    image: "<base64_image_data>",
    mask: "<base64_mask_data>",
    size: "1024x1024",
    n: 1
  });

  fetch(url, { method: "POST", headers, body })
    .then(async response => {
      if (!response.ok) {
          const text = await response.text();
          throw new Error(`HTTP error! status: ${response.status}, body: ${text}`);
      }
      return response.json();
    })
    .then(console.log)
    .catch(console.error);
  ```

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

  import (
  	"bytes"
  	"fmt"
  	"net/http"
      "io/ioutil"
  )

  func main() {
      // For local development, use: http://localhost:3000/v1/generation/image/edit
  	url := "https://apolloai.lol/v1/generation/image/edit"
  	var jsonStr = []byte(`{
          "prompt":"A futuristic city skyline with flying cars", 
          "image":"<base64_image_data>", 
          "mask":"<base64_mask_data>",
          "size":"1024x1024", 
          "n": 1
      }`)
  	req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
  	req.Header.Set("x-api-key", "<api_key>")
  	req.Header.Set("Content-Type", "application/json")

  	client := &http.Client{}
  	resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()
      
      body, _ := ioutil.ReadAll(resp.Body)
      
      if resp.StatusCode >= 400 {
          fmt.Printf("Error (Status %d): %s\n", resp.StatusCode, string(body))
      } else {
          fmt.Println(string(body))
      }
  }
  ```

  ```java Java theme={null}
  import java.net.URI;
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.http.HttpResponse.BodyHandlers;

  public class Main {
      public static void main(String[] args) throws Exception {
          // For local development, use: http://localhost:3000/v1/generation/image/edit
          String url = "https://apolloai.lol/v1/generation/image/edit";
          String json = "{\"prompt\":\"A futuristic city skyline with flying cars\", \"image\":\"<base64_image_data>\", \"mask\":\"<base64_mask_data>\", \"size\":\"1024x1024\", \"n\": 1}";

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create(url))
              .header("x-api-key", "<api_key>")
              .header("Content-Type", "application/json")
              .POST(HttpRequest.BodyPublishers.ofString(json))
              .build();

          client.sendAsync(request, BodyHandlers.ofString())
              .thenAccept(response -> {
                  if (response.statusCode() >= 400) {
                      System.out.println("Error (Status " + response.statusCode() + "): " + response.body());
                  } else {
                      System.out.println(response.body());
                  }
              })
              .join();
      }
  }
  ```

  ```ruby Ruby theme={null}
  require 'uri'
  require 'net/http'
  require 'json'

  url = URI("https://apolloai.lol/v1/generation/image/edit")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(url)
  request["x-api-key"] = "<api_key>"
  request["Content-Type"] = "application/json"
  request.body = JSON.dump({
    "prompt": "A futuristic city skyline with flying cars",
    "image": "<base64_image_data>",
    "mask": "<base64_mask_data>",
    "size": "1024x1024",
    "n": 1
  })

  response = http.request(request)
  puts response.read_body
  ```

  ```c C theme={null}
  #include <stdio.h>
  #include <curl/curl.h>

  int main(void) {
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
      curl_easy_setopt(curl, CURLOPT_URL, "https://apolloai.lol/v1/generation/image/edit");
      
      struct curl_slist *headers = NULL;
      headers = curl_slist_append(headers, "x-api-key: <api_key>");
      headers = curl_slist_append(headers, "Content-Type: application/json");
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

      const char *data = "{\"prompt\":\"A futuristic city skyline with flying cars\", \"image\":\"<base64_image_data>\", \"mask\":\"<base64_mask_data>\", \"size\":\"1024x1024\", \"n\": 1}";
      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);

      res = curl_easy_perform(curl);
      
      curl_slist_free_all(headers);
      curl_easy_cleanup(curl);
    }
    return 0;
  }
  ```

  ```rust Rust theme={null}
  use reqwest::Client;
  use serde_json::json;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Client::new();
      let res = client.post("https://apolloai.lol/v1/generation/image/edit")
          .header("x-api-key", "<api_key>")
          .header("Content-Type", "application/json")
          .json(&json!({
              "prompt": "A futuristic city skyline with flying cars",
              "image": "<base64_image_data>",
              "mask": "<base64_mask_data>",
              "size": "1024x1024",
              "n": 1
          }))
          .send()
          .await?;

      let body = res.text().await?;
      println!("{}", body);
      Ok(())
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "created": 1706859322,
    "data": [
      {
        "b64_json": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
      }
    ]
  }
  ```

  ```json 400 Bad Request theme={null}
  {
    "error": "Image is required for editing."
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": "Invalid API Key."
  }
  ```

  ```json 429 Too Many Requests theme={null}
  {
    "error": "Daily quota exceeded."
  }
  ```
</ResponseExample>
