> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsair.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Railway plugin

> Projects, environments, services and service instances, deployments with logs, deploy, redeploy, restart and rollback, variables, domains and TCP proxies, volumes and backups, buckets, databases, templates, GitHub repo deploys, workspaces, members, invitations and tokens, notification rules, observability dashboards, metrics, HTTP logs and traces, usage limits, sandboxes and cloud agents (394 operations over Railway's public GraphQL API).

Use **Railway** through Corsair: one client, typed API calls.

Connect with a Railway token from railway.com/account/tokens: an account
token reaches every workspace you are in, a workspace token one workspace.
Both go out as `Authorization: Bearer <token>`. A project token (from a
project's settings) works with `tokenKind: 'project'` in the plugin
options and reaches only that project's environment.

* **One operation per GraphQL field.** Every query and mutation of
  Railway's public API (`backboard.railway.com/graphql/v2`) is an operation;
  its input is the field's arguments, mostly an `input` object for mutations.
  The plugin sends a fixed document per operation that selects the result's
  scalar and enum fields and the scalars of each nested object. Fields that
  need arguments, connections inside a result (a project's services come
  from their own list operation) and fields API tokens can't read
  (`User.platformFeatureFlags`) are left out.
* **Lists.** Relay connections (projects, deployments, environments, ...)
  take `first`/`after` (or `last`/`before`) and return `{ items, pageInfo }`;
  pass `pageInfo.endCursor` as `after` for the next page. A few lists page
  their own way (`cloudAgentTasks.list` returns `nextCursor` and takes
  `cursor`): their output says which fields to use.
* **Errors.** Railway answers most failures with HTTP 200 and a GraphQL
  `errors` list; the plugin raises them as `RailwayGraphQLError` with a
  status (403 for "Not Authorized", 404 for a missing record, 429 for
  "too many requests" or "too quickly", 400 otherwise). When the only
  errors are inside the result (an audit log entry whose project was
  deleted), the call succeeds and those nested fields come back null.
* **Risk.** Queries are `read`. Deletes, deploys, redeploys, restarts,
  rollbacks, template and repo deploys, new services, environments,
  volumes, buckets, sandboxes and cloud agents (all use credits), tokens and
  credential resets, invitations (they send email), billing and usage limits,
  restores and transfers are `destructive`; other mutations are `write`.
* Not wrapped: Railway's CLI telemetry and login-session fields, its staff
  and careers fields, the dashboard's landing and X-agent claim state, email
  change and second-factor/passkey setup (they need a person at the
  dashboard), and fields Railway marks deprecated. Railway's project
  webhooks are not signed, so the plugin has no webhook handlers.

**What you get:**

* 394 typed API operations

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/railway better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/railway better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/railway better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/railway better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { railway } from '@corsair-dev/railway';

export const corsair = createCorsair({
	plugins: [
		railway(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the Railway API key before the first call: `pnpm corsair setup --plugin=railway --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> railway()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'railway',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**List projects**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.railway.api.projects.list({ first: 20 });
```

**Set a service variable**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.railway.api.variables.upsert({
	input: {
		projectId: '00000002-5c1e-4d8a-9f43-2b6e1c0a9d17',
		environmentId: '00000003-5c1e-4d8a-9f43-2b6e1c0a9d17',
		serviceId: '00000004-5c1e-4d8a-9f43-2b6e1c0a9d17',
		name: 'API_URL',
		value: 'https://api.example.com',
	},
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/railway/api.md) page.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/railway/api.md)
>
> Every `railway.api.*` operation with input and output types.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.