Skip to main content
The TypeScript SDK generator creates modern TypeScript client libraries from your contract definitions. The generated code works across Node.js, Bun, and Deno without modifications, uses native fetch, and provides full type inference with a resource-based developer experience.

Key Features

  • Runtime Agnostic: Works on Node.js 18+, Bun, and Deno
  • Zero Dependencies: Uses native fetch API only
  • TypeScript-First: Full type inference and autocompletion
  • ES Modules: Modern JavaScript with async/await
  • SSE Streaming: First-class AsyncIterable streaming
  • npm-Ready: Includes package.json and tsconfig.json

Quick Start

Step 1: Define Your Contract

Step 2: Generate the SDK

Step 3: Install and Use

Generated Code Structure

package.json

tsconfig.json

Client Configuration

Creating a Client

Configuration Options

Accessing Config

Type System

Type Mapping Reference

Interface Types

Contract struct types generate TypeScript interfaces:

Optional and Nullable Fields

Example:

Enum Fields

Enum fields generate as union types:

Const Fields

Const fields generate as literal types:

Array and Record Types

Union Types (Discriminated)

Union types generate as TypeScript union types:
Usage:

Resources and Methods

Resource Pattern

Each contract resource becomes a property on the client:

Method Signatures

Methods use camelCase naming:

Calling Methods

Streaming (SSE)

For methods with streaming support, the SDK provides AsyncIterable streams:

Basic Streaming

Stream with Cancellation

Collecting Stream Events

Stream Type

The stream object implements AsyncIterable and has an AbortController:

Error Handling

Error Types

The SDK defines three error classes:

Handling Errors

Automatic Retries

The client automatically retries failed requests:
Retries are attempted for:
  • Network errors
  • Timeout errors
Note: 4xx and 5xx errors are NOT retried (they throw immediately).

Advanced Usage

Custom Headers

Authentication Modes

The SDK supports different authentication modes:

Timeout Configuration

Using with Different Runtimes

The SDK works across all modern JavaScript runtimes:

Complete Example

Server

Client Usage

Streaming Example

Installation and Distribution

Installing Locally

Publishing to npm

Installing from Git

Using Without npm

The generated code can be used directly in Deno or Bun without npm:

See Also