### Install ImagineoAI SDK Source: https://docs.imagineo.dev/docs/usage Instructions for installing the ImagineoAI JavaScript SDK using either bun or npm package managers. ```bash bun add @imagineoai/javascript-sdk # or npm install @imagineoai/javascript-sdk ``` -------------------------------- ### Basic Image Generation Source: https://docs.imagineo.dev/docs/usage Shows a basic example of generating an image with a prompt and specifying dimensions, using the default 'flux-dev' model, and logging the resulting image URL. ```javascript const result = await client.images.generate({ prompt: 'A beautiful sunset over mountains', model_type: 'flux-dev', // Optional, this is the default width: 1024, height: 1024 }); console.log(result.data.image_url); ``` -------------------------------- ### Browser: Image Upload and Generation Examples Source: https://docs.imagineo.dev/docs/usage Shows how to upload a file and generate images using various models like Flux Dev, OpenAI, Google Imagen4, WAN Image 2.1, WAN Image 2.2, and Qwen Image Edit, including consistent character image generation. ```javascript import { ImagineoAIClient, upload } from "@imagineoai/javascript"; const client = new ImagineoAIClient("https://api.imagineoai.com", { apiKey: "sk-..." }); // Upload an image const file = new File([/* ... */], "image.png"); const result = await client.images.upload({ file }); // Generate an image with Flux Dev model (default) const fluxResult = await client.images.generateRun({ prompt: 'A beautiful landscape', model_type: 'flux-dev' // Optional, this is the default }); // Generate an image with OpenAI model const openAIResult = await client.images.generateRun({ prompt: 'A stunning portrait', model_type: 'openai' }); // Generate an image with Google Imagen4 model const googleResult = await client.images.generateRun({ prompt: 'A futuristic city at sunset', model_type: 'google-imagen4', aspect_ratio: '16:9' // Required for Google Imagen4 }); // Generate with WAN Image 2.1 const wan21Result = await client.images.generateRun({ prompt: 'A magical forest', model_type: 'wan-image-2.1', strength_model: 1.5 }); // Generate with WAN Image 2.2 (dual LoRA) const wan22Result = await client.images.generateRun({ prompt: 'An epic battle scene', model_type: 'wan-image-2.2', lora_low_name: 'style-lora', lora_low_strength: 0.7, lora_high_name: 'detail-lora', lora_high_strength: 1.2 }); // Generate with Qwen Image Edit const qwenResult = await client.images.generate({ prompt: 'Transform into a cyberpunk scene with neon lights', model_type: 'qwen-image-edit', negative_prompt: 'daylight, nature, traditional', lora_1: 'cyberpunk-style-v2', strength_model: 1.5, width: 1024, height: 1024 }); // Generate consistent character images const characterResult = await client.images.character.json({ prompt: 'A brave warrior in a mystical forest', character_reference_image: 'https://example.com/character.jpg', style_type: 'Realistic', aspect_ratio: '16:9' }); ``` -------------------------------- ### Install ImagineoAI React SDK using Bun or NPM Source: https://docs.imagineo.dev/docs/react-sdk Installs the ImagineoAI React SDK and its JavaScript SDK peer dependency using either Bun or NPM package managers. ```bash bun add @imagineoai/react @imagineoai/javascript ``` ```bash npm install @imagineoai/react @imagineoai/javascript ``` -------------------------------- ### Initialize ImagineoAI Client Source: https://docs.imagineo.dev/docs/usage Demonstrates how to create an instance of the ImagineoAIClient, providing the API endpoint and an API key for authentication. ```javascript import { ImagineoAIClient } from '@imagineoai/javascript'; const client = new ImagineoAIClient('https://api.imagineoai.com', { apiKey: 'your-api-key' }); ``` -------------------------------- ### Monitoring Asynchronous Operations Source: https://docs.imagineo.dev/docs/usage Explains how to monitor the progress of asynchronous image operations using the `getRun` endpoint. ```APIDOC ## POST /api/images/edit/fluxKontext (Async) ### Description Initiates an asynchronous image editing operation and provides a `run_id` to monitor its progress. ### Method POST ### Endpoint /api/images/edit/fluxKontext ### Parameters #### Request Body - **original_run_id** (string) - Required - The ID of the original image generation run. - **prompt** (string) - Required - The prompt for editing the image. - **sync** (boolean) - Optional - Set to `false` for asynchronous operation. Defaults to `true`. ### Request Example ```json { "original_run_id": "run-id", "prompt": "Add snow to the mountains", "sync": false } ``` ## GET /api/runs/{run_id} ### Description Retrieves the status and progress of a specific run (e.g., image generation or edit). ### Method GET ### Endpoint /api/runs/{run_id} ### Parameters #### Path Parameters - **run_id** (string) - Required - The ID of the run to check. ### Response #### Success Response (200) - **data** (object) - Contains the run's status and progress information. - **live_status** (string) - The current status of the run (e.g., 'processing', 'completed', 'failed'). - **progress** (integer) - The completion progress percentage. - **image_url** (string) - The URL of the final image if the run is completed. #### Response Example ```json { "data": { "live_status": "completed", "progress": 100, "image_url": "https://example.com/final_image.png" } } ``` ``` -------------------------------- ### Synchronous vs Asynchronous Editing Source: https://docs.imagineo.dev/docs/usage Explains the difference between synchronous and asynchronous image editing operations and how to use them. ```APIDOC ## POST /api/images/edit/fluxKontext ### Description Provides options for synchronous (immediate results) and asynchronous (webhook/polling) image editing. ### Method POST ### Endpoint /api/images/edit/fluxKontext ### Parameters #### Request Body - **original_run_id** (string) - Required - The run ID of the original image generation. - **prompt** (string) - Required - The text prompt describing the desired edits. - **sync** (boolean) - Required - Set to `true` for synchronous, `false` (or omitted) for asynchronous. ### Request Example (Synchronous) ```json { "original_run_id": "run-id", "prompt": "Add a sunset sky", "sync": true } ``` ### Response Example (Synchronous) ```json { "run_id": "sync-run-id-789", "image_url": "http://example.com/sunset_image.png" } ``` ### Request Example (Asynchronous) ```json { "original_run_id": "run-id", "prompt": "Add a sunset sky", "sync": false } ``` ### Response Example (Asynchronous) ```json { "run_id": "async-run-id-012", "live_status": "processing" } ``` ``` -------------------------------- ### Update Prompt Example (JavaScript) Source: https://docs.imagineo.dev/docs/methods/prompts/updatePrompt Demonstrates how to call the updatePrompt method with a prompt ID and update payload. This example will currently throw an error as the method is not yet implemented. ```javascript await client.updatePrompt("prompt-id", { prompt: "new text" }); // Throws for now ``` -------------------------------- ### Enhance Prompt Example (Node.js) Source: https://docs.imagineo.dev/docs/methods/prompts/enhancePrompt Shows the usage of the `enhance` function within a Node.js application. Similar to the browser example, it initializes the client and calls the enhance method, logging the enhanced prompt upon successful execution. ```javascript const client = new ImagineoAIClient(apiUrl, { apiKey }); const result = await client.prompts.enhance({ prompt: "A cat riding a skateboard" }); if (result.success) { console.log(result.data.enhancedPrompt); } ``` -------------------------------- ### Character Generation with Ideogram (JavaScript) Source: https://docs.imagineo.dev/docs/usage This section provides multiple examples of generating consistent characters across different scenes using the Ideogram Character model. It covers using JSON with image URLs, FormData with file uploads (browser and Node.js buffers), and referencing previous run IDs. ```javascript // JSON method with URL reference const response = await client.images.character.json({ prompt: 'A hero standing tall in a castle courtyard', character_reference_image: 'https://example.com/my-character.jpg', rendering_speed: 'Quality', style_type: 'Realistic', aspect_ratio: '16:9', resolution: '2048' }); // FormData method with file upload (Browser) const fileInput = document.getElementById('character-file'); const file = fileInput.files[0]; const response = await client.images.character.formData({ prompt: 'The same character in a battle scene', character_reference_file: file, style_type: 'Fiction', magic_prompt_option: 'On' }); // FormData method with Buffer (Node.js) import fs from 'fs'; const characterBuffer = fs.readFileSync('./character-ref.png'); const response = await client.images.character.formData({ prompt: 'The character exploring a dungeon', character_reference_file: characterBuffer, rendering_speed: 'Turbo', seed: 42 }); // Use existing run as character reference const response = await client.images.character.json({ prompt: 'The character at a tavern', character_reference_run_id: 'previous-run-uuid', aspect_ratio: '1:1' }); ``` -------------------------------- ### Install ImagineoAI JavaScript Library Source: https://docs.imagineo.dev/docs/methods/method-gemini-25 Installs the ImagineoAI JavaScript library using package managers like npm, yarn, or bun. This library provides the client to interact with Gemini 2.5. ```bash npm install @imagineoai/javascript ``` ```bash yarn add @imagineoai/javascript ``` ```bash bun add @imagineoai/javascript ``` -------------------------------- ### API Key Authentication Example Source: https://docs.imagineo.dev/docs/auth Demonstrates how to initialize the ImagineoAIClient with an API key for authentication. This method is suitable for server-side applications but should not be exposed client-side in production. ```javascript const client = new ImagineoAIClient(apiUrl, { apiKey: "sk-..." }); ``` -------------------------------- ### Setup ImagineoAIProvider in React App Source: https://docs.imagineo.dev/docs/react-sdk-usage Wraps your application with ImagineoAIProvider to provide the ImagineoAI client via React context. Requires a getToken function for authentication and the API URL. getToken should return a promise resolving to the API token. ```javascript import { ImagineoAIProvider } from '@imagineoai/react'; function AppRoot() { return ( ); } ``` -------------------------------- ### Reproducible Generation using Seed Source: https://docs.imagineo.dev/docs/usage Demonstrates how to use the `seed` parameter to achieve consistent and reproducible image generation results. ```APIDOC ## POST /api/images/generate ### Description Generates an image based on a prompt, with options for model type and a seed for reproducibility. ### Method POST ### Endpoint /api/images/generate ### Parameters #### Query Parameters - **prompt** (string) - Required - The text prompt to generate an image from. - **model_type** (string) - Required - The type of model to use for generation (e.g., 'flux-kontext-max'). - **seed** (integer) - Optional - A seed value for reproducible results. ### Request Example ```json { "prompt": "A red apple", "model_type": "flux-kontext-max", "seed": 42 } ``` ### Response #### Success Response (200) - **data** (object) - Contains the generated image URL and other details. - **image_url** (string) - The URL of the generated image. #### Response Example ```json { "data": { "image_url": "https://example.com/image.png" } } ``` ``` -------------------------------- ### Upload an Image Source: https://docs.imagineo.dev/docs/usage Handles the upload of image files, typically from a web browser. ```APIDOC ## POST /api/images/upload ### Description Uploads an image file to the server. ### Method POST ### Endpoint /api/images/upload ### Parameters #### Request Body - **file** (file) - Required - The image file to upload. - **description** (string) - Optional - A description for the uploaded image. ### Request Example ```javascript // Assuming 'file' is a File object obtained from an input element // The client library will handle the FormData creation ``` ### Response #### Success Response (200) - **data** (object) - Contains details about the uploaded image. - **image_url** (string) - The URL of the uploaded image. ``` -------------------------------- ### Image Generation with OpenAI Source: https://docs.imagineo.dev/docs/usage Generates an image using the OpenAI model. Optionally accepts a reference image URL. ```APIDOC ## POST /api/images/generate ### Description Generates an image using a specified AI model and prompt. ### Method POST ### Endpoint /api/images/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt to guide image generation. - **model_type** (string) - Required - The type of model to use (e.g., "openai", "google-imagen4", "flux-kontext-max"). - **reference_image_url** (string) - Optional - A URL to a reference image. ### Request Example ```json { "prompt": "A serene landscape", "model_type": "openai", "reference_image_url": "https://example.com/reference.jpg" } ``` ### Response #### Success Response (200) - **data.image_url** (string) - The URL of the generated image. #### Response Example ```json { "data": { "image_url": "https://example.com/generated_image.jpg" } } ``` ``` -------------------------------- ### Get User Jobs using ImagineoAI Client Source: https://docs.imagineo.dev/docs/methods/user/method-getUserJobs Demonstrates how to fetch a list of completed jobs for a user using the ImagineoAI JavaScript client. It shows setting up the client with an API key and handling the response, including potential errors. ```javascript import { ImagineoAIClient } from "@imagineoai/javascript/browser"; // Or /server for Node.js const imagine = new ImagineoAIClient({ apiKey: "YOUR_API_KEY" }); async function main() { try { const jobsResponse = await imagine.me.getUserJobs({ status: "completed" }); console.log("User jobs:", jobsResponse.jobs); console.log("Total jobs:", jobsResponse.total); } catch (error) { console.error("Error fetching user jobs:", error); } } main(); ``` -------------------------------- ### Complete Image Generation with Nanobanana (JavaScript) Source: https://docs.imagineo.dev/docs/methods/method-nanobanana Provides comprehensive examples of image generation using the Nanobanana model. It covers both simple generation and generation with a reference image for style transfer. ```javascript import { ImagineoAIClient } from '@imagineoai/javascript'; const client = new ImagineoAIClient(apiUrl, { apiKey: process.env.IMAGINEOAI_API_KEY }); async function generateWithNanobanana() { try { // Simple generation const simple = await client.images.generate({ prompt: "A futuristic cityscape at night", model_type: "nanobanana" }); // With reference image const withReference = await client.images.generate({ prompt: "A futuristic cityscape at night", model_type: "nanobanana", reference_image_url: "https://example.com/style-reference.jpg" }); console.log("Generated images:", { simple, withReference }); } catch (error) { console.error("Generation failed:", error); } } ``` -------------------------------- ### getPrompt Example Usage Source: https://docs.imagineo.dev/docs/methods/prompts/getPrompt Demonstrates how to call the `getPrompt` method with a prompt ID. Note that this will currently throw an error as the method is not yet implemented. ```javascript await client.getPrompt("prompt-id"); // Throws for now ``` -------------------------------- ### Get User Runs with ImagineoAIClient Source: https://docs.imagineo.dev/docs/methods/user/method-getUserRuns Demonstrates how to fetch a list of user runs using the ImagineoAIClient. It shows how to instantiate the client, call the getUserRuns method with optional query parameters like limit, and handle the response or potential errors. The client can be imported for browser or Node.js environments. ```javascript import { ImagineoAIClient } from "@imagineoai/javascript/browser"; // Or /server for Node.js const imagine = new ImagineoAIClient({ apiKey: "YOUR_API_KEY" }); async function main() { try { const runsResponse = await imagine.me.getUserRuns({ limit: 10 }); console.log("User runs:", runsResponse.runs); console.log("Total runs:", runsResponse.total); } catch (error) { console.error("Error fetching user runs:", error); } } main(); ``` -------------------------------- ### Advanced WAN Generation with Custom Parameters Source: https://docs.imagineo.dev/docs/usage Generates an image using a fine-tuned model with the WAN workflow, allowing custom strength, guidance, and webhook configurations. ```APIDOC ## POST /api/images/generate ### Description Provides advanced control over fine-tuned model generation using the WAN workflow, including model strength, guidance scale, and optional webhooks. ### Method POST ### Endpoint /api/images/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt for generation. - **model_id** (string) - Required - The unique identifier for your fine-tuned model. - **workflow_type** (string) - Required - Must be set to "wan". - **width** (integer) - Optional - The desired width of the image. - **height** (integer) - Optional - The desired height of the image. - **strength_model** (number) - Optional - Controls the influence of the model (0-2, default: 1). - **model_weight** (number) - Optional - Adjusts the model's weight (0-1, default: 0.7). - **guidance** (number) - Optional - Sets the guidance scale (0-100, default: 7.5). - **webhook_url** (string) - Optional - A URL to receive asynchronous generation status updates. ### Request Example ```json { "prompt": "A detailed scene using my custom trained style", "model_id": "your-model-uuid", "workflow_type": "wan", "width": 1920, "height": 1088, "strength_model": 1.5, "model_weight": 0.8, "guidance": 8.0, "webhook_url": "https://your-webhook.com/endpoint" } ``` ### Response #### Success Response (200) - **data.run_id** (string) - The identifier for the generation run. #### Response Example ```json { "data": { "run_id": "run-abc123xyz" } } ``` ``` -------------------------------- ### Error Handling with try-catch Source: https://docs.imagineo.dev/docs/usage Illustrates how to implement error handling for SDK methods by wrapping the calls in a try-catch block to manage potential network, validation, or API errors. ```javascript try { await client.uploadImage({ file }); } catch (e) { // handle error } ``` -------------------------------- ### Edit Image with Custom Aspect Ratio Source: https://docs.imagineo.dev/docs/usage Demonstrates how to perform image edits with custom aspect ratios and control over synchronous or asynchronous execution. ```APIDOC ## POST /api/images/edit/fluxKontext ### Description Edits an existing image with specified aspect ratio, seed, and synchronization settings. ### Method POST ### Endpoint /api/images/edit/fluxKontext ### Parameters #### Request Body - **original_run_id** (string) - Required - The run ID of the original image generation. - **prompt** (string) - Required - The text prompt describing the desired edits. - **aspect_ratio** (string) - Required - The desired aspect ratio of the edited image (e.g., '1:1', '16:9'). - **seed** (integer) - Optional - A seed for reproducible results. - **sync** (boolean) - Optional - If true, the operation is synchronous and waits for completion. Defaults to false (asynchronous). ### Request Example ```json { "original_run_id": "your-original-run-id", "prompt": "Transform this into a cyberpunk scene with neon lights", "aspect_ratio": "1:1", "seed": 123, "sync": false } ``` ### Response #### Success Response (200) - **run_id** (string) - The ID of the edit operation. - **live_status** (string) - The current status of the operation. - **image_url** (string) - The URL of the edited image (if synchronous operation completes). ### Response Example ```json { "run_id": "edit-run-id-456", "live_status": "completed", "image_url": "http://example.com/edited_image.png" } ``` ``` -------------------------------- ### Generate Image with OpenAI Source: https://docs.imagineo.dev/docs/usage Generates an image using the OpenAI model. Requires a prompt and can optionally use a reference image URL. ```javascript const result = await client.images.generate({ prompt: 'A serene landscape', model_type: 'openai', reference_image_url: 'https://example.com/reference.jpg' // Optional }); console.log(result.data.image_url); ``` -------------------------------- ### Token-based Authentication Example (Clerk) Source: https://docs.imagineo.dev/docs/auth Shows how to initialize the ImagineoAIClient using a function that retrieves a token, such as from a service like Clerk. This is recommended for browser applications due to its more secure, short-lived token handling. ```javascript const client = new ImagineoAIClient(apiUrl, { getToken: async () => getClerkToken() }); ``` -------------------------------- ### Character Generation Source: https://docs.imagineo.dev/docs/usage Enables the generation of consistent character images across different scenes using a reference image or run ID. ```APIDOC ## POST /api/images/character ### Description Generates character images with consistency across multiple generations. ### Method POST ### Endpoint /api/images/character ### Parameters #### Request Body (JSON) - **prompt** (string) - Required - The text prompt for the character image. - **character_reference_image** (string) - Optional - URL of the character reference image. - **character_reference_file** (file) - Optional - File object of the character reference image (for FormData). - **character_reference_run_id** (string) - Optional - Run ID of a previous generation to use as character reference. - **rendering_speed** (string) - Optional - The rendering speed ('Quality' or 'Turbo'). - **style_type** (string) - Optional - The artistic style (e.g., 'Realistic', 'Fiction'). - **aspect_ratio** (string) - Optional - The desired aspect ratio (e.g., '16:9', '1:1'). - **resolution** (string) - Optional - The desired resolution (e.g., '2048'). - **seed** (integer) - Optional - A seed for reproducible results. - **magic_prompt_option** (string) - Optional - Enhances the prompt ('On' or 'Off'). ### Request Example (JSON with URL) ```json { "prompt": "A hero standing tall in a castle courtyard", "character_reference_image": "https://example.com/my-character.jpg", "rendering_speed": "Quality", "style_type": "Realistic", "aspect_ratio": "16:9", "resolution": "2048" } ``` ### Request Example (FormData with File Upload - Browser) ```javascript // Assuming 'file' is a File object obtained from an input element // The client library will handle the FormData creation ``` ### Request Example (FormData with Buffer - Node.js) ```javascript // Assuming 'characterBuffer' is a Buffer object from fs.readFileSync // The client library will handle the FormData creation ``` ### Request Example (JSON with Run ID) ```json { "prompt": "The character at a tavern", "character_reference_run_id": "previous-run-uuid", "aspect_ratio": "1:1" } ``` ### Response #### Success Response (200) - **run_id** (string) - The ID of the character generation operation. - **image_url** (string) - The URL of the generated character image. ``` -------------------------------- ### Image Generation with Flux Kontext Max Source: https://docs.imagineo.dev/docs/usage Generates an image using the Flux Kontext Max model. Supports aspect ratio and seed for reproducibility. ```APIDOC ## POST /api/images/generate ### Description Generates an image using the Flux Kontext Max model, allowing for aspect ratio and seed for reproducible results. ### Method POST ### Endpoint /api/images/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt to guide image generation. - **model_type** (string) - Required - Must be set to "flux-kontext-max". - **aspect_ratio** (string) - Optional - The desired aspect ratio of the image (e.g., "16:9"). - **seed** (integer) - Optional - A seed value for reproducible generations. ### Request Example ```json { "prompt": "A majestic dragon soaring through storm clouds at golden hour", "model_type": "flux-kontext-max", "aspect_ratio": "16:9", "seed": 42 } ``` ### Response #### Success Response (200) - **data.image_url** (string) - The URL of the generated image. #### Response Example ```json { "data": { "image_url": "https://example.com/generated_dragon.jpg" } } ``` ``` -------------------------------- ### Basic Fine-tuned Model Generation with WAN Workflow Source: https://docs.imagineo.dev/docs/usage Generates an image using a fine-tuned model via the WAN workflow. Requires a model ID. ```APIDOC ## POST /api/images/generate ### Description Generates an image using a fine-tuned model with the WAN workflow, optimized for custom models. ### Method POST ### Endpoint /api/images/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt for generation. - **model_id** (string) - Required - The unique identifier for your fine-tuned model. - **workflow_type** (string) - Required - Must be set to "wan". - **width** (integer) - Optional - The desired width of the image. - **height** (integer) - Optional - The desired height of the image. ### Request Example ```json { "prompt": "A portrait in the style of my fine-tuned model", "model_id": "your-model-uuid", "workflow_type": "wan", "width": 1920, "height": 1088 } ``` ### Response #### Success Response (200) - **data.image_url** (string) - The URL of the generated image. #### Response Example ```json { "data": { "image_url": "https://example.com/generated_fine_tuned.jpg" } } ``` ``` -------------------------------- ### Delete Prompt Example (JavaScript) Source: https://docs.imagineo.dev/docs/methods/prompts/deletePrompt Demonstrates how to call the deletePrompt method. Currently, this method is a stub and will throw an error indicating it's not implemented yet. ```javascript await client.deletePrompt("prompt-id"); // Throws for now ``` -------------------------------- ### Image Generation with Google Imagen4 Source: https://docs.imagineo.dev/docs/usage Generates an image using the Google Imagen4 model. Supports aspect ratio customization. ```APIDOC ## POST /api/images/generate ### Description Generates an image using the Google Imagen4 model, allowing for aspect ratio specification. ### Method POST ### Endpoint /api/images/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt to guide image generation. - **model_type** (string) - Required - Must be set to "google-imagen4". - **aspect_ratio** (string) - Optional - The desired aspect ratio of the image (e.g., "16:9"). ### Request Example ```json { "prompt": "A futuristic cityscape", "model_type": "google-imagen4", "aspect_ratio": "16:9" } ``` ### Response #### Success Response (200) - **data.image_url** (string) - The URL of the generated image. #### Response Example ```json { "data": { "image_url": "https://example.com/generated_cityscape.jpg" } } ``` ``` -------------------------------- ### Node.js: Image Upload Source: https://docs.imagineo.dev/docs/usage Demonstrates uploading an image file in a Node.js environment, using a file buffer. The SDK supports Buffer or Readable streams for uploads. ```javascript import { ImagineoAIClient, upload } from "@imagineoai/javascript/server"; import fs from "fs"; const client = new ImagineoAIClient("https://api.imagineoai.com", { apiKey: "sk-..." }); const buffer = fs.readFileSync("./image.png"); const result = await client.images.upload({ file: buffer }); ``` -------------------------------- ### Generate Image with Flux Kontext Max Source: https://docs.imagineo.dev/docs/usage Generates an image using the Flux Kontext Max model. Requires a prompt, aspect ratio, and supports a seed for reproducibility. ```javascript const result = await client.images.generate({ prompt: 'A majestic dragon soaring through storm clouds at golden hour', model_type: 'flux-kontext-max', aspect_ratio: '16:9', seed: 42 // For reproducible results }); console.log(result.data.image_url); ``` -------------------------------- ### Generate Image with Google Imagen4 Source: https://docs.imagineo.dev/docs/usage Generates an image using the Google Imagen4 model. Requires a prompt and supports specifying an aspect ratio. ```javascript const result = await client.images.generate({ prompt: 'A futuristic cityscape', model_type: 'google-imagen4', aspect_ratio: '16:9' }); console.log(result.data.image_url); ``` -------------------------------- ### Aspect Ratio Matching in Image Editing Source: https://docs.imagineo.dev/docs/usage Shows how to use `aspect_ratio: 'match_input_image'` during image editing to preserve the original image's aspect ratio. ```APIDOC ## POST /api/images/edit/fluxKontext ### Description Edits an existing image using the Flux Kontext model. Allows preserving the original aspect ratio by setting `aspect_ratio` to `match_input_image`. ### Method POST ### Endpoint /api/images/edit/fluxKontext ### Parameters #### Request Body - **original_run_id** (string) - Required - The ID of the original image generation run. - **prompt** (string) - Required - The prompt for editing the image. - **aspect_ratio** (string) - Optional - Set to 'match_input_image' to preserve the original aspect ratio. ### Request Example ```json { "original_run_id": "original-run-id", "prompt": "Change the lighting to golden hour", "aspect_ratio": "match_input_image" } ``` ### Response #### Success Response (200) - **data** (object) - Contains details about the edited image. - **run_id** (string) - The ID of this edit run. #### Response Example ```json { "data": { "run_id": "edit-run-id-123" } } ``` ``` -------------------------------- ### WAN Image 2.2 Dual LoRA Generation Source: https://docs.imagineo.dev/docs/usage Generates an image using the WAN Image 2.2 workflow, supporting dual LoRA models with independent strength controls. ```APIDOC ## POST /api/images/generate ### Description Enables advanced image generation by combining two LoRA models with independent strength controls using the WAN Image 2.2 workflow. ### Method POST ### Endpoint /api/images/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt for generation. - **model_id** (string) - Required - The unique identifier for your base model. - **workflow_type** (string) - Required - Must be set to "wan-image-2.2". - **width** (integer) - Optional - The desired width of the image. - **height** (integer) - Optional - The desired height of the image. - **lora_low_name** (string) - Required - The name/path of the first LoRA model. - **lora_low_strength** (number) - Optional - The strength for the first LoRA (0-2, default: 0.5). - **lora_high_name** (string) - Required - The name/path of the second LoRA model. - **lora_high_strength** (number) - Optional - The strength for the second LoRA (0-2, default: 1.0). - **batch_size** (integer) - Optional - Number of variations to generate. ### Request Example ```json { "prompt": "A professional fashion photograph with natural lighting", "model_id": "your-model-uuid", "workflow_type": "wan-image-2.2", "width": 1200, "height": 1500, "lora_low_name": "wan2.2/wan2.2-lora-instagirl-2.0/Instagirlv2.0_lownoise.safetensors", "lora_low_strength": 0.5, "lora_high_name": "wan2.2/wan2.2-lora-instagirl-2.0/Instagirlv2.0_hinoise.safetensors", "lora_high_strength": 1.0, "batch_size": 2 } ``` ### Response #### Success Response (200) - **data.image_url** (string) - The URL of the generated image. #### Response Example ```json { "data": { "image_url": "https://example.com/generated_dual_lora.jpg" } } ``` ### Error Handling - **Error**: If `lora_low_name` or `lora_high_name` are missing when `workflow_type` is `wan-image-2.2`. - **Message**: "WAN Image 2.2 workflow requires both lora_low_name and lora_high_name parameters" ``` -------------------------------- ### Browser: Mask Image from URLs Source: https://docs.imagineo.dev/docs/usage An example of how to mask an image by providing URLs for both the original image and the mask image. The result is a PNG blob usable in the browser or streamable in Node.js. ```javascript const pngBlob = await client.edit.maskImage( "https://example.com/original.png", "https://example.com/mask.png" ); // Use pngBlob in the browser, or stream in Node.js ``` -------------------------------- ### Generate Image with WAN Image 2.2 (JavaScript) Source: https://docs.imagineo.dev/docs/methods/method-wan-image-22 Generates an image using the WAN Image 2.2 workflow, requiring two LoRA models (`lora_low_name` and `lora_high_name`) and their respective strengths. This example demonstrates a basic setup for dual LoRA generation. ```javascript const result = await client.images.generate({ prompt: "A female model in vintage fashion, natural lighting", width: 1200, height: 1500, model_id: "your-model-uuid", model_type: "wan-image-2.2", lora_low_name: "wan2.2/wan2.2-lora-instagirl-2.0/Instagirlv2.0_lownoise.safetensors", // Required lora_low_strength: 0.5, lora_high_name: "wan2.2/wan2.2-lora-instagirl-2.0/Instagirlv2.0_hinoise.safetensors", // Required lora_high_strength: 1.0, batch_size: 1 }); console.log("Generated image:", result.image_url); ``` -------------------------------- ### Synchronous vs. Asynchronous Editing (JavaScript) Source: https://docs.imagineo.dev/docs/usage This example contrasts synchronous and asynchronous image editing operations. Synchronous editing waits for the process to complete and returns the result directly, while asynchronous editing returns immediately with a run ID, requiring subsequent polling or webhooks for completion. ```javascript // Synchronous - get results immediately (10-30 second wait) const syncEdit = await client.images.edit.fluxKontext.json({ original_run_id: 'run-id', prompt: 'Add a sunset sky', sync: true }); console.log('Done:', syncEdit.image_url); // Asynchronous - returns immediately, use webhooks/polling (default) const asyncEdit = await client.images.edit.fluxKontext.json({ original_run_id: 'run-id', prompt: 'Add a sunset sky', sync: false }); console.log('Started:', asyncEdit.run_id); ``` -------------------------------- ### Compare Default vs WAN Workflow for Image Generation Source: https://docs.imagineo.dev/docs/usage Compares the image generation using the default workflow versus the WAN workflow for fine-tuned models. Demonstrates differences in parameters like workflow type and strength. ```javascript // Default workflow - standard generation const defaultResult = await client.images.generate({ prompt: 'A landscape painting', model_id: 'your-model-uuid', workflow_type: 'default', // or omit (default) width: 1024, height: 1024 }); // WAN workflow - optimized for fine-tuned models const wanResult = await client.images.generate({ prompt: 'A landscape painting', model_id: 'your-model-uuid', workflow_type: 'wan', // Uses specialized deployment width: 1920, height: 1088, strength_model: 1.2 // Fine-tune the model influence }); ``` -------------------------------- ### Enhance Prompt Example (Browser) Source: https://docs.imagineo.dev/docs/methods/prompts/enhancePrompt Demonstrates how to use the `enhance` function in a browser environment. It initializes the client, calls the enhance method with a prompt, and logs either the enhanced prompt on success or error details on failure. ```javascript const client = new ImagineoAIClient(apiUrl, { apiKey }); const result = await client.prompts.enhance({ prompt: "A cat riding a skateboard" }); if (result.success) { console.log(result.data.enhancedPrompt); } else { console.error(result.message, result.code, result.details); } ``` -------------------------------- ### GET /users/me/jobs Source: https://docs.imagineo.dev/docs/methods/user/method-getUserJobs Retrieves a list of jobs for the authenticated user. Supports filtering by status and pagination. ```APIDOC ## GET /users/me/jobs ### Description Retrieves a list of jobs for the authenticated user. This endpoint allows for filtering by job status (e.g., 'completed', 'failed', 'pending') and pagination using limit and offset parameters. ### Method GET ### Endpoint /users/me/jobs ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of jobs to return. - **offset** (integer) - Optional - The number of jobs to skip before starting to collect the result set. - **status** (string) - Optional - Filters jobs by their status. Possible values include 'completed', 'failed', 'pending', etc. ### Request Example ```json { "limit": 10, "offset": 0, "status": "completed" } ``` ### Response #### Success Response (200) - **jobs** (array) - A list of job objects. - **total** (integer) - The total number of jobs available that match the query. - **limit** (integer) - The limit applied to the returned jobs. - **offset** (integer) - The offset applied to the returned jobs. #### Response Example ```json { "jobs": [ { "id": "job_123", "userId": "user_abc", "status": "completed", "createdAt": "2023-10-27T10:00:00Z", "completedAt": "2023-10-27T10:05:00Z" } ], "total": 50, "limit": 10, "offset": 0 } ``` ``` -------------------------------- ### Error Handling with try/catch Source: https://docs.imagineo.dev/docs/faq Implement robust error handling by wrapping your SDK operations within a `try...catch` block. Log any caught errors to assist in troubleshooting upload failures or other runtime problems. ```javascript try { // SDK operation that might fail await imagineo.upload(file); } catch (error) { console.error("Upload failed:", error); } ``` -------------------------------- ### GET /api/v1/edits/layers Source: https://docs.imagineo.dev/docs/methods/method-getLayers Fetches all layers associated with a given run ID. The run ID is passed as a query parameter. ```APIDOC ## GET /api/v1/edits/layers ### Description Fetches all layers associated with a given run ID. ### Method GET ### Endpoint /api/v1/edits/layers ### Parameters #### Query Parameters - **run_id** (string) - Required - ID of the run to fetch layers for. ### Response #### Success Response (200) - **data.layers** (Layer[]) - An array of Layer objects. #### Response Example ```json { "data": { "layers": [ { "id": "layer-123", "name": "Layer 1", "type": "mask" } ] } } ``` ``` -------------------------------- ### GET /users/runs Source: https://docs.imagineo.dev/docs/methods/user/method-getUserRuns Retrieves a list of runs for the authenticated user. Supports filtering by status, limiting results, and pagination. ```APIDOC ## GET /users/runs ### Description Retrieves a list of runs for the authenticated user. This endpoint allows for filtering by run status, limiting the number of returned runs, and specifying an offset for pagination. ### Method GET ### Endpoint /users/runs ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of runs to return. - **offset** (integer) - Optional - The number of runs to skip before returning results. - **status** (string) - Optional - Filters runs by their status (e.g., 'completed', 'failed'). ### Request Example ```javascript import { ImagineoAIClient } from "@imagineoai/javascript/browser"; const imagine = new ImagineoAIClient({ apiKey: "YOUR_API_KEY" }); async function fetchUserRuns() { try { const runsResponse = await imagine.me.getUserRuns({ limit: 10, status: "completed" }); console.log("User runs:", runsResponse.runs); console.log("Total runs:", runsResponse.total); } catch (error) { console.error("Error fetching user runs:", error); } } fetchUserRuns(); ``` ### Response #### Success Response (200) - **runs** (array) - An array of run objects. - **total** (integer) - The total number of runs available. #### Response Example ```json { "runs": [ { "id": "run_123", "status": "completed", "createdAt": "2023-10-27T10:00:00Z" }, { "id": "run_456", "status": "completed", "createdAt": "2023-10-26T09:00:00Z" } ], "total": 50 } ``` ``` -------------------------------- ### Initialize ImagineoAI Client and Generate/Edit Images (JavaScript) Source: https://docs.imagineo.dev/docs/index Demonstrates how to initialize the ImagineoAI JavaScript client with an API key and perform image generation and editing tasks. It showcases generating an image using the 'flux-kontext-max' model and then editing the generated image to add a rainbow. This requires the '@imagineoai/javascript' package. ```javascript import { ImagineoAIClient } from '@imagineoai/javascript'; const client = new ImagineoAIClient('https://api.imagineoai.com', { apiKey: 'your-api-key' }); // Generate with Flux Kontext Max const result = await client.images.generate({ prompt: 'A majestic mountain landscape', model_type: 'flux-kontext-max', aspect_ratio: '16:9' }); // Edit the generated image const edit = await client.images.edit.fluxKontext.json({ original_run_id: result.data.run_id, prompt: 'Add a rainbow over the mountains' }); ```