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
Starting the Server
Start the HyperGen API server using the CLI:Server Options
HuggingFace model ID or local path to model
Host address to bind to. Use
0.0.0.0 to accept connections from any IP.Port to listen on
Device to run model on:
cuda, cpu, or mpsModel data type:
float16, bfloat16, or float32API key for authentication. If not set, authentication is disabled.
Path to LoRA weights to load
Maximum number of requests in queue
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
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:/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:- Drop-in Replacement: Use HyperGen as a replacement for OpenAI’s DALL-E API
- Same Request Format: Request and response formats match OpenAI’s spec
- 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
Negative prompt to guide what to avoid
Number of denoising steps (quality vs speed)
How closely to follow the prompt
Random seed for reproducible results
Path to LoRA weights (overrides server default)
LoRA influence strength (0.0 to 2.0)
Example with Extensions
Error Handling
The API uses standard HTTP status codes:Request succeeded
Invalid request parameters
Missing or invalid API key
Server error during generation
Error Response Format
All errors return a JSON response: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
/healthendpoint
Monitor queue size using the
/health endpoint to track server loadBest Practices
Production Deployment
Production Deployment
- Always use
--api-keyfor authentication - Set appropriate
--max-queue-sizebased on expected traffic - Use a reverse proxy (nginx, Caddy) for HTTPS
- Monitor the
/healthendpoint - Run on a GPU-enabled instance
Performance Optimization
Performance Optimization
- Use SDXL Turbo for faster generation (4 steps vs 50)
- Adjust
--max-batch-sizefor throughput vs latency - Use
float16dtype for 2x speed improvement - Keep queue size reasonable to avoid memory issues
Development
Development
- Run without
--api-keyfor easier testing - Use
--reloadflag for auto-restart on code changes - Monitor logs for debugging
- Test with
/healthendpoint first