Skip to content

TypeScript SDK

TypeScript SDK

Server-side client for OAuth and managed-secret credentials. Tokens never leave the SDK.

The TypeScript SDK ships as the @alter-ai/alter-sdk package on npm. Node 18+.

This is the server-side SDK (Node, Bun, Deno, edge runtimes with fetch). It is not for browser code — for the browser-side OAuth widget that opens the consent popup, see the Connect SDK.

Terminal window
npm install @alter-ai/alter-sdk
import { App, Agent, HttpMethod } from "@alter-ai/alter-sdk";

The SDK exposes two top-level clients. They share the request surface but differ in principal and identity scoping.

Both classes are async. Always close them via await app.close() (or wrap usage in try/finally) so background tasks drain and HTTP/2 connections release.

const app = new App({ apiKey: process.env.ALTER_API_KEY! });
try {
const page = await app.listGrants();
} finally {
await app.close();
}

The constructor accepts an apiKey argument; application code is responsible for sourcing it. The convention is to read it from the process environment:

VariableUsed byDescription
ALTER_API_KEYapplication code (typical app workload)Conventional name when the application owns one app-level key.
AGENT_API_KEYapplication code (agent workload)Conventional name when the workload runs as a managed agent.

For agent workloads, the convention is to read AGENT_API_KEY in application code:

import { Agent } from "@alter-ai/alter-sdk";
const agent = new Agent({ apiKey: process.env.AGENT_API_KEY! });
  • Every method is async and returns a Promise. Use await.
  • Models are frozen objects. Field names are camelCase (the wire format is snake_case; the SDK maps automatically).
  • Methods that retrieve tokens never return the token plaintext. The SDK injects it into the outbound request.
  • Public exceptions extend AlterSDKError. See Errors.
  • Time-budget parameters are in milliseconds (matches setTimeout, Date.now()). User-selectable durations passed to the Connect UI are in seconds.