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

# Image Generation

> Generate images from text prompts

Generate high-quality images using the Titan Image Generator.

### Headers

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

### Query Parameters

<ParamField query="model" type="string" required>
  The ID of the model to use. Must be `titan` (Titan Image Generator G1 V2).
</ParamField>

### Body Parameters

<ParamField body="prompt" type="string" required>
  The text description of the image to generate.
</ParamField>

<ParamField body="size" type="string" default="1024x1024">
  The dimensions of the generated image. Supported values depend on the model (e.g., "1024x1024", "512x512").
</ParamField>

<ParamField body="n" type="integer" default="1">
  The number of images to generate.
  *Note: Tier limits apply (Starter: 3/day, Economy: 10/day, Pro: 25/day, Ultimate: 50/day).*
</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?model=titan" \
    -H "x-api-key: <api_key>" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "A futuristic city skyline at sunset",
      "size": "1024x1024",
      "n": 1
    }'
  ```

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

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

  params = {"model": "titan"}
  headers = {
      "x-api-key": "<api_key>",
      "Content-Type": "application/json"
  }
  data = {
      "prompt": "A futuristic city skyline at sunset",
      "size": "1024x1024",
      "n": 1
  }

  try:
      response = requests.post(url, params=params, 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}
  // For local development, use: http://localhost:3000/v1/generation/image
  const url = "https://apolloai.lol/v1/generation/image?model=titan";
  const headers = {
    "x-api-key": "<api_key>",
    "Content-Type": "application/json"
  };
  const body = JSON.stringify({
    prompt: "A futuristic city skyline at sunset",
    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
  	url := "https://apolloai.lol/v1/generation/image?model=titan"
  	var jsonStr = []byte(`{"prompt":"A futuristic city skyline at sunset", "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
          String url = "https://apolloai.lol/v1/generation/image?model=titan";
          String json = "{\"prompt\":\"A futuristic city skyline at sunset\", \"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?model=titan")

  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 at sunset",
    "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?model=titan");
      
      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 at sunset\", \"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?model=titan")
          .header("x-api-key", "<api_key>")
          .header("Content-Type", "application/json")
          .json(&json!({
              "prompt": "A futuristic city skyline at sunset",
              "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": "Model 'llama3' does not support image generation. Please use 'Titan Image Generator'."
  }
  ```

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

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