Nirmos

Authentication

Choose a service or personal key, connect the SDK and verify your organization access.

Pass a Nirmos service or personal key to the client through auth. Both use the same SDK configuration and send an x-api-key header with each request.

Your Nirmos key connects your application to an organization. Provider credentials, such as an OpenAI API key, are configured separately in the dashboard.

Choose a key

KeyUse it forPermissions
Service keyApplication servers, background jobs and shared integrationsExplicit scopes selected for the key
Personal keyScripts and tools that act as youYour current roles in the organization bound to the key

Use a service key for workloads that should run independently of an individual user. Use a personal key when actions should carry your user identity, such as submitting an assigned review.

Both key types are bound to one organization. To access another organization, create a separate client with a key for that organization. A request's organizationId cannot change the key's scope.

Generate a key in the dashboard's API keys settings. The quickstart walks through provider setup and your first request.

Connect and verify access

Set NIRMOS_API_KEY in your application's server environment, then pass it explicitly to the SDK:

import { Nirmos } from "@nirmos/sdk";

// Read the Nirmos key from your server environment.
const key = process.env.NIRMOS_API_KEY;
if (!key) throw new Error("Set NIRMOS_API_KEY before starting the application.");

const nirmos = new Nirmos({
  auth: { type: "api-key", key }, // Works with a service or personal key.
});

// Confirm which organization and permissions this key can use.
const context = await nirmos.auth.getContext();
console.log("Organization:", context.organizationId);
console.log("Permissions:", context.permissions);

The SDK does not read environment variables or load .env files for you. Load them through your application before creating the client.

auth.getContext() verifies the key and returns its organization and permissions without returning the credential. Individual endpoints still check the permissions needed for each operation.

If a request fails with 401, check that the key is valid and has not expired or been revoked. For 403, check the key's organization and permissions. See errors and reliability for handling these failures.

Keep keys on the server

Store keys in a server secret store or private environment variables. Keep them out of source control, logs and browser storage. Never expose a key through a NEXT_PUBLIC_ or VITE_ variable.

To rotate a key, create a replacement, deploy it, verify that requests succeed, then revoke the old key.

Supply credentials through auth; per-request headers cannot override authentication. Use advanced authentication if your integration requires the Authorization: Bearer header.

Advanced authentication

Use this option when an integration requires Authorization: Bearer instead of x-api-key. The API verifies the credential as a Nirmos service or organization-bound personal key.

import { Nirmos } from "@nirmos/sdk";

// Store a Nirmos key in this server variable for Bearer transport.
const token = process.env.NIRMOS_BEARER_CREDENTIAL;
if (!token) throw new Error("Set NIRMOS_BEARER_CREDENTIAL before starting the application.");

const nirmos = new Nirmos({
  auth: { type: "access-token", token }, // Sends Authorization: Bearer <token>.
});

// Verify the credential before using other resources.
const context = await nirmos.auth.getContext();
console.log("Organization:", context.organizationId);

The option name access-token does not make an arbitrary OAuth token valid. The SDK only sets the header; it does not issue, exchange or refresh tokens.

Configure authentication through auth. Per-request headers cannot override x-api-key or authorization; avoid setting credentials in default headers too.

On this page