A smart proxy server that automatically manages RunPod instance lifecycle, starting pods when needed and stopping them after periods of inactivity to save costs.
Note
The code and this readme have been created with Claude code.
The proxy server acts as an intelligent middleware between your local applications and your RunPod instances:
- Automatic Pod Management: Starts your RunPod instance when the first request arrives
- Request Proxying: Forwards all HTTP requests to your running pod
- Idle Detection: Monitors request activity and stops the pod after a configurable timeout
- Cost Optimization: Minimizes compute costs by only running pods when actively used
- ✅ Automatic pod start/stop lifecycle management
- ✅ Configurable idle timeout (default: 5 minutes)
- ✅ Random port selection when no port specified
- ✅ Health check endpoint
- ✅ Graceful shutdown with pod cleanup
- ✅ Comprehensive logging and error handling
- ✅ ESM module support
npm installCopy the example environment file and fill in your RunPod details:
cp .env.dist .envEdit .env with your configuration:
# Your RunPod API key (found in your RunPod account settings)
RUNPOD_API_KEY=your_runpod_api_key_here
# The URL of your RunPod instance (e.g., https://your-pod-id-8080.proxy.runpod.net)
PROXIED_URL=https://your-pod-endpoint.proxy.runpod.net
# Your RunPod instance/pod ID
RUNPOD_INSTANCE_ID=your_pod_id
# Local server port (optional - random port used if not specified)
PORT=3000
# Timeout in milliseconds (optional - defaults to 5 minutes)
TIMEOUT=300000npm startThe server will start and display:
- Local proxy URL
- Target RunPod URL
- Pod ID being managed
- Configured timeout
- Health check endpoint
Once running, send requests to your local proxy server instead of directly to RunPod:
# Instead of: curl https://your-pod.proxy.runpod.net/api/endpoint
curl http://localhost:3000/api/endpointThe proxy will:
- Check if the pod is running
- Start the pod if it's stopped (waits for startup)
- Forward your request to the pod
- Return the pod's response
- Start the idle timeout counter
Check proxy status:
curl http://localhost:3000/healthResponse includes:
- Proxy server status
- Pod running state
- Last request timestamp
- Configured timeout
The server handles graceful shutdown:
# Ctrl+C or:
kill -SIGINT <process_id>This will automatically stop the RunPod instance before exiting.
| Variable | Required | Default | Description |
|---|---|---|---|
RUNPOD_API_KEY |
✅ | - | Your RunPod API key |
PROXIED_URL |
✅ | - | RunPod instance endpoint URL |
RUNPOD_INSTANCE_ID |
✅ | - | RunPod pod/instance ID |
PORT |
❌ | Random | Local server port |
TIMEOUT |
❌ | 300000 | Idle timeout in milliseconds |
RunPod API Key:
- Go to RunPod → Settings → API Keys
- Create a new API key if needed
Pod ID:
- In your RunPod dashboard, click on your pod
- The ID is shown in the pod details
Pod URL:
- In your pod details, look for the "Connect" section
- Use the HTTP service URL (usually ends with
.proxy.runpod.net)
- Stopped: Pod is not running (saving money)
- Starting: Pod is booting up (may take 30-60 seconds)
- Running: Pod is active and receiving requests
- Stopping: Pod is shutting down after idle timeout
The proxy helps minimize RunPod costs by:
- On-Demand Starting: Only starts pods when requests arrive
- Automatic Stopping: Stops pods after the configured idle period
- Smart Monitoring: Tracks request activity to determine when it's safe to stop
"Missing required environment variables"
- Ensure
.envfile exists and contains all required variables - Double-check variable names match exactly
"Pod failed to start within timeout period"
- Your pod may take longer to start than expected
- Check your pod's Docker image and startup time
- Verify the pod isn't stuck or has configuration issues
"Proxy error" responses
- Verify your
PROXIED_URLis correct and accessible - Check that your pod is properly configured to accept HTTP requests
- Ensure any required authentication is handled by your pod
Port already in use
- The proxy will automatically try a different random port
- Or specify a different
PORTin your.envfile
Enable detailed logging by checking the console output. The proxy logs:
- Pod status checks
- Start/stop operations
- Request proxying
- Timeout events
- Errors and warnings
npm run devISC - See package.json for details.
Caution
This proxy is designed for development and testing purposes. For production use, consider additional features like authentication, rate limiting, and monitoring.