---
title: "Deploy Khoj AI"
description: "Ask anything, understand documents, create new content"
category: "Other"
url: https://railway.com/deploy/khoj-ai
---

# Deploy Khoj AI

Ask anything, understand documents, create new content

**[Deploy Khoj AI on Railway](https://railway.com/template/khoj-ai)**

- **Creator:** Şükrü
- **Category:** Other
- **Total deploys:** 9

## Template content

### computer https://devicons.railway.app/computer

- **Image:** ghcr.io/khoj-ai/khoj-computer
- **Public domain:** Yes

### search https://devicons.railway.app/search

- **Image:** searxng/searxng
- **Public domain:** Yes

### sandbox https://devicons.railway.app/sandbox

- **Image:** ghcr.io/khoj-ai/terrarium
- **Public domain:** Yes

### server https://i.ibb.co/NqqBML9/134046886-s-200-v-4.png

- **Image:** ghcr.io/khoj-ai/khoj-cloud:latest
- **Public domain:** Yes

### pgvector https://devicons.railway.app/i/postgresql.svg

- **Image:** pgvector/pgvector:pg16
- **Start command:** `/bin/sh -c "unset PGPORT; docker-entrypoint.sh postgres --port=5432"`

## Documentation

# Deploy and Host Khoj AI on Railway

[Khoj AI](https://khoj.dev/) is an open-source personal AI that allows you to chat with your knowledge base, search the web, execute code in sandboxes, and integrate with multiple AI models. It’s designed to be easily extensible, self-hostable, and privacy-conscious.

## About Hosting Khoj AI

Hosting Khoj AI on [Railway](https://railway.app/) provides a simple and powerful way to deploy your own personal AI assistant in the cloud. With minimal setup, Railway takes care of the infrastructure and scaling, while you configure the services and API keys. Deploying Khoj involves setting up a Python backend, connecting to a PostgreSQL (pgvector) database, and optionally integrating external search and LLM APIs. Once deployed, you can access Khoj through your Railway public domain and manage everything from a single dashboard.

## Common Use Cases

- Personal AI assistant for research and writing
- Self-hosted AI chatbot with search and retrieval capabilities
- Integration with custom LLMs and vector databases for advanced workflows

## Dependencies for Khoj AI Hosting

- PostgreSQL with pgvector extension (auto-provisioned on Railway)
- Python runtime for backend server
- Optional external API integrations (Jina, OpenAI, Gemini, etc.)

### Deployment Dependencies

- [Khoj GitHub Repository](https://github.com/khoj-ai/khoj)
- [E2B API](https://e2b.dev/)
- [Jina API](https://jina.ai/)
- [Serper.dev](https://serper.dev/)
- [Firecrawl](https://firecrawl.dev/)
- [Olostep](https://olostep.com/)
- [SearxNG](https://searxng.org/)

### Implementation Details (Optional)

You can scale the Gunicorn workers depending on your Railway plan by changing `GUNICORN_WORKERS`. Default is 6 for Pro plans.

```bash
GUNICORN_WORKERS=3
```

You can also change the OpenAI-compatible API endpoint by setting `OPENAI_BASE_URL`.

## Environment Variables Explained

### Server Service

- **KHOJ_DEBUG** — Enables debug mode. Default: `False`.
- **E2B_API_KEY** — Key for E2B sandbox. Enables code execution in E2B instead of Terrarium.
- **KHOJ_DOMAIN** — Your Railway public domain.
- **POSTGRES_DB / HOST / PORT / USER / PASSWORD** — PostgreSQL database credentials (auto-provisioned).
- **JINA_API_KEY** — API key for Jina AI (optional, for web search).
- **KHOJ_NO_HTTPS** — Set `True` or `False` to control HTTPS usage. Be cautious when enabling this.
- **GEMINI_API_KEY / OPENAI_API_KEY / ANTHROPIC_API_KEY** — API keys for respective LLM providers.
- **OLOSTEP_API_KEY / FIRECRAWL_API_KEY / SERPER_DEV_API_KEY** — Optional API keys for webpage reading and search.
- **OPENAI_BASE_URL** — Custom URL for OpenAI-compatible providers (e.g., DeepInfra, LMStudio).
- **GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET** — Google OAuth integration.
- **GUNICORN_WORKERS** — Number of Gunicorn workers for scaling.
- **KHOJ_ADMIN_EMAIL / KHOJ_ADMIN_PASSWORD** — Admin credentials for Khoj panel.
- **KHOJ_SEARXNG_URL** — Default URL of SearxNG service.
- **KHOJ_TERRARIUM_URL** — URL of Terrarium sandbox for code execution.
- **KHOJ_ALLOWED_DOMAIN** — Allowed domain for Khoj.
- **KHOJ_OPERATOR_ENABLED** — Enable operator mode (Khoj can use its computer).
- **KHOJ_DJANGO_SECRET_KEY** — Secret key for the Django server.
- **KHOJ_TELEMETRY_DISABLE** — Disable telemetry if desired.
- **KHOJ_DEFAULT_CHAT_MODEL** — Set a default chat model if needed.

### SearxNG Service

- **SEARXNG_BASE_URL** — Base URL for the SearxNG search service.

## Why Deploy Khoj AI on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Khoj AI on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

## Services Overview

To deploy Khoj AI on Railway, multiple services work together to provide a complete and modular AI assistant stack. Here’s a breakdown of each service:

### 1. `pgvector` — Vector Database
- **Image:** `pgvector/pgvector:pg16`
- **Purpose:** This is a PostgreSQL database with the `pgvector` extension enabled. Khoj uses it to store and retrieve embeddings for efficient semantic search.
- **Notes:** Automatically provisioned by Railway. Make sure the connection variables are properly set in the server service.

### 2. `server` — Khoj Backend
- **Image:** `ghcr.io/khoj-ai/khoj-cloud:latest`
- **Purpose:** This is the main Khoj AI backend service that handles all API calls, search orchestration, and model integrations.
- **Notes:** Connects to pgvector and optionally uses external APIs like OpenAI, Gemini, Jina, etc.

### 3. `sandbox` — Terrarium Code Sandbox
- **Image:** `ghcr.io/khoj-ai/terrarium`
- **Purpose:** A secure, isolated sandbox where Khoj can execute Python code. This is used when the agent needs to run code directly.
- **Notes:** Alternatively, you can use an external sandbox with E2B.

### 4. `searxng` — Web Search Engine
- **Image:** `searxng/searxng`
- **Docker Hub:** [https://hub.docker.com/r/searxng/searxng](https://hub.docker.com/r/searxng/searxng)
- **Purpose:** Provides fast, privacy-friendly meta web search. Khoj uses this as the default web search engine when enabled.
- **Notes:** The service URL is referenced in the `KHOJ_SEARXNG_URL` variable.

### 5. `computer` — Operator Mode Service
- **Image:** `ghcr.io/khoj-ai/khoj-computer`
- **Purpose:** Enables “operator mode” where Khoj can interact with the system and execute more advanced workflows.
- **Notes:** Optional but powerful feature for power users. Controlled via the `KHOJ_OPERATOR_ENABLED` environment variable.


## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/khoj-ai
