### Get Media Image - Go Example Source: https://platform.pixai.art/en/docs/api/media/getMediaImage Go program to retrieve media image data. This example demonstrates making a GET request to the API. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { mediaId := "YOUR_MEDIA_ID" url := fmt.Sprintf("https://platform.pixai.art/api/media/getMediaImage?mediaId=%s", mediaId) resp, err := http.Get(url) if err != nil { fmt.Printf("Error making request: %s\n", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Printf("Status Code: %d\n", resp.StatusCode) fmt.Printf("Response Body: %s\n", string(body)) } ``` -------------------------------- ### Get Media Image - Python Example Source: https://platform.pixai.art/en/docs/api/media/getMediaImage Python script to fetch media image data. It handles the request and prints the response. ```python import requests media_id = "YOUR_MEDIA_ID" url = f"https://platform.pixai.art/api/media/getMediaImage?mediaId={media_id}" headers = { 'accept': 'application/json' } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes data = response.json() print(data) except requests.exceptions.RequestException as e: print(f"Error fetching media image: {e}") ``` -------------------------------- ### Get Task Request Examples Source: https://platform.pixai.art/en/docs/api/task/getTask Examples of how to call the Get Task API using various programming languages. Remember to include the authentication header in your requests. ```curl curl -X GET "https://platform.pixai.art/api/task/getTask?id=65d302103137110012345678" \ -H "Authorization: Bearer YOUR_API_KEY" ``` ```js const taskId = "65d302103137110012345678"; fetch(`https://platform.pixai.art/api/task/getTask?id=${taskId}`, { method: "GET", headers: { "Authorization": "Bearer YOUR_API_KEY" } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error("Error:", error)); ``` ```go package main import ( "fmt" "io/ioutil" "net/http" ) func main() { taskId := "65d302103137110012345678" url := fmt.Sprintf("https://platform.pixai.art/api/task/getTask?id=%s", taskId) client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("Authorization", "Bearer YOUR_API_KEY") res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` ```python import requests task_id = "65d302103137110012345678" url = f"https://platform.pixai.art/api/task/getTask?id={task_id}" headers = { "Authorization": "Bearer YOUR_API_KEY" } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") print(response.text) ``` ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GetTask { public static void main(String[] args) throws IOException, InterruptedException { String taskId = "65d302103137110012345678"; String url = "https://platform.pixai.art/api/task/getTask?id=" + taskId; HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Authorization", "Bearer YOUR_API_KEY") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class GetTaskExample { public static async Task Main(string[] args) { string taskId = "65d302103137110012345678"; string url = $"https://platform.pixai.art/api/task/getTask?id={taskId}"; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY"); HttpResponseMessage response = await client.GetAsync(url); if (response.IsSuccessStatusCode) { string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } else { Console.WriteLine($"Error: {response.StatusCode}"); } } } } ``` -------------------------------- ### Get Media by ID (Java) Source: https://platform.pixai.art/en/docs/api/media/getMedia Example of fetching media details in Java using standard HTTP client. Ensure to replace {media_id} with the actual ID. ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GetMedia { public static void main(String[] args) { HttpClient client = HttpClient.newHttpClient(); String mediaId = "your_media_id_here"; // Replace with actual media ID HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://platform.pixai.art/api/media/" + mediaId)) .GET() .build(); try { HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("Status Code: " + response.statusCode()); System.out.println("Response Body: " + response.body()); } catch (IOException | InterruptedException e) { e.printStackTrace(); } } } ``` -------------------------------- ### Create Image Request Examples Source: https://platform.pixai.art/en/docs/api-v2/image/createImage Examples of how to call the createImage endpoint using different programming languages and tools. Includes cURL, JavaScript, Go, Python, Java, C#, and Bash. ```curl curl -X POST https://api.pixai.art/v2/image/create \ -H "Authorization: Bearer $PIXAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard" }' ``` ```javascript const response = await fetch("https://api.pixai.art/v2/image/create", { method: "POST", headers: { "Authorization": `Bearer ${PIXAI_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard", }), }); const task = await response.json(); console.log(task); ``` ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.pixai.art/v2/image/create" payload := map[string]string{ "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard", } jsonData, err := json.Marshal(payload) if err != nil { fmt.Println("Error marshalling JSON:", err) return } req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Authorization", "Bearer $PIXAI_API_KEY") req.Header.Set("Content-Type", "application/json") client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() var task map[string]interface{} if err := json.NewDecoder(resp.Body).Decode(&task); err != nil { fmt.Println("Error decoding response:", err) return } fmt.Println(task) } ``` ```python import requests response = requests.post( "https://api.pixai.art/v2/image/create", headers={ "Authorization": f"Bearer {PIXAI_API_KEY}", "Content-Type": "application/json", }, json={ "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard", }, ) task = response.json() print(task) ``` ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class CreateImage { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); String jsonPayload = "{\"modelVersionId\":\"1983308862240288769\",\"prompt\":\"1girl, green hair, solo, standing\",\"aspectRatio\":\"9:16\",\"mode\":\"standard\"}"; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.pixai.art/v2/image/create")) .header("Authorization", "Bearer $PIXAI_API_KEY") .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonPayload)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` ```csharp using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; public class CreateImageClient { public static async Task Main(string[] args) { using (var client = new HttpClient()) { var requestData = new { modelVersionId = "1983308862240288769", prompt = "1girl, green hair, solo, standing", aspectRatio = "9:16", mode = "standard" }; var json = System.Text.Json.JsonSerializer.Serialize(requestData); var content = new StringContent(json, Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "$PIXAI_API_KEY"); var response = await client.PostAsync("https://api.pixai.art/v2/image/create", content); var responseString = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseString); } } } ``` ```bash curl -X POST https://api.pixai.art/v2/image/create \ -H "Authorization: Bearer $PIXAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard" }' ``` ```javascript const response = await fetch("https://api.pixai.art/v2/image/create", { method: "POST", headers: { "Authorization": `Bearer ${PIXAI_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard", }), }); const task = await response.json(); console.log(task); ``` -------------------------------- ### Get Task Detail by ID Response (200 OK) Source: https://platform.pixai.art/en/docs/api/task/getTask Example JSON response for a successfully retrieved task. Includes task ID, status, timestamps, and output media details. ```json { "id": "string", "status": "waiting", "createdAt": "2019-08-24T14:15:22Z", "updatedAt": "2019-08-24T14:15:22Z", "startedAt": "2019-08-24T14:15:22Z", "endAt": "2019-08-24T14:15:22Z", "outputs": { "mediaIds": [ "string" ], "mediaUrls": [ "string" ] } } ``` -------------------------------- ### Get Media by ID cURL Example Source: https://platform.pixai.art/en/docs/api/media/getMedia Example of how to call the 'Get media by ID' API endpoint using cURL. ```curl curl -X GET "https://api.pixai.art/v1/media/string" ``` -------------------------------- ### Get Media Image - Java Example Source: https://platform.pixai.art/en/docs/api/media/getMediaImage Java code snippet for fetching media image data using Apache HttpClient. Replace 'YOUR_MEDIA_ID' with the actual media ID. ```java import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class GetMediaImage { public static void main(String[] args) { String mediaId = "YOUR_MEDIA_ID"; String url = "https://platform.pixai.art/api/media/getMediaImage?mediaId=" + mediaId; try (CloseableHttpClient client = HttpClients.createDefault()) { HttpGet request = new HttpGet(url); request.addHeader("accept", "application/json"); org.apache.http.client.ResponseHandler responseHandler = response -> { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { return EntityUtils.toString(response.getEntity()); } else { throw new org.apache.http.client.HttpResponseException(status, response.getStatusLine().getReasonPhrase()); } }; String responseBody = client.execute(request, responseHandler); System.out.println("Response Body: " + responseBody); } catch (Exception e) { System.err.println("Error fetching media image: " + e.getMessage()); } } } ``` -------------------------------- ### Get Media Image - C# Example Source: https://platform.pixai.art/en/docs/api/media/getMediaImage C# code to retrieve media image data using HttpClient. Remember to replace 'YOUR_MEDIA_ID' with the actual media ID. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class GetMediaImageClient { public static async Task GetMediaImageAsync(string mediaId) { using (HttpClient client = new HttpClient()) { string url = $"https://platform.pixai.art/api/media/getMediaImage?mediaId={mediaId}"; client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); try { HttpResponseMessage response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); // Throw an exception if the status code is not successful string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } catch (HttpRequestException e) { Console.WriteLine($"Error fetching media image: {e.Message}"); } } } public static void Main(string[] args) { string mediaId = "YOUR_MEDIA_ID"; GetMediaImageAsync(mediaId).Wait(); } } ``` -------------------------------- ### Get Task Detail by ID (cURL) Source: https://platform.pixai.art/en/docs/api/task/getTask Example of how to retrieve task details using cURL. Replace 'string' with the actual task ID. ```shell curl -X GET "https://api.pixai.art/v1/task/string" ``` -------------------------------- ### Get Media Image - cURL Example Source: https://platform.pixai.art/en/docs/api/media/getMediaImage Use this cURL command to fetch media image data. Replace 'YOUR_MEDIA_ID' with the actual media ID. ```bash curl -X GET "https://platform.pixai.art/api/media/getMediaImage?mediaId=YOUR_MEDIA_ID" \ -H "accept: application/json" ``` -------------------------------- ### Get Media Image - JavaScript Example Source: https://platform.pixai.art/en/docs/api/media/getMediaImage JavaScript code to fetch media image data using the fetch API. Ensure you replace 'YOUR_MEDIA_ID' with the correct ID. ```javascript fetch(`https://platform.pixai.art/api/media/getMediaImage?mediaId=YOUR_MEDIA_ID`, { method: 'GET', headers: { 'accept': 'application/json' } }) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then(data => { console.log(data); }) .catch(error => { console.error('Error fetching media image:', error); }); ``` -------------------------------- ### Get Media by ID (Python) Source: https://platform.pixai.art/en/docs/api/media/getMedia Use Python's requests library to get media details. The {media_id} should be substituted with the target media's ID. ```python import requests media_id = "your_media_id_here" url = f"https://platform.pixai.art/api/media/{media_id}" response = requests.get(url) if response.status_code == 200: print(response.json()) elif response.status_code == 404: print("Media not found") else: print(f"An error occurred: {response.status_code}") ``` -------------------------------- ### Example API Response Structure Source: https://platform.pixai.art/en/docs/quick-start/first-api-call This is an example of the JSON response you might receive when checking the status of a task. It details the task's ID, status, creation and update times, and output media. ```json { "id": "TASK_ID", "status": "waiting", "createdAt": "2026-03-04T04:32:10.635Z", "updatedAt": "2026-03-04T04:32:10.635Z", "outputs": {}, "mediaIds": [], "mediaUrls": [] } ``` -------------------------------- ### Get Media by ID (Go) Source: https://platform.pixai.art/en/docs/api/media/getMedia Retrieve media information using Go's net/http package. Replace {media_id} with the actual media ID. ```go package main import ( "fmt" "net/http" ) func main() { url := "https://platform.pixai.art/api/media/{media_id}" resp, err := http.Get(url) if err != nil { fmt.Println("Error making request:", err) return } defer resp.Body.Close() // Process the response body here fmt.Println("Status Code:", resp.StatusCode) } ``` -------------------------------- ### Create Image Request Example Source: https://platform.pixai.art/en/docs/api-v2/image/createImage This snippet demonstrates how to construct a request to the createImage API. It includes setting headers and the JSON body with parameters for image generation. ```javascript fetch("/api/v2/image/createImage", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ modelVersionId: "1983308862240288769", prompt: "1girl, green hair, solo, standing", aspectRatio: "9:16", mode: "standard", }), }); const task = await response.json(); console.log(task); ``` -------------------------------- ### Empty Request Body Example Source: https://platform.pixai.art/en/docs/api-v2/image/createImage An example of an empty request body for the createImage API. This might be used for default generation settings or testing. ```json {} ``` -------------------------------- ### Create Image Generation Task (JavaScript Fetch) Source: https://platform.pixai.art/en/docs/api-v2/image/createImage This JavaScript fetch example demonstrates how to programmatically create an image generation task via the /v2/image/create API endpoint. It shows how to structure the request body with necessary parameters. ```javascript fetch("https://api.pixai.art/v2/image/create", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard" }) }).then(response => response.json()).then(data => console.log(data)); ``` -------------------------------- ### Get Media by ID Not Found Response (404) Source: https://platform.pixai.art/en/docs/api/media/getMedia Indicates that the media with the specified ID was not found. ```json Empty ``` -------------------------------- ### Get Media by ID (C#) Source: https://platform.pixai.art/en/docs/api/media/getMedia Retrieve media details using C#'s HttpClient. The {media_id} placeholder must be replaced with the specific media identifier. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class MediaApiClient { private static readonly HttpClient client = new HttpClient(); public static async Task GetMediaAsync(string mediaId) { string url = $"https://platform.pixai.art/api/media/{mediaId}"; try { HttpResponseMessage response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); // Throws if status code is not 2xx string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } catch (HttpRequestException e) { Console.WriteLine($"Request error: {e.Message}"); if (e.StatusCode == System.Net.HttpStatusCode.NotFound) { Console.WriteLine("Media not found."); } } } // Example usage: // public static async Task Main(string[] args) // { // await GetMediaAsync("your_media_id_here"); // } } ``` -------------------------------- ### LoRA Model ID and Version ID Example Source: https://platform.pixai.art/en/docs/api-v2/image/createImage Illustrates how to find and use the LoRA model ID and version ID from a PixAI URL. This is crucial for applying specific LoRA adapters to image generation. ```text https://pixai.art/model// → LoRA version ID is ``` -------------------------------- ### Bearer Token Authentication Example Source: https://platform.pixai.art/en/docs/api-v2/image/createImage This snippet shows how to include a Bearer token in the Authorization header for API requests. Ensure your token is valid. ```javascript Authorization: Bearer YOUR_API_TOKEN ``` -------------------------------- ### Get Media by ID (JavaScript) Source: https://platform.pixai.art/en/docs/api/media/getMedia Fetch media details using JavaScript's fetch API. Ensure the media_id is correctly formatted. ```javascript fetch("https://platform.pixai.art/api/media/{media_id}") .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { console.log(data); }) .catch(error => { console.error('There was a problem with the fetch operation:', error); }); ``` -------------------------------- ### Create an image generation task Source: https://platform.pixai.art/llms.txt Starts a new image generation task using the v2 API. This endpoint offers simplified parameters like aspectRatio, mode, and named style presets. ```APIDOC ## POST /v2/image/createImage ### Description Initiates an image generation task with simplified parameters. ### Method POST ### Endpoint /v2/image/createImage ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt to guide image generation. - **aspectRatio** (string) - Optional - The desired aspect ratio for the generated image (e.g., "16:9"). - **mode** (string) - Optional - The generation mode (e.g., "realistic", "anime"). - **style** (string) - Optional - A named style preset for the image generation. ``` -------------------------------- ### Webhook Reference Source: https://platform.pixai.art/en/docs/faq Information about setting up webhooks for asynchronous notification of task completion. ```APIDOC ## POST /en/docs/references/webhook ### Description Webhook for async notification. ### Method POST ### Endpoint /en/docs/references/webhook ### Parameters #### Request Body - **url** (string) - Required - The URL to receive webhook notifications. - **type** (string) - Optional - The type of notification (e.g., "task_completion"). ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Webhook configured successfully." } ``` ``` -------------------------------- ### Prompt Helper Options Source: https://platform.pixai.art/en/docs/api-v2/image/createImage Demonstrates the options for the prompt helper, which can automatically enhance prompts before image generation. Use 'enable' for automatic enhancement or 'disable' to use the prompt as-is. ```text "prompt_helper": "enable" ``` ```text "prompt_helper": "disable" ``` -------------------------------- ### Get Media by ID API Endpoint Source: https://platform.pixai.art/en/docs/api/media/getMedia This endpoint retrieves media information by its ID. It uses the GET HTTP method. ```http GET /media/{mediaId} ``` -------------------------------- ### Create Image (v2 API) Source: https://platform.pixai.art/en/docs/faq Starts a new image generation using the simplified v2 API. This API offers user-friendly parameters like `aspectRatio`, `mode`, and named `style` presets, replacing the raw pixel dimensions and internal parameter names of v1. ```APIDOC ## POST /en/docs/api-v2/image/createImage ### Description Starts a new image generation using the simplified v2 API. ### Method POST ### Endpoint /en/docs/api-v2/image/createImage ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt for image generation. - **aspectRatio** (string) - Optional - The desired aspect ratio for the image (e.g., "16:9"). - **mode** (string) - Optional - The generation mode (e.g., "anime", "realistic"). - **style** (string) - Optional - A named style preset for the image generation. - **negativePrompt** (string) - Optional - A prompt describing elements to exclude from the image. - **seed** (integer) - Optional - The seed for reproducible generation. - **cfgScale** (number) - Optional - Controls how strongly the prompt influences the image. - **steps** (integer) - Optional - The number of diffusion steps. - **modelId** (string) - Optional - The ID of the model to use for generation. - **sampler** (string) - Optional - The sampler to use for diffusion. - **styleRaw** (string) - Optional - Raw style parameters. - **quality** (number) - Optional - The quality setting for the generation. - **sizeTier** (string) - Optional - The size tier for the image. - **webhookUrl** (string) - Optional - URL for asynchronous notification upon task completion. - **webhookType** (string) - Optional - Type of webhook notification. ### Request Example ```json { "prompt": "A majestic dragon soaring through the clouds", "aspectRatio": "16:9", "mode": "fantasy", "style": "cinematic", "negativePrompt": "ugly, deformed, blurry", "seed": 12345, "cfgScale": 7, "steps": 30, "modelId": "stable-diffusion-xl-1024-v1.0", "sampler": "euler_a", "quality": 1, "sizeTier": "large", "webhookUrl": "https://example.com/webhook" } ``` ### Response #### Success Response (200) - **taskId** (string) - The ID of the generated task. #### Response Example ```json { "taskId": "task_abc123xyz789" } ``` ``` -------------------------------- ### Create Generation Task Source: https://platform.pixai.art/en/docs/api-v2/image/createImage Start to generate a new image using the simplified v2 API. The v2 API provides a streamlined interface with user-friendly parameters such as `aspectRatio`, `mode`, and named `style` presets, replacing the raw pixel dimensions and internal parameter names of v1. ```APIDOC ## POST /api/v2/image/createImage ### Description Start to generate a new image using the simplified v2 API. The v2 API provides a streamlined interface with user-friendly parameters such as `aspectRatio`, `mode`, and named `style` presets, replacing the raw pixel dimensions and internal parameter names of v1. ### Method POST ### Endpoint /api/v2/image/createImage ### Parameters #### Query Parameters - **aspectRatio** (string) - Optional - The desired aspect ratio for the generated image (e.g., "16:9", "1:1"). - **mode** (string) - Optional - The generation mode (e.g., "default", "creative"). - **style** (string) - Optional - A named style preset for the image generation (e.g., "photorealistic", "anime"). ### Request Example ```json { "prompt": "A futuristic cityscape at sunset", "aspectRatio": "16:9", "mode": "creative", "style": "cinematic" } ``` ### Response #### Success Response (200) - **taskId** (string) - The ID of the created generation task. - **status** (string) - The initial status of the task. #### Response Example ```json { "taskId": "gen_task_12345abcde", "status": "pending" } ``` ``` -------------------------------- ### Get Media Image by ID API Endpoint Source: https://platform.pixai.art/en/docs/api/media/getMediaImage This is the cURL command to make a GET request to the PixAI API to retrieve a media image. Replace 'string' with the actual media ID. ```cURL curl -X GET "https://api.pixai.art/v1/media/string/image" ``` -------------------------------- ### Submit a Task Source: https://platform.pixai.art/en/docs/quick-start/first-api-call Send a POST request to the /image/create endpoint to initiate image generation. Required fields include modelVersionId and prompt. The response contains a TASK_ID for subsequent polling. ```APIDOC ## POST /image/create ### Description Initiates image generation by submitting a task with specified model and prompt. ### Method POST ### Endpoint https://api.pixai.art/v2/image/create ### Parameters #### Request Body - **modelVersionId** (string) - Required - The ID of the model version to use. - **prompt** (string) - Required - The text prompt for image generation. - **aspectRatio** (string) - Optional - The desired aspect ratio of the image (e.g., "9:16"). - **mode** (string) - Optional - The generation mode (e.g., "standard"). ### Request Example ```json { "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, masterpiece, best quality, solo, standing, flower", "aspectRatio": "9:16", "mode": "standard" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the submitted task (TASK_ID). - **status** (string) - The initial status of the task (e.g., "waiting"). - **createdAt** (string) - The timestamp when the task was created. - **updatedAt** (string) - The timestamp when the task was last updated. - **outputs** (object) - An object containing media details. - **mediaIds** (array) - An array of media IDs (initially empty). - **mediaUrls** (array) - An array of media URLs (initially empty). #### Response Example ```json { "id": "TASK_ID", "status": "waiting", "createdAt": "2026-03-04T04:32:10.635Z", "updatedAt": "2026-03-04T04:32:10.635Z", "outputs": { "mediaIds": [], "mediaUrls": [] } } ``` ``` -------------------------------- ### Get media by ID Source: https://platform.pixai.art/llms.txt Retrieves media information associated with a specific ID. ```APIDOC ## GET /api/media/{mediaId} ### Description Fetches media details using its unique identifier. ### Method GET ### Endpoint /api/media/{mediaId} ### Parameters #### Path Parameters - **mediaId** (string) - Required - The unique identifier of the media. ``` -------------------------------- ### Get media image by ID Source: https://platform.pixai.art/llms.txt Retrieves the image data associated with a specific media ID. ```APIDOC ## GET /api/media/getMediaImage/{mediaId} ### Description Fetches the image content for a given media ID. ### Method GET ### Endpoint /api/media/getMediaImage/{mediaId} ### Parameters #### Path Parameters - **mediaId** (string) - Required - The unique identifier of the media. ``` -------------------------------- ### POST /image/create Source: https://platform.pixai.art/en/docs/api-v2/image/createImage Generates an image based on the provided prompt and model version. Users can specify generation parameters like aspect ratio, mode, and apply various artistic presets. ```APIDOC ## POST /image/create ### Description Generates an image based on the provided prompt and model version. Users can specify generation parameters like aspect ratio, mode, and apply various artistic presets. ### Method POST ### Endpoint /image/create ### Parameters #### Request Body - **modelVersionId** (string) - Required - The unique identifier for the model version to use for generation. Preferred replacement for the deprecated `modelId` field. - **modelId** (string) - Optional - Deprecated. Please use `modelVersionId` instead. This field expects a model version ID. - **prompt** (string) - Required - The text prompt to guide image generation. - **aspectRatio** (string) - Optional - The desired aspect ratio for the generated image (e.g., "9:16"). - **mode** (string) - Optional - The generation mode (e.g., "standard"). - **preset** (string) - Optional - An artistic preset to apply to the generation. Available presets include: - `anime-watercolor-impasto` (Watercolor Glow) - `art-crayon` (Art Crayon) - `bold-line-soft-color` (Glint & Gloom) - `chibi` (Chibi) - `classic-japanese` (Classic Anime) - `clean-flat-illustration` (Clean Flat-Illustration) - `colored-pencil-grain` (Chromatic Pencil) - `cool-warm-oil-contrast` (Seasonal Glow) - `desaturated-cool` (Cool Softlight) - `flat-anime-pastel` (Pastel Flat) - `glossy-glass-anime` (Glassy Anime) - `grey-blocks-lineless` (Grey Wash) - `hard-line-monochrome-accent` (Sharp Ink) - `high-contrast-retro-vivid` (Neon Vivid) - `holographic` (Hyper Pop) - `korean-style` (Polished Manhwa) - `lineart-watercolor-airy` (Luminous Wash) - `low-saturation-expressive-eyes` (Muted & Transparent) - `lucid-dreamy` (Lucid Dreamy) - `luminous-retro-impasto` (Luminous Impasto) - `minimal-flat-color` (Minimal Flat) - `modern-oil-glamour` (Modern Glam Anime) - `moe-pastel` (Moe Pastel) - `oil-watercolor-blend` (Water-Infused Oil) - `painterly-doodle` (Tender Brushstroke) - `paper-watercolor` (Soft Aqueous) - `pencil-sketch` (Pencil Sketch) - `poster-graffiti` (Neon Poster) - `retro-comic-fusion` (Retro Fusion) - `retro-oil-glamour` (Retro Glam Anime) - `retro-tv-anime` (90s Retro-Cell) - `semi-realistic` (Semi-Real) - `stable-vaporwave` (Neon Vaporwave) - `tinted-sketch` (Tinted Sketch) - `vintage-collage` (Vintage Collage) ### Request Example ```json { "modelVersionId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "aspectRatio": "9:16", "mode": "standard" } ``` ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Get Media by ID Success Response (200) Source: https://platform.pixai.art/en/docs/api/media/getMedia The structure of the response body when media is successfully retrieved. ```json { "id": "string", "type": "string", "urls": [ { "variant": "string", "url": "string" } ], "width": 0, "height": 0 } ``` -------------------------------- ### Get Media by ID (cURL) Source: https://platform.pixai.art/en/docs/api/media/getMedia Use this snippet to fetch media details by its unique identifier using cURL. ```bash curl -X GET "https://platform.pixai.art/api/media/{media_id}" ``` -------------------------------- ### Get task detail by ID Source: https://platform.pixai.art/llms.txt Retrieves the details of a specific image generation task using its unique ID. ```APIDOC ## GET /api/task/{taskId} ### Description Returns the details of a single image generation task identified by its ID. ### Method GET ### Endpoint /api/task/{taskId} ### Parameters #### Path Parameters - **taskId** (string) - Required - The unique identifier of the task. ``` -------------------------------- ### Get Task Source: https://platform.pixai.art/en/docs/api/task/getTask Retrieves the details of a specific task by its ID. This includes the task's status, timestamps, and any generated media. ```APIDOC ## GET /task/{taskId} ### Description Retrieves the details of a specific task by its ID. This includes the task's status, timestamps, and any generated media. ### Method GET ### Endpoint /task/{taskId} ### Parameters #### Path Parameters - **taskId** (string) - Required - The unique identifier for the task. ### Response #### Success Response (200) - **id** (string) - The unique identifier for the task. - **status** (string) - The status of the task. - **createdAt** (string) - The time the task was created. - **updatedAt** (string) - The time the task was last updated. - **startedAt** (string) - The time the task was started. - **finishedAt** (string) - The time the task was finished. - **output** (array) - The outputs of the task. - **mediaIds** (array) - The media IDs generated by the task. You can use these IDs to fetch detailed information about the generated media. The images you generate are usually not permanently retained. You need to retrieve your images as soon as possible. - **id** (string) - The unique identifier for the media. - **url** (string) - The public URL of the images generated by the task. The images you generate are usually not permanently retained. You need to retrieve your images as soon as possible. If an image is not available, it MAY be replaced by null in the array. #### Response Example (200) { "id": "string", "status": "string", "createdAt": "string", "updatedAt": "string", "startedAt": "string", "finishedAt": "string", "output": [ { "mediaIds": [ { "id": "string", "url": "string" } ] } ] } #### Error Response (404) - **message** (string) - Task not found. ``` -------------------------------- ### Get Task by ID Source: https://platform.pixai.art/en/docs/api/task/getTask Retrieves details for a specific task using its unique ID. Requires an API key for authentication. ```HTTP GET /task/{taskId} ``` -------------------------------- ### Get Model Version ID Source: https://platform.pixai.art/en/docs/quick-start/first-api-call Find the modelVersionId from the model version URL on PixAI. The last segment of the URL is the modelVersionId. ```text https://pixai.art/model// ``` -------------------------------- ### Authentication Header Source: https://platform.pixai.art/en/docs/api/task/getTask Demonstrates how to include the API key in the Authorization header for authenticated requests. ```HTTP Authorization: Bearer API-Key ``` -------------------------------- ### Get Media Source: https://platform.pixai.art/en/docs/api/media/getMedia Retrieves information about a specific media asset. This endpoint is useful for fetching details such as the media type, available URLs, and dimensions. ```APIDOC ## GET /media/{id} ### Description Retrieves details of a specific media asset. ### Method GET ### Endpoint /media/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the media asset. ### Response #### Success Response (200) - **id** (string) - The unique identifier of the media asset. - **type** (string) - The type of the media asset (e.g., 'image', 'video'). - **urls** (array) - A list of URLs for the media asset, each with a 'variant' and 'url'. - **variant** (string) - The variant of the URL (e.g., 'thumbnail', 'original'). - **url** (string) - The actual URL of the media asset. - **width** (integer) - Optional - The width of the media asset in pixels. - **height** (integer) - Optional - The height of the media asset in pixels. #### Response Example ```json { "id": "media-123", "type": "image", "urls": [ { "variant": "thumbnail", "url": "https://example.com/thumbnails/media-123.jpg" }, { "variant": "original", "url": "https://example.com/originals/media-123.jpg" } ], "width": 1920, "height": 1080 } ``` ``` -------------------------------- ### Create Image Source: https://platform.pixai.art/en/docs/api-v2/image/createImage Generates an image based on the provided prompt and configuration. This endpoint supports various models and allows for fine-tuning of the output through parameters like aspect ratio, size, mode, and style. ```APIDOC ## POST /v2/image/create ### Description Generates an image based on the provided prompt and configuration. This endpoint supports various models and allows for fine-tuning of the output through parameters like aspect ratio, size, mode, and style. ### Method POST ### Endpoint `/v2/image/create` ### Parameters #### Request Body - **modelId** (string) - Required - The ID of the model to use for generation. Example: `1983308862240288769` - **prompt** (string) - Required - The main prompt describing the content you want to generate. Example: `1girl, green hair, solo, standing` - **negativePrompt** (string) - Optional - Text describing elements to avoid in the generated image. Example: `nsfw, lowres, bad anatomy` - **aspectRatio** (string) - Optional - The aspect ratio of the generated image. Defaults to `1:1`. Available ratios: `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `3:5`, `5:3`, `9:16`, `16:9`, `1:3`, `3:1` - **size** (string) - Optional - The output resolution tier. Defaults to `1k`. Available tiers: `1k`, `1.5k` - **mode** (string) - Optional - The inference profile controlling generation quality and speed. Defaults to `standard`. Available modes: `lite`, `standard`, `pro`, `ultra` - **style** (object) - Optional - The style to apply during image generation. Can be a named preset or a custom style string. - **type** (string) - Required - Type of style. Can be `preset` or `custom`. - **key** (string) - Required if type is `preset` - The key of the preset style. Example: `anime-watercolor-impasto` - **custom** (string) - Required if type is `custom` - A raw style prompt string. - **loras** (array) - Optional - Apply one or more LoRA adapters to fine-tune output style or content. Up to 5 LoRAs can be combined. - **modelId** (string) - Required - The model ID of the LoRA adapter. - **weight** (number) - Optional - The weight of the LoRA adapter. Defaults to 1. ### Request Example ```json { "modelId": "1983308862240288769", "prompt": "1girl, green hair, solo, standing", "negativePrompt": "nsfw, lowres, bad anatomy", "aspectRatio": "1:1", "size": "1k", "mode": "standard", "style": { "type": "preset", "key": "anime-watercolor-impasto" }, "loras": [ { "modelId": "1234567890123456789", "weight": 0.8 } ] } ``` ### Response #### Success Response (200) - **images** (array) - An array of generated image URLs. - **id** (string) - The ID of the generation job. #### Response Example ```json { "images": [ "https://pixai.art/images/generated/example1.png", "https://pixai.art/images/generated/example2.png" ], "id": "job-abcdef123456" } ``` ``` -------------------------------- ### Get Task Information Source: https://platform.pixai.art/en/docs/api/task/getTask Retrieves the status and details of a specific task using its unique identifier. This endpoint is useful for monitoring the progress of asynchronous operations. ```APIDOC ## GET /tasks/{taskId} ### Description Retrieves the status and details of a specific task using its unique identifier. ### Method GET ### Endpoint /tasks/{taskId} ### Parameters #### Path Parameters - **taskId** (string) - Required - The unique identifier for the task. ### Response #### Success Response (200) - **id** (string) - The unique identifier for the task. - **status** (string) - The status of the task. Possible values: 'waiting', 'running', 'completed', 'cancelled', 'failed'. - **createdAt** (string) - The time the task was created. (date-time format) - **updatedAt** (string) - The time the task was last updated. (date-time format) - **startedAt** (string) - The time the task was started. (date-time format, optional) - **endAt** (string) - The time the task was finished. (date-time format, optional) - **outputs** (object) - The outputs of the task. (optional) - **mediaIds** (string[]) - The media IDs generated by the task. (optional) - **mediaUrls** (string | null)[]) - The public URLs of the images generated by the task. (optional) #### Response Example ```json { "id": "task_12345", "status": "completed", "createdAt": "2023-10-27T10:00:00Z", "updatedAt": "2023-10-27T10:05:00Z", "startedAt": "2023-10-27T10:01:00Z", "endAt": "2023-10-27T10:05:00Z", "outputs": { "mediaIds": ["media_abc", "media_def"], "mediaUrls": ["https://example.com/image1.png", "https://example.com/image2.png"] } } ``` ```