### Generate Images with ImageRouter API Source: https://docs.imagerouter.io/index This snippet demonstrates how to generate images using the ImageRouter API's OpenAI-compatible endpoint. It requires an API key for bearer token authentication and specifies the desired prompt and model within the JSON request body. The examples show how to make a POST request and handle the JSON response. ```Curl curl 'https://api.imagerouter.io/v1/openai/images/generations' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ --data-raw '{"prompt": "YOUR_PROMPT", "model": "test/test"}' ``` ```Javascript const url = 'https://api.imagerouter.io/v1/openai/images/generations'; const options = { method: 'POST', headers: {Authorization: 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'}, body: '{"prompt": "YOUR_PROMPT", "model": "test/test"}' }; const response = await fetch(url, options); const data = await response.json(); console.log(data); ``` ```Python import requests url = "https://api.imagerouter.io/v1/openai/images/generations" payload = { "prompt": "YOUR_PROMPT", "model": "test/test" } headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` -------------------------------- ### Generate Image with Open WebUI Plugin Source: https://docs.imagerouter.io/integrations/open-webui-plugin Example of a text prompt used to generate an image through the ImageRouter plugin in Open WebUI. The plugin processes the latest message for image generation. ```Prompt A cozy wooden cabin in a snowy forest at sunset, ultra-realistic ``` -------------------------------- ### Get Available Models from ImageRouter API Source: https://docs.imagerouter.io/api-reference/models These code examples demonstrate how to retrieve a list of all models currently available on the ImageRouter platform using a simple GET request to the /v1/models endpoint. The response will be a JSON object containing the model details. ```Curl curl 'https://api.imagerouter.io/v1/models' ``` ```Javascript const url = 'https://api.imagerouter.io/v1/models'; const options = {method: 'GET'}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```Python import requests url = "https://api.imagerouter.io/v1/models" response = requests.get(url) print(response.json()) ``` -------------------------------- ### Generate Video via ImageRouter API Source: https://docs.imagerouter.io/api-reference/video-generation Demonstrates how to make a POST request to the ImageRouter API's experimental video generation endpoint. This operation requires an API key for authorization and a JSON payload containing the text `prompt` and the `model` identifier. Note that other parameters are currently defaulted and ignored. ```Curl curl 'https://api.imagerouter.io/v1/openai/videos/generations' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ --data-raw '{"prompt": "YOUR_PROMPT", "model": "ir/test-video"}' ``` ```Javascript const url = 'https://api.imagerouter.io/v1/openai/videos/generations'; const options = { method: 'POST', headers: {Authorization: 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'}, body: '{"prompt": "YOUR_PROMPT", "model": "ir/test-video"}' }; const response = await fetch(url, options); const data = await response.json(); console.log(data); ``` ```Python import requests url = "https://api.imagerouter.io/v1/openai/videos/generations" payload = { "prompt": "YOUR_PROMPT", "model": "ir/test-video" } headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` -------------------------------- ### Image Generation API Parameters Source: https://docs.imagerouter.io/api-reference/image-generation Detailed documentation for the parameters accepted by the ImageRouter API's image generation endpoint. This includes required parameters like `prompt` and `model`, and optional parameters such as `quality` and `response_format`. ```APIDOC prompt*: Text prompt for generating images. model*: Image model to use for generation. quality: [auto, low, medium, high] - default “auto”; Supported models have “quality” feature label. response_format: [url, b64_json] - default “url”. ``` -------------------------------- ### ImageRouter Video Generation API Endpoint Details Source: https://docs.imagerouter.io/api-reference/video-generation This section outlines the request parameters for the ImageRouter video generation API endpoint. It specifies the required inputs and notes the current default values for other parameters that are not yet configurable. ```APIDOC Endpoint: POST /v1/openai/videos/generations Parameters: prompt*: string Description: Text prompt for generating video. model*: string Description: Video model to use. Note: Currently, every other parameter is ignored & defaulted (aspectRatio=16:9, personGeneration=allow_adult, numberOfVideos=1, durationSeconds=5) for simplicity. These will be added in the future. ``` -------------------------------- ### Generate Images via ImageRouter API Source: https://docs.imagerouter.io/api-reference/image-generation This snippet demonstrates how to make a POST request to the ImageRouter API's image generation endpoint. It requires an API key for authorization and a JSON payload specifying the prompt and model. The API supports various models and allows customization of quality and response format. ```Curl curl 'https://api.imagerouter.io/v1/openai/images/generations' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ --data-raw '{"prompt": "YOUR_PROMPT", "model": "test/test"}' ``` ```Javascript const url = 'https://api.imagerouter.io/v1/openai/images/generations'; const options = { method: 'POST', headers: {Authorization: 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'}, body: '{"prompt": "YOUR_PROMPT", "model": "test/test"}' }; const response = await fetch(url, options); const data = await response.json(); console.log(data); ``` ```Python import requests url = "https://api.imagerouter.io/v1/openai/images/generations" payload = { "prompt": "YOUR_PROMPT", "model": "test/test" } headers = { "Authorization": "Bearer YOUR_API_KEY", "Content": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` -------------------------------- ### Image Edits API POST Parameters Reference Source: https://docs.imagerouter.io/api-reference/image-edits This section details the required and optional parameters for the ImageRouter Image Edits API endpoint. It specifies the purpose, type, and constraints for each parameter, including `prompt`, `model`, `image[]`, `mask[]`, `quality`, and `response_format`. ```APIDOC POST /v1/openai/images/edits Parameters: - prompt (string, required): Text prompt for editing the image. - model (string, required): Model to use for image editing. Select from models that has “edit” label on them. - image[] (file array, required): Image files to be edited. Different models support different quantity of input images (usually 1 to 16). - mask[] (file, optional): Some models require a mask file to specify areas to edit. - quality (enum: auto, low, medium, high, optional): default “auto”; Supported models have “quality” feature label. - response_format (enum: url, b64_json, optional): default “url”. Notes: - Currently, `size` is not supported. ``` -------------------------------- ### Perform Image Edits via ImageRouter API Source: https://docs.imagerouter.io/api-reference/image-edits This snippet demonstrates how to send a POST request to the ImageRouter API's image edits endpoint. It requires an API key, a text prompt, a model name, and one or more image files. An optional mask file can also be provided for specific models. The API returns the edited image data. ```Curl curl -X POST "https://api.imagerouter.io/v1/openai/images/edits" \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "prompt=YOUR_PROMPT" \ -F "model=openai/gpt-image-1" \ -F "image[]=@your_image1.webp" \ -F "image[]=@your_image2.webp" \ -F "mask[]=@your_mask.webp" ``` ```Javascript const formData = new FormData() formData.append('prompt', 'YOUR_PROMPT') formData.append('model', 'openai/gpt-image-1') // Add your image files (up to 16) const imageFile1 = await fetch('your_image1.webp').then(r => r.blob()) formData.append('image[]', imageFile1) // or from local file const imagePath = '/home/phoenics/projects/Image router/materials/logo.png' const imageBuffer = fs.readFileSync(imagePath) const imageBlob = new Blob([imageBuffer], { type: 'image/png' }) formData.append('image[]', imageBlob, path.basename(imagePath)) // Add mask file - some models support/require it //const maskFile = await fetch('your_mask.webp').then(r => r.blob()) //formData.append('mask[]', maskFile) const response = await fetch('https://api.imagerouter.io/v1/openai/images/edits', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY' }, body: formData }) const data = await response.json() console.log(data) ``` ```Python import requests url = "https://api.imagerouter.io/v1/openai/images/edits" headers = { "Authorization": "Bearer YOUR_API_KEY" } files = { "image[]": [ open("your_image1.webp", "rb"), open("your_image2.webp", "rb") ], "mask[]": open("your_mask.webp", "rb") } payload = { "prompt": "YOUR_PROMPT", "model": "openai/gpt-image-1", } response = requests.post(url, files=files, data=payload, headers=headers) print(response.json()) ``` -------------------------------- ### ImageRouter API Rate Limits Specification Source: https://docs.imagerouter.io/rate-limits This specification outlines the rate limits applied to the ImageRouter API, detailing the maximum number of requests allowed per second for general API calls and per minute for image generation requests. These limits are in place to ensure fair usage and prevent system abuse. ```APIDOC Rate Limits: General API: Limit: 100 requests per second Image Generation: Limit: 30 requests per minute ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.