Image Generation API

Generate AI images using multiple providers including OpenAI DALL-E, Stability AI, Google Gemini (Nano Banana), and Flux through a unified API.

Quick Start

🎨 Generate Images with AI

MCPHub's Image Generation API provides a simple interface to generate images from text prompts using multiple AI providers.

Production Endpoint

https://api.mcphub.com/api/v3/images/generate

Multiple Providers

OpenAI, Google Gemini, Stability AI, Flux

Generate an Image

Python

import requests

# Get your JWT token first
token_response = requests.post(
    "https://api.mcphub.com/api/v3/user/token",
    headers={"X-User-Id": "your-user-id"}
)
token = token_response.json()["data"]["accessToken"]

# Generate an image
response = requests.post(
    "https://api.mcphub.com/api/v3/images/generate",
    headers={
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    },
    json={
        "prompt": "A serene mountain landscape at sunset",
        "provider": "google",  # google, openai, stability-ai, flux
        "model": "gemini-2.5-flash-image-1024x1024",
        "width": 1024,
        "height": 1024
    }
)

result = response.json()
print(f"Image URL: {result['image_url']}")
print(f"Credits used: {result['credits_used']}")

TypeScript/JavaScript

// Get your JWT token first
const tokenResponse = await fetch('https://api.mcphub.com/api/v3/user/token', {
  method: 'POST',
  headers: { 'X-User-Id': 'your-user-id' }
});
const { data: { accessToken } } = await tokenResponse.json();

// Generate an image
const response = await fetch('https://api.mcphub.com/api/v3/images/generate', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'A serene mountain landscape at sunset',
    provider: 'google',  // google, openai, stability-ai, flux
    model: 'gemini-2.5-flash-image-1024x1024',
    width: 1024,
    height: 1024
  })
});

const result = await response.json();
console.log(`Image URL: ${result.image_url}`);
console.log(`Credits used: ${result.credits_used}`);

cURL

# Get JWT token first
curl -X POST "https://api.mcphub.com/api/v3/user/token" \
  -H "X-User-Id: your-user-id"

# Generate image
curl -X POST "https://api.mcphub.com/api/v3/images/generate" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A serene mountain landscape at sunset",
    "provider": "google",
    "model": "gemini-2.5-flash-image-1024x1024",
    "width": 1024,
    "height": 1024
  }'

Available Providers & Models

Google Gemini (Nano Banana)

  • gemini-2.5-flash-image-1024x1024
  • gemini-2.5-flash-image-16:9
  • gemini-2.5-flash-image-9:16

~34 credits per image

OpenAI DALL-E

  • dall-e-3
  • dall-e-2

Varies by resolution & quality

📋 Get Full Model List

Retrieve all available image generation models and their pricing:

GET https://api.mcphub.com/api/v3/media-pricing/models?media_type=image

API Endpoints

POST/api/v3/images/generate

Generate an image from a text prompt

Request Body
prompt (required) - Text description of the image
provider (optional) - AI provider: google, openai, stability-ai, flux
model (optional) - Specific model ID
width (optional) - Image width in pixels
height (optional) - Image height in pixels
GET/api/v3/images/history

Get your image generation history

POST/api/v3/images/pricing/calculate-cost

Calculate cost before generating

Response Format

{
  "success": true,
  "image_id": "img_abc123",
  "image_url": "https://...",
  "provider": "google-genai",
  "model": "gemini-2.5-flash-image-1024x1024",
  "processing_time": 3.45,
  "credits_used": 34.0,
  "remaining_credits": 966.0,
  "width": 1024,
  "height": 1024,
  "original_prompt": "A serene mountain landscape at sunset",
  "status": "completed",
  "created_at": "2025-11-12T10:30:00Z"
}

Authentication

The Image Generation API uses JWT token authentication:

1

Get User ID

Sign in and get your user ID from your account

2

Request JWT Token

POST to /api/v3/user/token with X-User-Id header

3

Use Token

Include token in Authorization header for all API requests

Next Steps

📚 Related Docs

🚀 Get Started