Skip to main content

Introduction

HyperGen provides an OpenAI-compatible HTTP API for image generation. This allows you to:
  • Generate images via REST API calls
  • Integrate with OpenAI client libraries
  • Deploy as a scalable service
  • Use familiar OpenAI API patterns
The API is fully compatible with OpenAI’s image generation endpoints, making it a drop-in replacement for services using the OpenAI API.

Starting the Server

Start the HyperGen API server using the CLI:

Server Options

string
required
HuggingFace model ID or local path to model
string
default:"0.0.0.0"
Host address to bind to. Use 0.0.0.0 to accept connections from any IP.
integer
default:"8000"
Port to listen on
string
default:"cuda"
Device to run model on: cuda, cpu, or mps
string
default:"float16"
Model data type: float16, bfloat16, or float32
string
API key for authentication. If not set, authentication is disabled.
string
Path to LoRA weights to load
integer
default:"100"
Maximum number of requests in queue
integer
default:"1"
Maximum batch size for processing

Example


Authentication

API Key

If you start the server with --api-key, all requests must include the API key in the Authorization header.

Error Responses

error
Returned when:
  • Authorization header is missing
  • API key is invalid
  • API key format is incorrect

Base URL

When running locally, the default base URL is:
All endpoints are prefixed with /v1 to match OpenAI’s API structure:

Endpoints

HyperGen provides the following API endpoints:

POST /v1/images/generations

Generate images from text prompts (OpenAI-compatible)

GET /v1/models

List available models (OpenAI-compatible)

GET /health

Health check endpoint for monitoring

OpenAI Compatibility

HyperGen’s HTTP API is designed to be compatible with OpenAI’s image generation API. This means:
  1. Drop-in Replacement: Use HyperGen as a replacement for OpenAI’s DALL-E API
  2. Same Request Format: Request and response formats match OpenAI’s spec
  3. Client Library Support: Works with OpenAI’s official client libraries

Using OpenAI Python Library

Using OpenAI Node.js Library


HyperGen Extensions

While maintaining OpenAI compatibility, HyperGen adds several extensions:

Extended Parameters

string
Negative prompt to guide what to avoid
integer
default:"50"
Number of denoising steps (quality vs speed)
float
default:"7.5"
How closely to follow the prompt
integer
Random seed for reproducible results
string
Path to LoRA weights (overrides server default)
float
default:"1.0"
LoRA influence strength (0.0 to 2.0)

Example with Extensions


Error Handling

The API uses standard HTTP status codes:
success
Request succeeded
error
Invalid request parameters
error
Missing or invalid API key
error
Server error during generation

Error Response Format

All errors return a JSON response:
Or in OpenAI format:

Rate Limiting

HyperGen uses a request queue system:
  • Maximum queue size: Configurable via --max-queue-size (default: 100)
  • Requests beyond the queue size will wait
  • Queue status available via /health endpoint
Monitor queue size using the /health endpoint to track server load

Best Practices

  • Always use --api-key for authentication
  • Set appropriate --max-queue-size based on expected traffic
  • Use a reverse proxy (nginx, Caddy) for HTTPS
  • Monitor the /health endpoint
  • Run on a GPU-enabled instance
  • Use SDXL Turbo for faster generation (4 steps vs 50)
  • Adjust --max-batch-size for throughput vs latency
  • Use float16 dtype for 2x speed improvement
  • Keep queue size reasonable to avoid memory issues
  • Run without --api-key for easier testing
  • Use --reload flag for auto-restart on code changes
  • Monitor logs for debugging
  • Test with /health endpoint first

Next Steps

Generate Images

Learn about the image generation endpoint

List Models

Query available models

Health Checks

Monitor server health and status