---
seo:
  description: >-
    varsafe stores environment variables — database URLs, API keys, signing
    secrets — encrypted at rest, and hands them to the process that needs them
    without…
sidebar:
  label: Overview
title: varsafe API
---
varsafe stores environment variables — database URLs, API keys, signing secrets — encrypted at rest, and hands them to the process that needs them without writing a `.env` file to disk.

### When to use this API

- Inject a project environment into a process or pipeline (`GET /secrets/inject`).
- Read one secret value at the moment it is needed (`GET /secrets/value`), rather than caching a whole environment.
- Create, update or delete secrets from automation (`POST /secrets`, `POST /secrets/bulk`).
- Discover what a credential may do before acting (`GET /me/cli`, `GET /capabilities`).

If you are an AI agent, prefer the Model Context Protocol endpoint at `POST /mcp` over these REST routes: it exposes the same capabilities as typed tools with per-tool scope enforcement and a consent step. See https://docs.varsafe.dev/guides/mcp.

### Authentication

Read the `security` field on each operation — it is derived from what the guards and handlers actually accept, and it is not uniform.

Most routes take an **API token** (`Authorization: Bearer …`), created self-serve in the dashboard and scopable to a project, an environment and read-only access. Routes carrying `x-varsafe-cli-scopes` also accept a **CLI grant** from the device authorization flow and enforce the listed scopes. Four routes are narrower: `GET /me/cli` and `POST /auth/cli/logout` answer only to a CLI grant, because both describe or revoke that grant itself; `POST /auth/cli/device/token` and `GET /auth/cli/device/events` authenticate with the device code rather than an account. `GET /me` accepts a session or a CLI grant but not an API token. The MCP endpoint at `POST /mcp` uses **OAuth 2.1**, or an API token, with the scope vocabulary in `components.securitySchemes.varsafeMcpOAuth`.

### Responses

Every operation documents its success body with a JSON Schema under `components.schemas`, and every failure with the body the server actually sends: `ErrorResponse` (branch on its `code`) for REST routes, `OAuthErrorResponse` and `JsonRpcErrorResponse` for the MCP transport. The schemas are generated from the same Zod definitions the handlers are type-checked against and that the `@varsafe/shared` package exports. Objects list the properties sent today; a later release may add one, so ignore properties you do not recognise. Streaming routes (`text/event-stream`) describe their events in prose.

### Scope of this document

This is the programmatic surface: the routes a token, a CLI grant or an agent may call. Dashboard-only and administrative routes are intentionally not described here. The same document is served at https://varsafe.dev/openapi.json and https://api.varsafe.dev/openapi.json.

Version 1.0.0

Base URL: `https://api.varsafe.dev`

## Capabilities

What this deployment supports, so a client can adapt instead of probing.

- [`GET /capabilities`](/api/capabilities/capabilities-controller-get) — Get server capabilities.

## CliDeviceAuth

Device authorization grant — how a CLI or an unattended agent obtains a credential.

- [`POST /auth/cli/device`](/api/cli-device-auth/cli-device-auth-controller-start) — Start device authorization.
- [`POST /auth/cli/device/token`](/api/cli-device-auth/cli-device-auth-controller-token) — Exchange a device code for a CLI credential.
- [`GET /auth/cli/device/events`](/api/cli-device-auth/cli-device-auth-controller-events) — Stream device-approval events.

## CliSession

Lifecycle of a CLI grant, including self-revocation.

- [`POST /auth/cli/logout`](/api/cli-session/cli-session-controller-logout) — Revoke the calling CLI credential.

## Environments

Environments within a project — development, staging, production, and any others.

- [`GET /projects/{projectId}/environments`](/api/environments/environments-controller-list) — List environments in a project.

## Health

Liveness and readiness probes.

- [`GET /health/live`](/api/health/health-controller-live) — Liveness check.
- [`GET /health/ready`](/api/health/health-controller-ready) — Readiness check.

## Keypairs

Per-environment keypairs used to encrypt values into a committable .env file.

- [`GET /environments/{envId}/keypair`](/api/keypairs/keypairs-controller-get) — Get an environment public key.
- [`POST /environments/{envId}/sealing-key`](/api/keypairs/keypairs-controller-ensure-sealing-key) — Get or create an environment sealing key.
- [`POST /environments/{envId}/sealed-values/open`](/api/keypairs/keypairs-controller-open-sealed-values) — Open an encrypted .env file.

## McpTransport

Model Context Protocol endpoint over Streamable HTTP.

- [`POST /mcp`](/api/mcp-transport/mcp-transport-controller-handle-post) — MCP transport (JSON-RPC request).
- [`GET /mcp`](/api/mcp-transport/mcp-transport-controller-decline-event-stream) — MCP transport (no event stream).
- [`DELETE /mcp`](/api/mcp-transport/mcp-transport-controller-handle-delete) — MCP transport (end session).

## Me

The identity and authority behind the calling credential.

- [`GET /me/verify`](/api/me/me-controller-verify) — Verify the calling credential.
- [`DELETE /me/token`](/api/me/me-controller-revoke-own-token) — Revoke the calling API token.
- [`GET /me`](/api/me/me-controller-me) — Get the current identity.
- [`GET /me/cli`](/api/me/me-controller-whoami-cli) — Get the CLI grant behind the credential.

## OAuthProviderWellKnown

RFC 8414 and RFC 9728 discovery documents for the OAuth 2.1 flow.

- [`GET /.well-known/oauth-authorization-server`](/api/o-auth-provider-well-known/o-auth-provider-well-known-controller-authorization-server) — OAuth 2.1 authorization server metadata.
- [`GET /.well-known/oauth-protected-resource`](/api/o-auth-provider-well-known/o-auth-provider-well-known-controller-protected-resource-root) — Protected resource metadata.
- [`GET /.well-known/oauth-protected-resource/mcp`](/api/o-auth-provider-well-known/o-auth-provider-well-known-controller-protected-resource-mcp) — Protected resource metadata for the MCP endpoint.

## Projects

Projects, the top-level grouping that owns environments and secrets.

- [`GET /projects`](/api/projects/projects-controller-list) — List projects.

## PublicOpenApi

This contract, as a machine-readable document.

- [`GET /openapi.json`](/api/public-open-api/public-open-api-controller-get) — Get this OpenAPI document.

## SecretComposition

How secrets reference one another through $&#123;KEY&#125; templates.

- [`GET /secrets/composition`](/api/secret-composition/secret-composition-controller-composition) — Get the secret composition graph.

## Secrets

Reading, writing and resolving secrets. The core of the API.

- [`POST /secrets`](/api/secrets/secrets-controller-create) — Create a secret.
- [`GET /secrets`](/api/secrets/secrets-controller-list) — List secrets.
- [`POST /secrets/bulk`](/api/secrets/secrets-controller-create-bulk) — Create or update secrets in bulk.
- [`GET /secrets/with-values`](/api/secrets/secrets-controller-list-with-values) — List secrets with values.
- [`GET /secrets/value`](/api/secrets/secrets-controller-get-value) — Read one secret value.
- [`GET /secrets/inject`](/api/secrets/secrets-controller-inject) — Resolve an environment for injection.
- [`GET /secrets/diff`](/api/secrets/secrets-controller-diff) — Diff two environments.
- [`DELETE /secrets/{secretId}`](/api/secrets/secrets-controller-delete) — Delete a secret.
- [`POST /secrets/delete-bulk`](/api/secrets/secrets-controller-delete-bulk) — Delete secrets in bulk.
