Nirmos

SDK quickstart

Install the Nirmos SDK, configure provider credentials and generate your first chat completion.

Use this guide from a trusted Node.js application to send your first chat request through Nirmos. You need a Nirmos organization, a trusted Node.js application with Fetch/Web Crypto support, and provider credentials for an accessible chat model. Use a current Node.js LTS release; install tsx if you prefer running the example as TypeScript.

Install Nirmos SDK

pnpm add @nirmos/sdk
npm install @nirmos/sdk
yarn add @nirmos/sdk
bun add @nirmos/sdk

The generated reference records the SDK version these docs track. Check your installed version when comparing method signatures.

Configure provider credentials and generate an API key

In the Nirmos Dashboard, select the organization you will use for requests.

  1. Open Provider credentials, select Add credential, and enter your provider's credentials and required configuration.
  2. Open API keys and generate a service API key with gateway execution permission (gateway:execute). Keep the key in a server secret store or environment variable.
  3. Open Available models and choose an active chat model for your configured provider. Use its provider slug and model slug in the next step.

The provider credential and Nirmos API key must belong to the same organization. Available models have active organization credentials; upstream access, quota and model permissions still determine whether a request succeeds.

Set the Nirmos API key in the terminal where you will run the example:

export NIRMOS_API_KEY="<your-nirmos-api-key>"

Your provider credentials stay in the dashboard. Pass the Nirmos API key to the SDK.

Authenticate and generate a chat completion

Save the following as quickstart.mjs. Replace <provider-slug>/<model-slug> with the provider and model slugs for your selection in Available models.

quickstart.mjs
import { Nirmos, NirmosError } from "@nirmos/sdk";

const key = process.env.NIRMOS_API_KEY;
if (!key) throw new Error("Missing NIRMOS_API_KEY");
const nirmos = new Nirmos({
  auth: { type: "api-key", key },
  apiBaseUrl: process.env.NIRMOS_API_URL,
  runtimeBaseUrl: process.env.NIRMOS_RUNTIME_URL,
});

try {
  const context = await nirmos.auth.getContext();
  console.log("Organization:", context.organizationId);

  const completion = await nirmos.gateway.chat.create({
    model: "<provider-slug>/<model-slug>",
    messages: [{ role: "user", content: "Explain an AI gateway in two sentences." }],
    maxOutputTokens: 200,
  });
  console.log(completion.outputText);
  console.log("Request:", completion.metadata.requestId);
} catch (error) {
  if (error instanceof NirmosError) {
    console.error({ code: error.code, status: error.status, requestId: error.requestId });
  }
  throw error;
}

Run the example after replacing the model placeholders:

node quickstart.mjs

The script prints your organization ID, the generated text and the request ID when present. outputText combines text from returned choices; metadata contains optional request and trace IDs, provider, latency and cache information.

The code also works as TypeScript. See chat completions for structured choices and usage fields.

Next steps

Your first AI request explains choices, usage and conversation history. Client configuration covers origins and per-request options. Runtime compatibility covers JavaScript environments.

On this page