Authentication
Authentication means proving who you are. NuRoute checks a secret code on every request. There are two kinds:
| Token | What it looks like | When to use it |
|---|---|---|
| API key | aicp-… | For servers and apps. Long-lived. Made in the dashboard |
| Session token (a JWT) | A long signed string | You get it from client.auth.login() or client.auth.signup(). It expires after 1 hour. You need it to change settings |
Using an API key
This is the recommended way for code that runs on a server:
from nuroute import NuRouteClient
client = NuRouteClient(
api_key="aicp-...",
base_url="https://your-gateway",
)
Create API keys in the dashboard under Settings → API Keys.
Why can't an API key change settings? An API key has no role. So changing settings (routing, projects, providers), and managing API keys and members, needs an owner's or admin's session token from client.auth.login(). With an API key, those calls are refused with 403.
Signing up
result = client.auth.signup(
org_name="Acme Corp",
email="you@acme.com",
password="super-secret",
user_name="Your Name", # optional
)
# result["token"] is a session JWT
client.set_api_key(result["token"])
Logging in
result = client.auth.login(
email="you@acme.com",
password="super-secret",
)
client.set_api_key(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:
# Inspect the invite link token
info = client.auth.get_invite_info(token)
print(info["email"], info["org_name"])
# Accept and get a session
result = client.auth.accept_invite(
token=token,
name="New Member",
password="my-password",
)
client.set_api_key(result["token"])
Changing the key while the program runs
client.set_api_key("new-aicp-key-or-jwt")
Keep secrets secret
Never put your API key or password in code you share. Keep them in environment variables or a secrets manager.