Remotehost Docs

API Reference

The REST API behind the CLI and console

The remote CLI and the console use the same REST API. This page covers what every request shares: authentication, limits, errors and polling. Each operation has its own page in the sections below, generated from the API's OpenAPI contract with its parameters, request body, responses and code samples.

The CLI defaults to https://api.remotehost.ai; set REMOTEHOST_API_URL=http://localhost:8787 for local development. The console uses NEXT_PUBLIC_API_URL.

Operations

SectionWhat it covers
IdentityWho the calling token belongs to
OrganizationsOrganizations you belong to, their plans and slugs
ProjectsProjects, their repositories, integrations and members
SandboxesCreate, sleep, wake, resize, renew and destroy
CommandsRun a command and wait for it
FilesRead and write beneath /code
PreviewsTeam and public links to a sandbox port
MetricsLive and sampled resource usage
Agent sessionsDrive coding agents inside sandboxes; see the guide
Agent tokensPersonal tokens for agents acting as you
UsageMachine hour usage for the billing period
API keysOrganization-bound keys for scripts, CI and platforms

OpenAPI and SDK

Download the deployed OpenAPI document for machine-readable request and response schemas. Its server URL includes /v1; paths on this page include that prefix explicitly.

The TypeScript SDK is generated from the same contract. It exposes sandbox resources and a typed remotehost.raw client for operations without convenience methods. The contract covers the core sandbox workflow, project reads and updates, identity, usage, API-key management and agent sessions. Console-only administration routes are added incrementally; see routes outside the contract.

Authentication

Every /v1 request requires an Authorization: Bearer <token> header. Two kinds of token work.

curl https://api.remotehost.ai/v1/me/orgs \
  -H "Authorization: Bearer $REMOTEHOST_TOKEN"

Session tokens are what remote login stores at ~/.config/remotehost/config.json. They carry the full permissions of the signed-in user, so they suit an interactive client, not an unattended one. The access token lasts an hour and is renewed with a refresh token stored beside it. The refresh token lasts 90 days from its last use, so a machine in regular use stays signed in and one left idle for 90 days has to sign in again.

Every refresh returns a new refresh token and retires the one you sent. Store the new one and discard the old. Two refreshes that send the same token within 10 seconds of each other, from two processes say, both get the same new token. Sending a retired token at any other time means someone else may hold a copy, so the whole session is signed out and must sign in again.

Each signed-in CLI, desktop or console is a session you can see and end:

curl -H "Authorization: Bearer $TOKEN" https://api.remotehost.ai/v1/me/sessions

Each session lists the user agent and IP address it signed in with (createdUserAgent, createdIp) and those of its latest refresh (lastUserAgent, lastIp), so a client you don't recognise stands out. Each pair describes one request. The IP address is shown once edge trust is live; until then, and whenever it can't be established, it is null, which means unknown. The user agent is null too when the client sent none, and for sessions from before these were recorded. All four are cleared when the session is revoked, and within the sweep interval (default one hour) of it expiring.

Each session has a clientKind: cli, desktop, console or unknown. RemoteHost sets it when the session is created, so it is reliable where the free-text client label is not.

DELETE /v1/me/sessions/{id} signs out one session, DELETE /v1/me/sessions/current signs out the one making the request, and DELETE /v1/me/sessions signs out every other one. A signed-out session cannot refresh, and its access tokens stop working within 30 seconds, including for opening new terminals. Terminals and tunnels it already has open close within a minute. API keys, agent tokens and preview links created while the session was live keep working until you revoke them.

API keys (rh_sk_...) are the credential for scripts, CI, the MCP server, and building a platform on RemoteHost. Mint one with remote keys create; it is shown once and stored only as a hash. A key ends in a checksum, so a mistyped or truncated key is refused before it is looked up, and a leaked one can be recognised by secret scanners.

Keys created before the rh_sk_ format start with rh_ and have been revoked; create a new key. A key that starts rh_sb_ is one RemoteHost gave a sandbox for Claims, which has been removed: no new one is issued, every one that existed has been revoked, and the API answers 401 with code: "invalid_credential" for it, as for any key that is not valid. They are not in your key list.

A key acts as the user who created it, inheriting exactly their permissions and never more, and is additionally limited to one org and to a fixed set of routes: it can create and read projects, drive sandboxes, mint and revoke preview links, and read usage, but cannot create orgs, touch billing, send invitations, connect agent credentials, delete a project, or mint another key. Those need a session token.

A key's effective permissions are the intersection of its scopes, the creator's current permissions, and the route allow-list. A key always belongs to one organization.

Every key is created with two explicit choices:

  • What it may do: a list of scopes, a template, or unscoped: true (everything its creator can do). [] grants no permissions. The templates are ci (create, run in and clean up sandboxes), read-only, platform (everything a platform backend needs, see Platform) and agent-watcher (read agent sessions). The claims template was removed with Claims in version 2.0.0 of the API: a request that names it is refused with 400 and code: "template_removed", and claims.use is no longer a permission, so a request whose scopes name it is refused with 400 too. Existing keys lost the claims.use scope, and a key that held nothing else has been revoked.
  • When it stops: expiresInDays (1 to 365) or neverExpires: true.

A request missing either choice is refused with 400.

Authentication errors

Statuserror.codeMeaningWhat to do
401noneNo Authorization: Bearer header was sent.Send a token.
401invalid_credentialThe token was refused.Sign in again, or check the key.
401reauthentication_requiredThe token is valid, but the action needs a fresh sign-in (approving a device code when the approver's account can no longer be found).Follow error.message.
403account_cannot_sign_inThe token is valid, but its account (a service account) cannot sign in.Use an API key for that account instead.
403email_not_verifiedThe sign-in is valid, but the email address is not verified with the sign-in provider.Verify the address, wait a minute, and sign in again.
403sign_in_refusedThe sign-in is valid, but the account cannot be completed.Contact support.

invalid_credential is the answer for every refused bearer token. For an API key, that means one that is malformed, unknown, revoked, expired or in a retired format. For a session token, it means one that is invalid, expired or signed out. The response is the same whatever the reason. The message is always "Invalid credential.".

Match on error.code, never on error.message. For invalid_credential, show your own prompt to sign in again. For any other code, error.message is written to be shown to the person as it is.

A WebSocket upgrade (terminals, tunnels) has no response body. It refuses a bearer token with the status line 401 Invalid credential, and a valid token whose account cannot sign in with 403 Sign-in refused.

Create a key

A signed-in user with api_keys.manage can call:

curl https://api.remotehost.ai/v1/orgs/$ORG_ID/api-keys \
  -H "Authorization: Bearer $REMOTEHOST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"usage reporter","expiresInDays":30,"scopes":["billing.read"]}'

The 201 response contains { "apiKey": { ... }, "token": "rh_sk_..." }. Save the token securely; it cannot be retrieved again. Listing, rotating and revoking keys also require a user session; an API key cannot manage other keys. See API keys.

Rotate a key

POST /v1/orgs/{orgId}/api-keys/{keyId}/rotate mints a successor with the same name, scopes and lifetime, and ends the old key after overlapHours (default 24, at most 168; 0 ends it now), so you can deploy the new token before the old one stops. The response has the new token and the old key's new expiresAt. Only the person who created a key can rotate it.

Rate limits

Keys are rate limited to 600 requests a minute per API instance, with a token bucket that refills continuously. This is a runaway-request guard, not a global quota. Over the limit, the API returns 429 with a Retry-After header.

Sandbox starts have separate plan limits. A refused start returns 429 with error.code set to rate_limited (start rate; see retryAfterSeconds and resetsAt) or limit_reached (concurrent sandboxes; see limit and active).

Usage guardrails

Org admins can set a hard sandbox machine hour cap and whether overage is allowed:

PATCH /v1/orgs/:orgId/subscription/usage-guardrails
Request body
{
  "sandboxMachineHourLimit": 250,
  "sandboxOverageEnabled": false
}

For project-level blast-radius control, org admins can set a project cap:

PATCH /v1/orgs/:orgId/projects/:projectId/usage-guardrails
Request body
{
  "sandboxMachineHourLimit": 50
}

Set sandboxMachineHourLimit to null to remove the project cap. A project cap is enforced inside the org cap and uses the same billing period as the subscription. Add ?projectId=:projectId to the usage endpoint to return project-scoped usage and alert state.

At the org level, null falls back to the catalog included allowance when overage is disabled. When overage is enabled and no explicit cap is set, usage may continue without a catalog cap for custom contracts.

The usage response exposes both the effective cap and the explicit override. sandboxMachineHourLimit is the cap enforced for the current period, while sandboxMachineHourLimitOverride is null when the subscription is using its default included allowance.

Lifecycle polling and retries

Poll GET /v1/sandboxes/:sandboxId to observe provisioning and lifecycle changes. The platform does not currently deliver customer lifecycle webhooks. SDK creation waits for readiness by default; use waitForReady: false to receive the provisioning response immediately.

The SDK retries safe GET/HEAD requests on transient failures, respecting Retry-After. It does not automatically retry writes. If a create request loses its response, inspect the sandbox list before submitting another create: a timeout does not prove that the first operation failed.

Errors

Error responses are { "error": { "message": "<message>" } } with a matching HTTP status code: 400 for invalid input, 401/403 for auth and membership failures, 402 for billing issues, 404 for missing resources, 409 for plan and state conflicts, 413 for a request body over the route's limit, 429 for rate limits, 500 for provisioning or database failures, and 503 when a sandbox's host is restarting, draining or unreachable.

Some errors also carry error.code so a client can act without parsing the message: rate_limited, limit_reached, plan_required (the profile needs a higher plan; see minimumPlan), and snapshot_in_progress (waking a sandbox whose snapshot is still being written; retry in a few seconds). host_unavailable (503) means the sandbox's host was restarting, draining or unreachable when a create, wake, sleep or destroy reached it. With retryable: true nothing was changed: send the same request again after Retry-After (retryAfterSeconds). With retryable: false the request may have been partly carried out (a sleep, for one, has already stopped billing); read the sandbox's status before trying again. A host that refuses for capacity answers 429 with no error.code, and one with no record of the sandbox answers 404. body_too_large comes with the route's limit in bytes as limit: 1 MiB for most routes, 5 MiB for writeSandboxFile (whose file content is still at most 2 MiB) and the MCP endpoint, and 16 KiB for the sign-in routes. An oversize body is never read past the limit: it is refused at once when its Content-Length says so, or at the first chunk past the limit when it is sent chunked. A chunked body must arrive in full within 30 seconds, or the answer is 408 with body_timeout. invalid_body (400) means the request body could not be read, is not JSON, is not a JSON object, or does not match what the operation takes; nothing was done. Send JSON; the Content-Type is not checked, but application/json is what to send. An empty body is a 400 where the operation needs a body, and a request with none of the fields where every field is optional. An operation that takes no body refuses any, an empty JSON object included, with invalid_body too; send none. For the authentication codes (invalid_credential, reauthentication_required, account_cannot_sign_in, email_not_verified and sign_in_refused), see Authentication errors.

Every response, successful or not, carries an X-Request-Id header. Quote it when you ask about a response, especially a refused one: it identifies the request and the access decision that answered it.

Routes outside the contract

These routes serve the console and CLI and are not yet in the OpenAPI document. Most need a session token.

Method & pathDescription
GET /healthUnauthenticated liveness check
POST /v1/orgsCreate an org
GET /v1/orgs/:orgId/membersList org members
GET /v1/orgs/:orgId/activityOrg activity feed (lifecycle events)
PATCH /v1/orgs/:orgId/subscription/usage-guardrailsSet the org sandbox cap and overage policy
PATCH /v1/orgs/:orgId/projects/:projectId/usage-guardrailsSet a project sandbox cap
POST /v1/orgs/:orgId/billing/checkoutStart a Stripe checkout session for a plan
GET /v1/orgs/:orgId/invitationsList pending invitations
POST /v1/orgs/:orgId/invitationsInvite a member by email
DELETE /v1/orgs/:orgId/invitations/:invitationIdRevoke a pending invitation
GET /v1/invitations/:tokenLook up an invitation by its token
POST /v1/invitations/:token/acceptAccept an invitation as the authenticated user

On this page