OpenAI-Compatible
Image Generation API

Professional-grade AI image generation with advanced segmentation, video processing, and media retrieval capabilities. OpenAI-compatible API with state-of-the-art models.

Lightning Fast
AI Segmentation
Video Processing
Quick Start Example
curl -X POST "https://api.univence.com/v1/images/generations" \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key-here" \
-d '{
"model": "z-image-turbo",
"prompt": "a beautiful sunset over mountains",
"image_size": "1024x1024"
}'

Quick Start

Generate your first image in just a few minutes

1

Get Your API Key

Sign up at univence.com and generate your API key from the dashboard.

2

Make Your First Request

Use our comprehensive REST API for image generation, segmentation, and media management. The API is fully compatible with OpenAI's format.

3

Receive High-Quality Images

Get your generated images instantly with URLs you can use anywhere.

Generate Your First Image

curl -X POST "https://api.univence.com/v1/images/generations" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{
    "model": "z-image-turbo",
    "prompt": "a beautiful sunset over mountains, digital art, highly detailed",
    "image_size": "1024x1024"
  }'

Powerful Features

Everything you need for professional image generation

High Performance

Lightning-fast generation with state-of-the-art AI models optimized for speed and quality.

Batch Processing

Generate up to 5 images simultaneously with our batch API endpoint for maximum efficiency.

Advanced Control

Fine-tune your generations with negative prompts, seeds, inference steps, and more.

Image Segmentation

Advanced AI-powered segmentation to identify and separate objects within images for precise editing.

Video Segmentation

Per-frame mask generation for video content with object tracking and separation capabilities.

Media Retrieval

Comprehensive file access and management for all your generated content and media assets.

OpenAI Compatible

Drop-in replacement for OpenAI's image generation API with familiar interface.

API Reference

Complete documentation for all endpoints, parameters, and examples

POST
/v1/images/generations

Generate Single Image

Generate a single image from a text prompt using advanced AI models. Supports various image sizes and generation parameters.

Request Parameters

Parameter Type Required Description Example
model string Yes The AI model to use for generation "z-image-turbo"
prompt string Yes Text description of the image to generate "a beautiful sunset over mountains"
image_size string No Output image dimensions "1024x1024"
negative_prompt string No Things to avoid in the image "blurry, low quality"
seed integer No Random seed for reproducible results 12345
num_inference_steps integer No Number of denoising steps (1-100) 50
guidance_scale float No How closely to follow the prompt (1-20) 7.5

Response

{
  "created": 1634567890,
  "data": [
    {
      "url": "https://api.univence.com/v1/media/abc123.jpg",
      "revised_prompt": "a beautiful sunset over mountains, digital art"
    }
  ]
}
POST
/v1/images/generations/batch

Generate Batch Images

Generate up to 5 images simultaneously in a single request for maximum efficiency.

Request Parameters

Parameter Type Required Description Example
requests array Yes Array of generation requests (max 5) [{...}, {...}]
response_format string No Response format: "url" or "b64_json" "url"

Example Request

curl -X POST "https://api.univence.com/v1/images/generations/batch" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{
    "requests": [
      {
        "model": "z-image-turbo",
        "prompt": "a red sports car"
      },
      {
        "model": "z-image-turbo", 
        "prompt": "a blue sports car"
      }
    ]
  }'
POST
/v1/images/upscale

Image Upscaling

Enhance and upscale existing images using advanced AI algorithms. Supports multiple upscaling methods and factors (2x, 4x, 8x).

Available Models

Model Description Best For Supported Factors
realesrgan_2x Real-ESRGAN 2x upscaling General photos, landscapes 2x
realesrgan_4x Real-ESRGAN 4x upscaling High-quality photos, portraits 4x
realesrgan_4x_anime Real-ESRGAN optimized for anime Anime, cartoon, illustrations 4x
swin2sr Swin2SR transformer-based High-detail restoration 2x, 4x
lanczos Classical Lanczos interpolation Simple upscaling, fast processing 2x, 4x, 8x

Request Parameters

Parameter Type Required Description Example
image_url string Yes URL of the image to upscale "https://example.com/image.jpg"
upscale_factor integer Yes Upscaling factor: 2, 4, or 8 4
model string No Upscaling model (defaults to realesrgan_4x) "realesrgan_4x"
enhance_details boolean No Enhance fine details during upscaling true
noise_reduction boolean No Apply noise reduction before upscaling false
output_format string No Output format: "png", "jpg", "webp" "png"

Response Format

{
  "created": 1634567890,
  "data": [
    {
      "url": "https://api.univence.com/v1/media/upscale_abc123.jpg",
      "original_size": "512x512",
      "upscale_factor": 4,
      "new_size": "2048x2048",
      "model_used": "realesrgan_4x",
      "processing_time": 2.34,
      "file_size": "2.1MB"
    }
  ]
}

Example Request

curl -X POST "https://api.univence.com/v1/images/upscale" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{
    "image_url": "https://example.com/low-res.jpg",
    "upscale_factor": 4,
    "model": "realesrgan_4x",
    "enhance_details": true,
    "noise_reduction": true,
    "output_format": "png"
  }'

Usage Examples

// JavaScript/Node.js Example
async function upscaleImage(imageUrl, factor = 4) {
    const response = await fetch('https://api.univence.com/v1/images/upscale', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-API-Key': 'your-api-key'
        },
        body: JSON.stringify({
            image_url: imageUrl,
            upscale_factor: factor,
            model: 'realesrgan_4x',
            enhance_details: true
        })
    });
    
    if (!response.ok) {
        throw new Error(`Upscaling failed: ${response.statusText}`);
    }
    
    const result = await response.json();
    return result.data[0].url;
}

// Python Example
import requests

def upscale_image(image_url, factor=4, model='realesrgan_4x'):
    url = "https://api.univence.com/v1/images/upscale"
    headers = {
        "Content-Type": "application/json",
        "X-API-Key": "your-api-key"
    }
    data = {
        "image_url": image_url,
        "upscale_factor": factor,
        "model": model,
        "enhance_details": True
    }
    
    response = requests.post(url, headers=headers, json=data)
    response.raise_for_status()
    
    result = response.json()
    return result['data'][0]['url']
POST
/v1/images/segmentations

Image Segmentation

AI-powered object segmentation and mask generation for precise image editing and analysis.

Request Parameters

Parameter Type Required Description Example
image_url string Yes URL of the image to segment "https://example.com/image.jpg"
model string No Segmentation model type "sam-vit-h"
confidence_threshold float No Minimum confidence for segmentation (0-1) 0.7
output_format string No Mask output format: "png" or "json" "png"
POST
/v1/videos/segmentations

Video Segmentation

Per-frame mask generation for video content with object tracking and separation capabilities.

Request Parameters

Parameter Type Required Description Example
video_url string Yes URL of the video to segment "https://example.com/video.mp4"
model string No Video segmentation model "video-sam"
frame_interval integer No Process every N frames (1-30) 5
max_duration integer No Maximum video duration in seconds 300
GET
/v1/media/{mediaFileId}

Media File Retrieval

Comprehensive file access and management for all generated content and media assets.

Path Parameters

Parameter Type Required Description Example
mediaFileId string Yes Unique identifier for the media file "abc123def456"

Query Parameters

Parameter Type Required Description Example
format string No Output format: "original", "jpg", "png", "webp" "jpg"
quality integer No Compression quality (1-100) 90

Authentication

Secure your API requests with API key authentication

API Key Authentication

All API requests require authentication using your API key. Include it in the request headers.

Header Authentication

curl -X POST "https://api.univence.com/v1/images/generations" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{"model": "z-image-turbo", "prompt": "a beautiful sunset"}'

JavaScript/Node.js Example

const response = await fetch('https://api.univence.com/v1/images/generations', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key-here'
  },
  body: JSON.stringify({
    model: 'z-image-turbo',
    prompt: 'a beautiful sunset over mountains'
  })
});

const result = await response.json();

Python Example

import requests

url = "https://api.univence.com/v1/images/generations"
headers = {
    "Content-Type": "application/json",
    "X-API-Key": "your-api-key-here"
}
data = {
    "model": "z-image-turbo",
    "prompt": "a beautiful sunset over mountains"
}

response = requests.post(url, headers=headers, json=data)
result = response.json()

Error Handling

Understanding and handling API errors effectively

HTTP Status Codes

Status Code Description Common Causes
200 Success Request completed successfully
201 Created Resource created successfully (batch operations)
400 Bad Request Invalid parameters, malformed JSON
401 Unauthorized Missing or invalid API key
402 Payment Required Insufficient credits or billing issues
404 Not Found Media file not found or expired
413 Payload Too Large Image/video file too large
429 Rate Limited Too many requests, quota exceeded
500 Server Error Internal server error, try again later
503 Service Unavailable Model temporarily unavailable

Error Response Format

{
  "error": {
    "code": "INVALID_MODEL",
    "message": "The specified model 'invalid-model' is not available",
    "type": "invalid_request_error",
    "details": {
      "available_models": ["z-image-turbo", "longcat-image-edit"],
      "request_id": "req_123456789",
      "timestamp": "2025-12-20T18:20:05Z"
    }
  }
}

Common Error Codes

Error Code Description Solution
INVALID_API_KEY API key is missing or invalid Check your API key and ensure it's properly formatted
INSUFFICIENT_CREDITS Not enough credits for the request Add credits to your account or upgrade your plan
RATE_LIMIT_EXCEEDED Too many requests in a short time Implement rate limiting or upgrade your plan
INVALID_IMAGE_URL Image URL is inaccessible or invalid Verify the image URL is publicly accessible
PROMPT_TOO_LONG Prompt exceeds maximum length Shorten your prompt or use our prompt optimization
INVALID_UPSCALE_FACTOR Upscale factor must be 2, 4, or 8 Use only supported upscale factors
VIDEO_TOO_LONG Video exceeds maximum duration Shorten video or increase max_duration parameter
BATCH_SIZE_EXCEEDED Batch request exceeds 5 images Limit batch requests to 5 images maximum

Rate Limiting

Understanding API rate limits and best practices

Rate Limits by Plan

Plan Requests/Minute Requests/Hour Concurrent Requests
Free Tier 10 100 1
Premium 60 1000 5
Enterprise 200 5000 20

Rate Limit Headers

All responses include rate limit information:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1634567890
X-RateLimit-Window: 60

Handling Rate Limits

import time
import requests

def generate_image_with_retry(prompt, max_retries=3):
    for attempt in range(max_retries):
        try:
            response = requests.post(
                'https://api.univence.com/v1/images/generations',
                headers={'X-API-Key': 'your-api-key'},
                json={'model': 'z-image-turbo', 'prompt': prompt}
            )
            
            if response.status_code == 429:
                # Rate limited, wait and retry
                reset_time = int(response.headers.get('X-RateLimit-Reset', 60))
                wait_time = min(reset_time, 60)
                print(f"Rate limited. Waiting {wait_time} seconds...")
                time.sleep(wait_time)
                continue
                
            response.raise_for_status()
            return response.json()
            
        except requests.exceptions.RequestException as e:
            if attempt == max_retries - 1:
                raise e
            time.sleep(2 ** attempt)  # Exponential backoff

Caching & Performance

Optimize your API usage with effective caching strategies

Media File Caching

Generated images and media files are cached for performance:

  • Generated Images: Cached for 24 hours
  • Segmentation Results: Cached for 7 days
  • Upscaled Images: Cached for 30 days
  • CDN Distribution: Global edge caching

Caching Best Practices

// Client-side caching example
class MediaCache {
    constructor() {
        this.cache = new Map();
        this.ttl = 24 * 60 * 60 * 1000; // 24 hours
    }
    
    generateCacheKey(prompt, params) {
        return btoa(JSON.stringify({prompt, ...params}));
    }
    
    isValid(timestamp) {
        return Date.now() - timestamp < this.ttl;
    }
    
    async getOrGenerate(prompt, params, generator) {
        const key = this.generateCacheKey(prompt, params);
        const cached = this.cache.get(key);
        
        if (cached && this.isValid(cached.timestamp)) {
            return cached.data;
        }
        
        const result = await generator(prompt, params);
        this.cache.set(key, {
            data: result,
            timestamp: Date.now()
        });
        
        return result;
    }
}

Available Models

Choose from our collection of powerful AI models

Z-Image-Turbo

Text-to-Image
Max Resolution: 2048×2048
Best For: General text-to-image generation

Delivers strong photorealistic image generation while maintaining excellent aesthetic quality.

Perfect for: Landscapes, portraits, abstract art, product images

LongCat-Image-Edit

Image-to-Image
Max Resolution: 2560×2560
Parameters: ~20B

Large-scale image editing model for advanced image manipulation and style transfer.

Perfect for: Image editing, style transfer, inpainting, photo enhancement

Simple Pricing

Flexible pricing that grows with your needs

Credit System: 1 Credit = $0.01 USD. Premium users get free access to all features including image generation, segmentation, and media retrieval!

New Pricing: Image Generation ($0.002/image), Image Segmentation ($0.0025/image), Video Segmentation ($0.0025/frame)

Ready to Get Started?

Join thousands of developers creating amazing images with our AI API