# TypeScript SDK

Install @urouter/sdk for Node.js 22 or later. Use the same ES module in TypeScript and JavaScript projects.

[Source on GitHub](https://github.com/uRouter/urouter-typescript)

[SDK examples](https://github.com/uRouter/urouter-typescript/tree/v0.1.0/examples)

## Install the SDK

```sh
npm install https://github.com/uRouter/urouter-typescript/releases/download/v0.1.0/urouter-sdk-0.1.0.tgz
```

## Send a text request

Create an inference key in Developer → API Keys. Eligible calls use Plan usage first, then paid credit. Keep the key in UROUTER_API_KEY on your server. The clients connect to https://api.urouter.net/v1 by default.

Choose an available text model from Models & Pricing and set UROUTER_MODEL to its exact ID. Review the model’s required credit for a 256-token output limit before running the example.

[Models & Pricing](/developers/catalog/models)

Set UROUTER_OPERATION_ID to a new UUID for this request and save it with your work. Run the example once to send a paid Responses request and print the result.

quickstart.mjs

```javascript
import { URouter, outputText } from '@urouter/sdk';

const apiKey = process.env.UROUTER_API_KEY;
const model = process.env.UROUTER_MODEL;
const key = process.env.UROUTER_OPERATION_ID;
if (!apiKey || !model || !key) throw new Error('Set the API key, model and operation ID.');

const client = new URouter({ apiKey, baseURL: process.env.UROUTER_BASE_URL });
const result = await client.responses.create(
  { model, input: 'Explain DNS in one sentence.', max_output_tokens: 256 },
  { idempotencyKey: key, onResponse: ({ requestId }) => console.log('Request ID:', requestId) },
);
console.log(outputText(result));
```

```sh
node quickstart.mjs
```

## Recover a request

Keep the HTTP request ID (req_…) and the operation’s idempotency key. If a stream disconnects or the outcome is unclear, look up the original request. Read its execution and financial states separately before deciding whether to send another request.

```javascript
const status = await client.requests.get(requestId);
```

## Handle an agent’s tool call

Declare the functions your app supports. When the model returns a function_call, check its name and arguments, apply your app’s approval policy, then run the approved action locally. Send a function_call_output with the same call_id. Each continuation is a new inference request.

[Run tools in your client](/developer/api-docs/responses#responses_tools)

[Example with approve, edit, and cancel decisions](https://github.com/uRouter/urouter-typescript/blob/v0.1.0/examples/tools.ts)

- [Models & pricing](/developer/api-docs/models)
- [Responses](/developer/api-docs/responses)
- [Errors & recovery](/developer/api-docs/errors)
- [Reseller API](/developer/resellers/api)
