Authentication
Authentication means proving who you are. NuRoute checks a secret code, called a Bearer token, on every request. There are two kinds:
| Token type | What it looks like | When to use it |
|---|---|---|
| API key | aicp-… | For servers and apps. Long-lived. Created in the dashboard |
| Session JWT | A standard JWT | You get it from auth.login() or auth.signup(). It expires after 1 hour. You need it to change settings: an API key has no role, so changes to routing, projects, providers and API keys made with one are refused with 403 |
(A JWT is a signed pass that proves you logged in.)
Either one is sent as a Bearer token:
Authorization: Bearer aicp-...
The SDK does this for you.
Using a permanent API key
For code that runs on a server, create an API key in the dashboard (Settings → API Keys) and pass it in:
const client = new NuRouteClient({
apiKey: 'aicp-...',
baseUrl: 'https://your-gateway',
});
API keys do not expire, unless you set an expiry when you create them or you delete them.
Signing up
const result = await client.auth.signup({
orgName: 'Acme Corp',
email: 'you@acme.com',
password: 'super-secret',
userName: 'Your Name', // optional
});
// result.token is a session JWT, set it on the client
client.setApiKey(result.token);
Logging in
const result = await client.auth.login({
email: 'you@acme.com',
password: 'super-secret',
});
client.setApiKey(result.token);
Accepting an invitation
When a teammate invites you, they send a link that contains a token. Use it to choose your password and start a session:
// First, inspect the invite
const info = await client.auth.getInviteInfo(token);
console.log(info.email, info.orgName);
// Then accept and get a session
const result = await client.auth.acceptInvite({
token,
name: 'New Member',
password: 'my-password',
});
client.setApiKey(result.token);
Keep secrets secret
Never put your API key or password in code you share, or in web page code that visitors can read. Keep them in environment variables or a secrets manager.