Skip to content

Reference

TypeScript SDK

Server-side Node.js client for credential-injected provider calls.

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

This is a server-side Node.js SDK. It uses Node-only APIs and is not supported in browsers, Bun, Deno, or edge runtimes. 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 pending work completes and the client rejects subsequent use deterministically.

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! });
try {
const info = await agent.me();
console.log(info.status);
} finally {
await agent.close();
}
  • I/O and lifecycle methods are asynchronous and return a Promise. Use await.
  • Model class instances are frozen. 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.

Report an issue with this page

Necessary

Required for sign-in, security, authorization, and remembering your choices.

Always active

Analytics

Helps us understand which product and documentation features are useful.

Performance diagnostics

Uses performance tracing and privacy-masked session replay to diagnose problems.

You can change these choices at any time from Cookie settings.