Skip to main content

Install the JavaScript SDK

An SDK (software development kit) is a ready-made helper for your code. Instead of writing the web requests by hand, you call simple functions like client.chat.complete(), and the SDK does the rest.

The NuRoute JavaScript SDK works in Node.js 18 or newer and in modern web browsers. It uses the built-in fetch feature, so in Node 18 and up you need no extra add-ons ("polyfills").

GitHub

Before you start​

  • Node.js 18 or newer. To check, type node --version in your terminal.
  • An API key that starts with aicp-. Make one in the dashboard under Settings → API Keys (see the Quickstart).
  • Your gateway address, the web address your requests go to.

Step 1: Install​

Use whichever tool you normally use. One of these is enough:

npm install @aicp/sdk
# or
yarn add @aicp/sdk
# or
pnpm add @aicp/sdk

Step 2: Create a client​

A client is the object you use to talk to NuRoute. You make it once and reuse it.

import { NuRouteClient } from '@aicp/sdk';

const client = new NuRouteClient({
apiKey: 'aicp-...', // your API key
baseUrl: 'https://your-gateway', // NuRoute gateway URL
timeout: 30_000, // request timeout in ms (default: 30 000)
});
OptionTypeDefaultWhat it means
apiKeystringnoneYour secret key (a "Bearer token"). You can leave it out and set it later with client.setApiKey().
baseUrlstringhttp://localhost:3000The NuRoute gateway address.
timeoutnumber30000How long to wait for an answer, in milliseconds, before giving up. (30,000 ms is 30 seconds.)

Change the key while the program runs​

After you log in or sign up, NuRoute gives you a session token (a temporary pass). You can start using it without making a new client:

const { token } = await client.auth.login({ email, password });
client.setApiKey(token);

Next step​

Learn which kind of key to use in Authentication, or jump to Chat completions to ask your first question.