Skip to main content
The Portkey AI Gateway can be deployed as a standalone Node.js server, giving you full control over your hosting environment.

Quick Start

The fastest way to run the gateway locally:
The gateway will start on http://localhost:8787.

From Source Deployment

For production deployments, build and run from source:
1

Clone the repository

Clone the Portkey AI Gateway repository:
2

Install dependencies

Install the required npm packages:
Or with bun for faster installation:
3

Build the project

Build the production bundle:
This creates optimized files in the build/ directory.
4

Start the server

Run the production server:
Or use the npm script:

Development Mode

For development and testing, use the development server:
This starts the server with hot-reloading using tsx.

Configuration

Environment Variables

Configure the gateway using environment variables:

Configuration File

Create a conf.json file for advanced configuration:
conf.json
Place this file in the project root directory.

Process Management

Using PM2

PM2 is a production process manager for Node.js applications.
1

Install PM2

2

Start with PM2

3

Configure auto-restart

Save the process list and configure startup:

PM2 Ecosystem File

Create an ecosystem.config.js file for advanced PM2 configuration:
ecosystem.config.js
Start with the ecosystem file:

PM2 Management Commands

Systemd Service

For Linux systems, create a systemd service:

Create Service File

Create /etc/systemd/system/portkey-gateway.service:
portkey-gateway.service

Manage the Service

1

Reload systemd

2

Enable on boot

3

Start the service

4

Check status

Reverse Proxy Setup

Nginx

Configure Nginx as a reverse proxy:
/etc/nginx/sites-available/portkey-gateway
Enable the site:

Add SSL with Certbot

Performance Tuning

Node.js Options

Optimize Node.js for production:

Clustering

Utilize multiple CPU cores by running multiple instances behind a load balancer, or use PM2’s cluster mode as shown above.

Monitoring

View Logs

Health Check

Check if the gateway is running:

Troubleshooting

Port Already in Use

If port 8787 is already in use, change it:

Memory Issues

Increase Node.js heap size:

Permission Errors

Ensure the user has proper permissions:

Next Steps

Docker Deployment

Containerize your Node.js deployment

Configuration

Configure the gateway for production