Skip to main content

Client

Install the SDK and create a client. The client is the entry point for every SDK call.
pnpm add @tryagent/sdk
import { TryAgent } from "@tryagent/sdk";

const tryagent = new TryAgent({
  apiKey: process.env.TRYAGENT_API_KEY!,
});

Authentication

Provide exactly one of apiKey, token, or getToken. Passing zero or more than one throws at construction.
OptionTypeUse it for
apiKeystringAgent runtimes creating escalations. A workspace key that looks like ain_live_....
tokenstringA static user bearer token. An alternative to a scoped API key for reviewer and read methods.
getToken() => string | Promise<string>A user token fetched lazily per request — refresh it without recreating the client.
// Agent runtime — create escalations with a workspace API key.
const agent = new TryAgent({ apiKey: process.env.TRYAGENT_API_KEY! });

// Reviewer / dashboard — read and decide on behalf of a user.
const reviewer = new TryAgent({
  getToken: () => session.getAccessToken(),
});
Read and reviewer methods (list, get, acknowledge, decide, cancel) work with an ain_live_ API key or a workspace user token/getToken. Keys are issued with all escalation scopes (escalations:write, :read, :acknowledge, :decide, :cancel) by default; pass a narrower scopes array to POST /api-keys to restrict one. A call missing the scope returns 403.

Options

OptionDefaultDescription
baseUrlhttps://api.tryagent.aiOverride only for local development or tests.
fetchglobal fetchSupply a custom fetch implementation (proxies, instrumentation, non-standard runtimes).
const tryagent = new TryAgent({
  apiKey: process.env.TRYAGENT_API_KEY!,
  baseUrl: "http://localhost:4000",
});

Resources

  • Escalations — create, read, and decide on escalations.
  • Webhooks — verify signed resume callbacks.
  • Errors — handle API, network, and signature failures.