MythIQ

Command Palette

Search for a command to run...

Media API

The Media API allows you to generate and manage media content such as images and videos using various AI models.

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.

GET

/v1/media

List media items with filtering and pagination options.

Query Parameters

ParameterTypeDescription
limitintegerMaximum number of items to return (default: 25, max: 100)
pageintegerPage number for pagination (default: 0)
userstringFilter by user ID or 'me' for current user
mediastringFilter by media type (e.g., 'image', 'video')
sizestringFilter by size (e.g., '1024x1024')
modelstringFilter by model ID or 'base/slug' format
providerstringFilter by provider ID or slug
searchstringSearch in prompt text
sortstringSort order: 'newest' (default) or 'oldest'

Response

json
{
  "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
}
POST

/v1/images/generations

Generate images using AI models.

Request Body

ParameterTypeDescription
modelstringRequired. Model ID or 'base/slug[:version]' format
promptstringRequired. Text prompt for image generation
sizestringImage size (default: '1024x1024')
providerstringOptional. Specific provider ID or slug
routingstringRouting strategy: 'optimal' (default), 'cheapest', or 'compatible'
publicbooleanWhether the generated media is public (default: true)

Response

json
{
  "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"
  }
}
POST

/v1/videos/generations

Generate videos using AI models.

Request Body

ParameterTypeDescription
modelstringRequired. Model ID or 'base/slug[:version]' format
promptstringRequired. Text prompt for video generation
sizestringVideo size (default: '1080p')
image_urlstringOptional. Source image URL for video generation
providerstringOptional. Specific provider ID or slug
routingstringRouting strategy: 'optimal' (default), 'cheapest', or 'compatible'
POST

/v1/media/upload

Get a signed URL for uploading media files.

Request Body

ParameterTypeDescription
namestringRequired. Filename with extension
mimestringRequired. MIME type of the file

Response

json
{
  "result": {
    "url": "https://storage.example.com/presigned-upload-url",
    "id": "upload123"
  },
  "success": true
}
PUT

/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

json
{
  "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

typescript
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

typescript
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

typescript
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:

optimal(default)

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.

cheapest

Always selects the lowest-cost provider that can fulfill the basic requirements of your request.

compatible

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.