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
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 mpsstring
default:"float16"
Model data type:
float16, bfloat16, or float32string
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:/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
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: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
Next Steps
Generate Images
Learn about the image generation endpoint
List Models
Query available models
Health Checks
Monitor server health and status