Deploy OpenCode OpenRouter

Use any OpenRouter model in your hosted OpenCode

Deploy OpenCode OpenRouter

Just deployed

/data

Deploy and Host self hosted OpenCode OpenRouter (Open-Source AI Coding Agent) on Railway

This template runs OpenCode 1.19.3 with OpenRouter wired in: /connect, paste one key, and pick any model with /models. Built for developers who switch between Kimi, DeepSeek and Claude on the same hosted server.

About Hosting OpenCode OpenRouter open-source software on Railway (self hosted OpenCode with OpenRouter template)

Your repos and your OpenRouter key stay on this service's /data volume: projects under /data/workspace, provider credentials under ~/.local/share/opencode/auth.json. Neither is baked into the image, so redeploys keep both, and deleting the service deletes them.

The template runs OpenCode 1.19.3 in one container on port 4096 behind basic auth. Railway supplies the public domain, TLS, the generated password, restarts and the volume mount.

Why Deploy OpenCode OpenRouter, the Claude Code alternative on Railway (Railway Free Trial)

Claude Code ties you to Anthropic models and Anthropic billing. Here you swap Kimi, DeepSeek or Claude per task through one OpenRouter key, on a server you control. Test it on the $5 Railway trial, no model lock-in at all.

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 OpenCode OpenRouter 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.

Railway vs Other Hosting Providers and VPS for OpenCode OpenRouter self hosting

Railway ships the container, HTTPS domain and the /data volume that keeps your OpenRouter key.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanDomain and volume attached; redeploys keep auth.jsonDroplet you patch, proxy and back up yourself
AWSNo VPC or ALB to wire up before /connect worksECS or EC2 with IAM, EBS and certs you assemble
HetznerNo server to patch, billed by usageCheap servers, but you own backups and upgrades

Either way the key lands in auth.json on disk, so pick the host whose patching and backups you will keep up.

Common Use Cases for hosted OpenCode OpenRouter

  • One key, many models: keep a single OpenRouter key in auth.json and switch between Kimi, DeepSeek and Claude builds with /models instead of juggling separate provider accounts.
  • Cheap model for small tasks: point small_model at a low-cost OpenRouter model so titles, summaries and commit messages stop burning your best model's tokens.
  • New model on day one: add it under provider.openrouter.models and call it as openrouter/VENDOR/MODEL, no template update required.
  • Pin a provider: set provider.order and allow_fallbacks in opencode.json when a model's tool calls behave better on one host.
  • Shared instance: teammates log in with the same username and password and share repos and sessions on /data.

Dependencies for OpenCode OpenRouter Docker hosted on Railway

This template runs one service, opencode, from ghcr.io/onepush-dev/opencode:1.19.3 on port 4096 with a public domain and a single volume at /data. The OpenRouter key can live on that volume or in the service environment, and either way it survives redeploys.

Deployment Dependencies for Managed OpenCode OpenRouter Service (AI Coding Agent)

  • OPENCODE_SERVER_PASSWORD: generated, 32 characters. The server refuses to start when this is empty.
  • OPENCODE_SERVER_USERNAME: opencode, the HTTP basic auth login.
  • OPENROUTER_API_KEY: optional and empty by default. Set it if you'd rather not paste a key in the UI.
  • HOME=/data/home, OPENCODE_WORKSPACE=/data/workspace, PORT=4096, OPENCODE_DISABLE_AUTOUPDATE=true.

Implementation Details for OpenCode OpenRouter (Using OpenCode official docker image)

The entrypoint runs opencode serve --hostname 0.0.0.0 --port 4096, which serves the API and the embedded web UI, with tini as PID 1. Provider credentials from /connect land in ~/.local/share/opencode/auth.json under /data/home.

How does OpenCode OpenRouter compare against other AI coding agents

OpenCode vs Claude Code (Claude Code Alternative)

  • Model freedom: one OpenRouter key swaps between Kimi, DeepSeek and Claude per task in /models.
  • Ownership: Claude Code is proprietary and tied to Anthropic billing; this is MIT and hosted on Railway.
  • Where Claude Code wins: Anthropic tunes its models for its own harness, so long refactors need less steering.

OpenCode vs Codex CLI (Codex CLI Alternative)

  • Provider spread: Codex CLI centers on OpenAI; OpenCode reaches 75+ providers via Models.dev, OpenRouter included.
  • Surfaces: this serves an API plus web UI on port 4096; Codex CLI runs in your terminal.
  • Where Codex CLI wins: a lighter install when you never need a remote host or a browser session.

OpenCode vs Cursor (Cursor Alternative)

  • Remote workspace: Cursor is a local VS Code fork; here repos live in /data/workspace and you sign in from any browser.
  • Billing shape: you pay OpenRouter per token instead of an editor seat on top.
  • Where Cursor wins: tab completion and inline edits are still smoother on big monorepos.

OpenCode vs Aider (Aider Alternative)

  • Shared ground: both are open source and git-native, with undo through snapshots.
  • Extra surfaces: Aider is terminal-first; OpenCode adds a web UI, HTTP API and share links.
  • Where Aider wins: one pip install and a chat loop, which many still prefer for single-file patches.

How to use OpenCode OpenRouter (the OSS AI coding agent)?

  1. Open the Railway domain and sign in with OPENCODE_SERVER_USERNAME and OPENCODE_SERVER_PASSWORD from the Variables tab.
  2. Run /connect, search OpenRouter, paste your key. It lands in ~/.local/share/opencode/auth.json under /data, so it survives redeploys.
  3. Run /models and pick one; many OpenRouter models are preloaded. Not listed? Add it under provider.openrouter.models.
  4. Set your default and a cheap small_model in ~/.config/opencode/opencode.json:
{
  "model": "openrouter/moonshotai/kimi-k2",
  "small_model": "openrouter/deepseek/deepseek-chat"
}
  1. To pin a host, add provider.openrouter.models options with "order": ["baseten"] and "allow_fallbacks": false.

How to self host OpenCode OpenRouter on other VPS Services (OpenCode self hosting guide)

Same server, any VPS.

Clone the Repository

Skip this unless you build the image yourself.

git clone https://github.com/anomalyco/opencode.git

Install Dependencies

Install the CLI, or use the official image ghcr.io/anomalyco/opencode.

curl -fsSL https://opencode.ai/install | bash

Configure Environment Variables

No password means no start. Add the OpenRouter key here or paste it later via /connect.

export OPENCODE_SERVER_USERNAME=opencode
export OPENCODE_SERVER_PASSWORD=change-me
export OPENROUTER_API_KEY=your-key

Put it behind HTTPS so the key and sessions are not sent in the clear.

Start the OpenCode OpenRouter Application

opencode serve --hostname 0.0.0.0 --port 4096

Open https://your-domain, sign in, run /connect or rely on the env var, then pick a model with /models and set model and small_model in ~/.config/opencode/opencode.json. Railway already handles the domain, TLS, basic auth, the /data volume and the health check, so you only supply the OpenRouter key.

Official Pricing of OpenCode OpenRouter (OpenCode pricing)

OpenCode itself is free and open source under MIT. Free OpenRouter models exist but come with tight rate limits, so treat them as evaluation, not production. There are no per-seat license costs, and pointing OpenCode at direct provider keys instead of OpenRouter is supported if you would rather skip the credit fee.

OpenCode OpenRouter cloud vs self hosted comparison (Pricing, features, costs, and more)

The software is identical either way. What changes is who runs the box, who holds the volume, and who pays for what.

Monthly cost of self hosting OpenCode OpenRouter on Railway

Plan on roughly $5-15/mo for the single opencode container at light use, and more during heavy builds or test runs. That covers the service, the /data volume and the domain. Free models keep the token bill near zero if your tasks tolerate them.

System Requirements for Hosting OpenCode OpenRouter on a VPS

Any small Linux VM with Docker, 2 GB of RAM and a few GB of disk is enough to run opencode serve. Give the agent room: node projects and LSPs on /data/workspace grow fast, so 5 GB or more of disk helps.

Frequently Asked Questions (FAQs)

Do I set OPENROUTER_API_KEY or use /connect?

Either works. /connect searches OpenRouter and takes a pasted key; the env var covers fresh deploys with no manual step.

Where is my OpenRouter key stored?

In ~/.local/share/opencode/auth.json, which maps to /data/home on the volume, so redeploys keep it. Check with opencode auth list.

How do I add a model that is not listed?

Add it to provider.openrouter.models in ~/.config/opencode/opencode.json, then pick it with /models. Ids stay openrouter/VENDOR/MODEL.

Can I pin a provider for one model?

Yes: "options": {"provider": {"order": ["baseten"], "allow_fallbacks": false}}. Whitelist and blacklist options hide providers from the picker.

Which OpenRouter models handle tool calls well?

The ones with solid tool-calling support, which you notice fast when edits stop landing. I run Claude or Kimi for build mode and a cheap DeepSeek model as small_model.

Does OpenRouter cost more than direct keys?

It adds a fee on credit purchases and free models are rate limited. Direct keys can be cheaper for a single provider; one key for everything is the trade.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
NEW
Möbius v0.1 Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

bento
1
View Template
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
7