Skip to main content
Read agent records from a server-side TypeScript application using Node.js fetch. This example checks your API key, adds a timeout, validates response fields, and supports pagination.
The first-party Threetone TypeScript SDK is planned. No verified installable release has been identified. This example uses built-in Node.js APIs and has no Threetone package installation or import.

Before you start

Use Node.js 24 or later and a personal API key with permission to read agents. Set THREETONE_API_KEY in your server environment. Do not expose it through a public environment variable or browser bundle. The .mts example uses Node.js TypeScript support. You do not need an additional HTTP library to run it.

Read a page of agents

Save this as list-agents.mts. It reads up to 20 agents through List agents.
list-agents.mts
Run the file in the environment that contains your key:
A successful request prints the ID and name of each returned agent, followed by whether another page is available. An empty list prints no agent rows. The parser validates only the fields this example consumes. TypeScript types alone do not validate JSON received over the network. The request aborts after 30 seconds. Redirects are disabled to avoid forwarding the API key to another destination.

Read the next page

When page.has_more is true and page.next_cursor is a string, pass it to listAgents(apiKey, page.next_cursor). Continue with each newly returned cursor until has_more is false. Keep cursor values unchanged. page_size accepts 1 to 100 and defaults to 30 when omitted. The example uses 20. Keep any filters unchanged between pages. Use Get agent to inspect one agent’s complete saved configuration.

Troubleshoot a request

For 401, check the key and its expiry. For 403, check its permissions and workspace access. For 429, follow Retry-After when supplied. Read Errors and retries before adding automatic retries. The error context includes the method, path, status, and a JSON-escaped request ID limited to 128 characters. It excludes the key and response body. A connection failure or timeout may have no response status or request ID.

Frequently asked questions

No verified first-party package release is documented yet. The SDK is planned. This example runs with Node.js and does not install a Threetone package.
Keep this request on your server because it uses a personal API key. Let browser code call your own authenticated server route.
No. Node.js removes the supported type syntax when running this file. The explicit response checks validate the fields used by the example. Run your project’s TypeScript checker separately.