Skip to main content
Deploying to Cloudflare Workers puts the gateway on Cloudflare’s global edge network, minimising latency to your users regardless of where your AI providers are located.

Prerequisites

Deploy

1

Clone the repository

git clone https://github.com/portkey-ai/gateway
cd gateway
2

Install dependencies

npm install
3

Authenticate with Cloudflare

If you have not already authenticated Wrangler with your Cloudflare account:
npx wrangler login
4

Deploy

npm run deploy
This runs wrangler deploy --minify src/index.ts, which bundles the gateway and publishes it to your Cloudflare Workers account. Wrangler prints the deployed URL on success.

wrangler.toml

The repository includes a wrangler.toml with pre-configured environments:
wrangler.toml
name = "rubeus"
compatibility_date = "2024-12-05"
main = "src/index.ts"
compatibility_flags = [ "nodejs_compat" ]

[vars]
ENVIRONMENT = 'dev'
CUSTOM_HEADERS_TO_IGNORE = []

# Staging environment
[env.staging]
name = "rubeus-dev"

[env.staging.vars]
ENVIRONMENT = 'staging'
CUSTOM_HEADERS_TO_IGNORE = []

# Production environment
[env.production]
name = "rubeus"
logpush = true

[env.production.vars]
ENVIRONMENT = 'production'
CUSTOM_HEADERS_TO_IGNORE = []
To deploy to a specific environment, pass the --env flag:
npx wrangler deploy --minify src/index.ts --env production

Notes

Cloudflare Workers run on the workerd runtime. The gateway detects this at startup and enables the WebSocket realtime handler accordingly. Redis-backed caching is not available on Workers — use Cloudflare KV or Durable Objects for persistent state if needed.
The nodejs_compat compatibility flag is required. It enables Node.js built-ins that the gateway depends on.
For more details on Cloudflare Workers deployment, see the official Cloudflare Workers documentation.

Build docs developers (and LLMs) love