Deployment Options
The AI Gateway can be deployed in multiple ways to suit your infrastructure needs:
NPM/Bun Quick local development
Docker Containerized deployment
Node.js Server Self-hosted production server
Cloudflare Workers Edge deployment
Kubernetes Scalable orchestration
Cloud Providers AWS, Azure, GCP
For a fully managed solution without infrastructure concerns, consider Portkey’s hosted gateway which processes billions of tokens daily in production.
Quick Start (npx)
The fastest way to get started:
Run with npx
No installation required - just run: Or with Bun:
Verify it's running
The gateway starts on port 8787:
API : http://localhost:8787/v1
Console : http://localhost:8787/public/
Test it: curl http://localhost:8787
You should see: AI Gateway says hey!
This method is perfect for local development and testing. For production, use Docker or a Node.js server.
Docker
Deploy using Docker for containerized production environments.
Run with Docker
Pull and run the latest image from Docker Hub: docker run --rm -p 8787:8787 portkeyai/gateway:latest
The gateway is now running at http://localhost:8787
Run with environment variables
Pass configuration via environment variables: docker run --rm -p 8787:8787 \
-e REDIS_CONNECTION_STRING="redis://localhost:6379" \
portkeyai/gateway:latest
Build from source (optional)
Clone the repository and build your own image: git clone https://github.com/portkey-ai/gateway
cd gateway
docker build -t portkey-gateway .
docker run --rm -p 8787:8787 portkey-gateway
Docker Compose
For multi-container setups with Redis caching:
Download docker-compose.yaml
wget "https://raw.githubusercontent.com/Portkey-AI/gateway/main/docker-compose.yaml"
Start the services
This starts:
AI Gateway on port 8787
Redis for caching (if configured)
View logs
docker compose logs -f gateway
The Docker image is built from the Dockerfile which uses a multi-stage build for optimal size.
Node.js Server
Run the gateway as a standalone Node.js application.
Clone the repository
git clone https://github.com/portkey-ai/gateway
cd gateway
Build the project
This compiles the TypeScript code and prepares the production bundle.
Start the server
node build/start-server.js
Or use npm script:
Configure (optional)
Create a conf.json file to customize settings. See conf_sample.json for available options. You can also use environment variables: export REDIS_CONNECTION_STRING = "redis://localhost:6379"
node build/start-server.js
For development, use npm run dev:node which includes hot-reload.
Running as a Service
Create a systemd service file for production:
/etc/systemd/system/portkey-gateway.service
[Unit]
Description =Portkey AI Gateway
After =network.target
[Service]
Type =simple
User =portkey
WorkingDirectory =/opt/portkey-gateway
ExecStart =/usr/bin/node /opt/portkey-gateway/build/start-server.js
Restart =always
Environment = NODE_ENV =production
[Install]
WantedBy =multi-user.target
Enable and start:
sudo systemctl enable portkey-gateway
sudo systemctl start portkey-gateway
sudo systemctl status portkey-gateway
Cloudflare Workers
Deploy to Cloudflare’s edge network for low-latency global distribution.
Clone and setup
git clone https://github.com/portkey-ai/gateway
cd gateway
npm install
Configure Wrangler
Make sure you have the Wrangler CLI installed and authenticated: npm install -g wrangler
wrangler login
Deploy to Cloudflare
This builds and deploys the gateway to Cloudflare Workers.
Get your worker URL
Wrangler will output your worker URL: https://your-worker.your-subdomain.workers.dev
Cloudflare Workers have request limits on the free tier. Consider upgrading for production use.
Kubernetes
Deploy to Kubernetes for production-grade orchestration.
Create deployment manifest
Create deployment.yaml: apiVersion : apps/v1
kind : Deployment
metadata :
name : portkey-gateway
spec :
replicas : 3
selector :
matchLabels :
app : portkey-gateway
template :
metadata :
labels :
app : portkey-gateway
spec :
containers :
- name : gateway
image : portkeyai/gateway:latest
ports :
- containerPort : 8787
env :
- name : NODE_ENV
value : "production"
---
apiVersion : v1
kind : Service
metadata :
name : portkey-gateway
spec :
type : LoadBalancer
ports :
- port : 80
targetPort : 8787
selector :
app : portkey-gateway
Apply to cluster
kubectl apply -f deployment.yaml
Verify deployment
kubectl get deployments
kubectl get services
kubectl get pods
Access the gateway
Get the external IP: kubectl get service portkey-gateway
For production, consider adding:
Horizontal Pod Autoscaling (HPA)
Resource limits and requests
Ingress controller for HTTPS
ConfigMaps for configuration
Secrets for API keys
AWS EC2
Quick deployment to AWS EC2 using CloudFormation.
Use CloudFormation template
The repository includes a CloudFormation template for one-click deployment:
Configure parameters
Set:
VPC ID
Subnet ID
Instance Type (t2.micro for testing, t3.small for production)
Launch stack
CloudFormation will:
Launch an EC2 instance
Install Docker
Run the gateway container
Configure security groups (port 8787)
Access your gateway
Get the public DNS from CloudFormation outputs: http://<instance-public-dns>:8787
Replit
Deploy with one click:
Zeabur
Use the template:
Azure, GCP, OpenShift
For enterprise deployments on:
Azure
Google Cloud Platform
Red Hat OpenShift
Other cloud providers
See the enterprise deployment guide or contact the team .
Configuration
Environment Variables
Common configuration options:
Variable Description Default PORTServer port 8787REDIS_CONNECTION_STRINGRedis URL for caching - NODE_ENVEnvironment mode development
Configuration File
Create conf.json for advanced settings:
{
"port" : 8787 ,
"cache" : {
"type" : "redis" ,
"connection" : "redis://localhost:6379"
}
}
See conf_sample.json in the repository for all available options.
Verification
After installation, verify your deployment:
Health check
curl http://localhost:8787
Should return: AI Gateway says hey!
Test API endpoint
curl http://localhost:8787/v1/chat/completions \
-H "Content-Type: application/json" \
-H "x-portkey-provider: openai" \
-H "Authorization: Bearer sk-***" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "test"}]
}'
Check the console
Open http://localhost:8787/public/ to view the web console.
Next Steps
Make Your First Request Follow the quickstart to make your first API call
Configure Routing Learn about routing, fallbacks, and load balancing
Add Guardrails Protect your AI apps with input/output validation
Production Deployment Best practices for production deployments