Overview
The Media API provides endpoints for generating images and videos, listing existing media, and uploading your own media files. It supports various models and providers, with intelligent routing to select the most appropriate provider based on your requirements.
Unified Media Generation
MythIQ's Media API provides a single interface to access multiple AI models and providers, simplifying the process of generating and managing media content.
Endpoints
Model-specific parameters
Each model may support additional parameters beyond those listed here. For model-specific parameters, please refer to the Models page and select the specific model you're interested in.
/v1/media
List media items with filtering and pagination options.
Query Parameters
Parameter | Type | Description |
---|---|---|
limit | integer | Maximum number of items to return (default: 25, max: 100) |
page | integer | Page number for pagination (default: 0) |
user | string | Filter by user ID or 'me' for current user |
media | string | Filter by media type (e.g., 'image', 'video') |
size | string | Filter by size (e.g., '1024x1024') |
model | string | Filter by model ID or 'base/slug' format |
provider | string | Filter by provider ID or slug |
search | string | Search in prompt text |
sort | string | Sort order: 'newest' (default) or 'oldest' |
Response
{
"result": {
"total": 42,
"medias": [
{
"id": "abc123",
"url": "https://cdn.example.com/user/abc123/main.jpg",
"mime": "image/jpeg",
"user": "user123",
"media": "image",
"model": "stability/sdxl",
"provider": "stability",
"prompt": "A beautiful sunset over the ocean",
"size": "1024x1024",
"createdAt": "2025-03-25T12:00:00Z",
"modelSlug": "stability/sdxl:1.0",
"providerName": "Stability AI"
},
// More media items...
]
},
"success": true
}
/v1/images/generations
Generate images using AI models.
Request Body
Parameter | Type | Description |
---|---|---|
model | string | Required. Model ID or 'base/slug[:version]' format |
prompt | string | Required. Text prompt for image generation |
size | string | Image size (default: '1024x1024') |
provider | string | Optional. Specific provider ID or slug |
routing | string | Routing strategy: 'optimal' (default), 'cheapest', or 'compatible' |
public | boolean | Whether the generated media is public (default: true) |
Response
{
"data": [
{
"id": "abc123",
"url": "https://cdn.example.com/user/abc123/main.jpg",
"mime": "image/jpeg",
"user": "user123",
"media": "image",
"model": "stability/sdxl",
"provider": "stability",
"prompt": "A beautiful sunset over the ocean",
"size": "1024x1024",
"createdAt": "2025-03-25T12:00:00Z"
}
],
"price": 0.002,
"success": true,
"stats": {
"setupTime": 120,
"processingTime": 350,
"generationTime": 2500,
"retries": 0,
"providerId": "stability"
}
}
/v1/videos/generations
Generate videos using AI models.
Request Body
Parameter | Type | Description |
---|---|---|
model | string | Required. Model ID or 'base/slug[:version]' format |
prompt | string | Required. Text prompt for video generation |
size | string | Video size (default: '1080p') |
image_url | string | Optional. Source image URL for video generation |
provider | string | Optional. Specific provider ID or slug |
routing | string | Routing strategy: 'optimal' (default), 'cheapest', or 'compatible' |
/v1/media/upload
Get a signed URL for uploading media files.
Request Body
Parameter | Type | Description |
---|---|---|
name | string | Required. Filename with extension |
mime | string | Required. MIME type of the file |
Response
{
"result": {
"url": "https://storage.example.com/presigned-upload-url",
"id": "upload123"
},
"success": true
}
/v1/media/:id
Complete a media upload process.
This endpoint is called after uploading a file to the presigned URL obtained from the /v1/media/upload endpoint. It validates the uploaded file and updates its metadata.
Response
{
"result": {
"id": "upload123",
"url": "https://cdn.example.com/user/upload123/main.jpg",
"mime": "image/jpeg",
"size": 1048576,
"status": "complete",
"createdAt": "2025-03-25T12:00:00Z"
},
"success": true
}
Examples
Code Examples
Generating an Image
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://api.mythiq.ai/v1',
apiKey: 'YOUR_API_KEY',
});
async function generateImage() {
const response = await openai.images.generate({
model: 'stability/sdxl',
prompt: 'A beautiful sunset over the ocean',
size: '1024x1024',
});
console.log(response.data);
}
Listing Media
import OpenAI from 'openai';
import { fetch } from 'cross-fetch';
const openai = new OpenAI({
baseURL: 'https://api.mythiq.ai/v1',
apiKey: 'YOUR_API_KEY',
fetch: fetch,
});
async function listMedia() {
// Using fetch directly as OpenAI SDK doesn't have a media list endpoint
const response = await fetch('https://api.mythiq.ai/v1/media?limit=10&page=0&user=me&media=image', {
headers: {
'Authorization': `Bearer ${openai.apiKey}`,
}
});
const data = await response.json();
console.log(data.result.medias);
console.log(`Total: ${data.result.total}`);
}
Uploading Media
import OpenAI from 'openai';
import { fetch } from 'cross-fetch';
import fs from 'fs';
const openai = new OpenAI({
baseURL: 'https://api.mythiq.ai/v1',
apiKey: 'YOUR_API_KEY',
fetch: fetch,
});
async function uploadMedia() {
// Step 1: Get a presigned upload URL
const uploadResponse = await fetch('https://api.mythiq.ai/v1/media/upload', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${openai.apiKey}`,
},
body: JSON.stringify({
name: 'example.jpg',
mime: 'image/jpeg',
}),
});
const { result } = await uploadResponse.json();
const { url, id } = result;
// Step 2: Upload the file to the presigned URL
const fileBuffer = fs.readFileSync('./example.jpg');
await fetch(url, {
method: 'PUT',
body: fileBuffer,
headers: {
'Content-Type': 'image/jpeg',
},
});
// Step 3: Complete the upload process
const completeResponse = await fetch(`https://api.mythiq.ai/v1/media/${id}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${openai.apiKey}`,
},
});
const completeData = await completeResponse.json();
console.log(completeData.result);
}
Provider Routing
The Media API uses intelligent routing to select the most appropriate provider for your request. You can control this behavior using the routing
parameter:
Balances cost and feature support. Selects the cheapest provider that supports all requested features, or may choose a slightly more expensive provider (within 20% price difference) if it supports more features.
Always selects the lowest-cost provider that can fulfill the basic requirements of your request.
Selects a provider that supports all the parameters you've specified in your request, even if some are optional. Useful when you need specific features.