Bypass network restrictions and access ChatGPT from isolated networks. A relay system that queues prompts from an internal server (with limited internet access) to a local bridge machine (with open internet), then delivers AI responses back.
AI Relay is a queue-based relay system that enables ChatGPT access in environments where:
- The internal network has restricted or no access to international internet
- A separate machine (e.g., laptop with Starlink or VPN) has open internet access
Instead of the internal server calling OpenAI directly (which would fail), a worker runs on the machine with internet. It polls the internal server for pending prompts, sends them to the OpenAI API, and returns the responses. This effectively bypasses filtering by routing AI traffic through the bridge machine.
- Corporate networks with strict outbound filtering
- Regions where AI services are blocked or throttled
- Air-gapped or semi-isolated networks with one bridge to the internet
- Educational or research environments with limited external access
┌─────────────────────────────────────────────────────────────────────────┐
│ RESTRICTED / INTERNAL NETWORK │
│ │
│ Users submit prompts via web UI │
│ ┌──────────────┐ ┌─────────────────────┐ │
│ │ Browser │ ──────► │ Internal Server │ │
│ │ (Users) │ ◄────── │ (Go + SQLite) │ │
│ └──────────────┘ │ • No OpenAI call │ │
│ │ • Queue in DB │ │
│ └──────────┬──────────┘ │
│ │ │
│ │ Polling (outbound only) │
└───────────────────────────────────────┼─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ BRIDGE MACHINE (Open Internet) │
│ │
│ ┌─────────────────────┐ ┌─────────────────────┐ │
│ │ Worker (Go) │ ──── HTTPS ──────► │ OpenAI API │ │
│ │ • Fetches jobs │ ◄─── Response ──── │ (ChatGPT) │ │
│ │ • Sends to OpenAI │ └─────────────────────┘ │
│ │ • Returns results │ │
│ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
Key design: The internal server never initiates connections to the outside. Only the worker (on the bridge machine) polls the server and talks to OpenAI. This works even when inbound connections are blocked.
| Feature | Description |
|---|---|
| Queue-based | Prompts are stored in SQLite; worker processes them in order |
| Polling model | Worker fetches jobs periodically—no inbound ports needed on internal server |
| Session auth | Secure login with bcrypt and session cookies |
| RTL / Persian UI | Right-to-left support, Vazirmatn font |
| Rate limiting | Per-user limits to prevent abuse |
| CSRF protection | Forms protected against cross-site request forgery |
| Atomic job claiming | Prevents duplicate processing by multiple workers |
| Docker support | One-command deployment with Docker Compose |
- Go 1.21+
- OpenAI API key
- (Optional) Docker & Docker Compose
git clone https://github.com/YOUR_USERNAME/ai-relay.git
cd ai-relaycp .env.example .env
# Edit .env: set WORKER_TOKEN, DEFAULT_PASSWORD, OPENAI_API_KEYgo run ./cmd/server
# Or with Docker:
# docker-compose up -dServer runs at http://localhost:8080 (or :8081 if port 8080 is in use).
# .env on bridge machine:
# INTERNAL_SERVER_URL=http://internal-server-ip:8080
# WORKER_TOKEN=<same as server>
# OPENAI_API_KEY=sk-...
go run ./cmd/worker- Open
http://<server-ip>:8080/login - Log in (default:
admin/admin123) - Submit prompts; worker fetches and processes them; responses appear in the dashboard
| Variable | Description | Default |
|---|---|---|
SERVER_PORT |
HTTP port | 8080 |
SESSION_SECRET |
Session encryption key | Required |
WORKER_TOKEN |
Shared secret for worker API | Required |
DEFAULT_USERNAME |
Initial user | admin |
DEFAULT_PASSWORD |
Initial password | changeme123 |
DATABASE_PATH |
SQLite path | ./data/ai_relay.db |
| Variable | Description | Default |
|---|---|---|
INTERNAL_SERVER_URL |
Internal server URL | Required |
WORKER_TOKEN |
Must match server | Required |
OPENAI_API_KEY |
OpenAI API key | Required |
OPENAI_MODEL |
Model name | gpt-4o-mini |
WORKER_POLL_INTERVAL_SECONDS |
Poll interval | 5 |
ai-relay/
├── cmd/
│ ├── server/ # Internal server (web + API)
│ └── worker/ # Bridge worker (polls + OpenAI)
├── internal/
│ ├── config/ # Config loading
│ ├── db/ # SQLite layer
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # Auth, CSRF, rate limit
│ ├── models/ # Data models
│ ├── openai/ # OpenAI client (worker only)
│ └── services/ # Worker HTTP client
├── web/
│ ├── static/ # CSS
│ └── templates/ # HTML
├── docker-compose.yml
├── Dockerfile
└── .env.example
# Build and run
docker-compose up -d --build
# Default port: 8081 (8080 if available)
# Data persisted in ./data/- Never commit
.env— it contains secrets. Use.env.exampleas a template. - If
.envwas accidentally committed:git rm --cached .envthen commit the removal. - Set
SESSION_SECRET,WORKER_TOKEN,DEFAULT_PASSWORDvia environment — no defaults in code. - Use HTTPS in production.
- Generate tokens:
openssl rand -base64 32 - Restrict worker API access by IP if possible.
MIT License. See LICENSE for details.