Skip to main content

SDK quickstart for TypeScript

This quickstart installs the typed Agent Router SDK for TypeScript, then makes a first read-only identity lookup (whoami) against the gateway. The lookup resolves the identity behind an API key with a GET /v1/me call and is safe to run as-is, so it confirms that the SDK, the key, and the base URL are wired together correctly before any billable request is sent.


Prerequisites

Two values and a runtime are required before starting:

  • An Agent Router API key. Keys are minted in the Console or with the tare CLI. The secret is shown once, in the form <keyid>.<secret>, so it must be copied immediately. See Make an API call for the key-minting steps.
  • The gateway base URL for the deployment, in the form https://api.<your-domain>. For the hosted service this is https://api.tetrate.ai.
  • Node.js 18 or later, which provides the npm and npx commands used below.

The SDK reads both values from the environment:

export AGENTROUTER_BASE_URL=https://api.<your-domain>
export AGENTROUTER_API_KEY=<keyid>.<secret>

Install the SDK

The TypeScript SDK is distributed as an npm pack (.tgz) from the public stable channel and is recorded as a local file: dependency rather than installed from the public npm registry. Replace <version> with the version shown on the SDKs page.

Download the pack into the project directory:

curl -fLO https://tare.tetrate.ai/tools/sdks/stable/agentrouter-typescript-<version>.tgz

Create package.json and tsconfig.json alongside it. The SDK is referenced as a file: dependency, and tsx is included to run the example without a separate build step:

package.json
{
"name": "agentrouter-quickstart",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"@tetrate/agentrouter-sdk": "file:agentrouter-typescript-<version>.tgz"
},
"devDependencies": {
"@types/node": "^20.0.0",
"tsx": "^4.0.0",
"typescript": "^5.4.0"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}

Install the dependencies:

npm install

Make the first call

Save the program below as index.ts. It constructs a client from the two environment variables, calls client.me.get() (the read-only GET /v1/me endpoint), and prints the resolved identity.

index.ts
// Runnable example for the Agent Router TypeScript SDK.
// Set AGENTROUTER_BASE_URL and AGENTROUTER_API_KEY in the environment, then run `npx tsx index.ts`.
import { Client } from '@tetrate/agentrouter-sdk'

const client = new Client({
baseUrl: process.env.AGENTROUTER_BASE_URL,
apiKey: process.env.AGENTROUTER_API_KEY,
})

try {
const result = await client.me.get()
console.log(result)
} catch (err) {
console.error('Error:', err)
}

Run the program from the project directory:

npx tsx index.ts

A successful run prints the identity associated with the API key. Because GET /v1/me only reads identity metadata, the call incurs no model usage and can be repeated freely while verifying setup.