Skip to main content

Overview

Ravi exposes a typed SDK gateway under /api/v1/*. The gateway is generated from the decorated CLI registry, so SDK clients mirror Ravi commands without hand-maintained API wrappers. The current SDK surfaces are:
  • TypeScript package: packages/ravi-os-sdk
  • Swift package: packages/ravi-os-swift-sdk
  • OpenAPI snapshot: docs/openapi.json
The source of truth is src/cli/registry-snapshot.ts. OpenAPI, TypeScript, and Swift are deterministic projections of that registry.

Start the Gateway

The SDK gateway is mounted on Ravi’s webhook HTTP server. The daemon starts that server only when an HTTP port is configured:
The gateway shares the same listener as webhooks. Requests go to:
If RAVI_HTTP_HOST is not loopback, Ravi refuses to start unless RAVI_GATEWAY_NETWORK_AUTHORIZED=1 is set. This keeps the SDK gateway private by default even when bearer auth is configured. Set RAVI_SDK_GATEWAY_DISABLE=1 to disable SDK routes while leaving the HTTP server available for webhook handlers.

Context Keys

Non-open SDK routes require a runtime context key (rctx_*) in the bearer auth header. Bootstrap the first admin key on the daemon host:
For external apps, issue a narrower child context:
The --allow format is:
Examples:
  • view:system:events for the events stream
  • view:system:tasks for the tasks stream
  • view:system:audit for the audit stream
  • access:session:ravi-web for one session stream

TypeScript Client

Install:
Create a client:
Generated method names follow the CLI shape:
Kebab-case commands become camelCase methods. For example, daemon init-admin-key becomes client.daemon.initAdminKey().

Wire Contract

Every command call is a POST:
The request body is flat JSON. Positional arguments and options are merged at the top level:
Generated clients must not send { "args": ..., "options": ... } wrappers. The HTTP transport sends:
  • Authorization: Bearer <rctx_key>
  • x-ravi-sdk-version
  • x-ravi-registry-hash

Streaming

Use @ravi-os/sdk/streaming for server-sent event streams:
Available streams: Streams always require a valid context key, even when ordinary open commands do not.

Binary Responses

Commands marked with @Returns.binary() return a raw Response on successful 2xx calls. Error responses still map to typed SDK errors.

Error Handling

All transports throw the same error hierarchy:
  • RaviAuthError for 401 responses
  • RaviPermissionError for 403 responses
  • RaviValidationError for 4xx validation failures, with issues[]
  • RaviInternalError for 5xx responses
  • RaviTransportError for network, timeout, or transport failures

Codegen

Regenerate the TypeScript client from the live registry:
Check committed generated files for drift:
Generate the OpenAPI snapshot:
Generate the Swift SDK:
Generated TypeScript files live in packages/ravi-os-sdk/src:
  • client.ts
  • schemas.ts
  • types.ts
  • version.ts
Hand-written SDK files contain transports, error mapping, streaming helpers, and package integration code.

Published Exports

The published TypeScript package exports:
The repo contains an in-process transport at packages/ravi-os-sdk/src/transport/in-process.ts, but it is monorepo-internal and is not exported by the published package.