Skip to main content

Introduction

HyperGen provides a production-ready API server that serves diffusion models with an OpenAI-compatible interface. Deploy any diffusers model with request queuing, batching, and authentication.

Key Features

OpenAI-Compatible

Drop-in replacement for OpenAI’s image generation API. Use the official OpenAI Python client.

Request Queue

Automatic request queuing and batching for optimal GPU utilization.

LoRA Support

Load and serve models with LoRA adapters dynamically.

Authentication

Optional API key authentication for secure deployments.

Production-Ready

Built on FastAPI + uvicorn with async request handling.

Easy Deployment

Single command to start serving any model.

Quick Start

Start a server in one command:
Then use it from Python:

Architecture

Components

1

API Server

FastAPI-based HTTP server that handles incoming requests and responses.
  • OpenAI-compatible endpoints
  • Request validation with Pydantic
  • Authentication middleware
  • Health check endpoints
2

Request Queue

Thread-safe async queue that manages incoming generation requests.
  • FIFO ordering
  • Configurable max size
  • Request tracking with unique IDs
  • Future-based result delivery
3

Model Worker

Background worker that processes requests from the queue.
  • Loads and manages the model
  • Batch processing (future feature)
  • LoRA loading and switching
  • GPU memory management

OpenAI Compatibility

HyperGen implements OpenAI’s image generation API:

Endpoint: /v1/images/generations

Standard OpenAI parameters: HyperGen extensions:

Other Endpoints

Health check endpoint for monitoring.Response:
List available models (OpenAI-compatible).Response:

Request Flow

  1. Client sends request to /v1/images/generations
  2. Server validates request parameters
  3. Server checks authentication (if enabled)
  4. Request added to queue with unique ID
  5. Worker picks up request from queue
  6. Model generates images on GPU
  7. Results returned to client via async future
  8. Response formatted as OpenAI-compatible JSON

Performance

Single Request Processing

Typical latency (SDXL, 50 steps, RTX 4090):
  • Queue time: <10ms
  • Generation time: ~3-5 seconds
  • Total: ~3-5 seconds

Queue Management

The request queue handles multiple concurrent requests:
  • Requests are processed FIFO (first in, first out)
  • Max queue size configurable (default: 100)
  • Queue full returns HTTP 503 (Service Unavailable)

Batch Processing

Batch processing for multiple requests is coming in Phase 2.
Future feature:
  • Automatically batch compatible requests
  • Process multiple prompts in one forward pass
  • Configurable max batch size

Deployment Scenarios

Local Development

No authentication, localhost only.

Production Deployment

With authentication and external access.

Behind Reverse Proxy

Docker Deployment

Official Docker images coming soon.
Example Dockerfile:

Roadmap

Phase 1 (Current)

  •  FastAPI server with OpenAI endpoints
  •  Request queue management
  •  Model worker
  •  API key authentication
  •  LoRA support (server flag)
  • =� Complete inference implementation

Phase 2 (Planned)

  • Request batching for multiple prompts
  • Dynamic LoRA hot-swapping via API
  • Metrics and monitoring endpoints
  • Rate limiting
  • Streaming responses
  • Image-to-image endpoints

Phase 3 (Future)

  • Multi-GPU serving
  • Model caching and auto-scaling
  • Load balancing across workers
  • WebSocket support
  • Video generation endpoints

Monitoring and Debugging

Health Checks

Check server health:

Logging

HyperGen logs to stdout with INFO level by default:

Error Handling

The server returns standard HTTP status codes:
  • 200 OK - Success
  • 400 Bad Request - Invalid parameters
  • 401 Unauthorized - Missing/invalid API key
  • 500 Internal Server Error - Generation failed
  • 503 Service Unavailable - Queue full

Security Considerations

Always use API keys in production deployments!
Best Practices:
  1. Use strong API keys:
  2. Run behind HTTPS:
    • Use nginx or similar reverse proxy
    • Enable SSL/TLS certificates
  3. Firewall rules:
    • Restrict access to trusted IPs
    • Use VPN or internal network
  4. Rate limiting:
    • Use nginx rate limiting
    • Or implement application-level limits
  5. Monitor usage:
    • Track API usage
    • Alert on anomalies

Next Steps

Quick Start

Start serving a model in 5 minutes

Configuration

All server configuration options

Supported Models

See which models you can serve

Examples

Client examples on GitHub