Nirmos

Client configuration

Configure client defaults, override individual requests and customize advanced SDK behavior.

Create a client with your API key, then set options for the requests your application makes. A client uses hosted URLs by default, so most applications can start with:

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

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 },
  timeoutMs: 30_000, // Allow up to 30 seconds for each attempt, including its body.
  maxRetries: 2, // Allow two additional attempts for eligible requests.
});

Reuse the configured client for requests that share credentials and defaults. See authentication to choose a service or personal key.

Client defaults

Timeouts, retries and default headers apply to both management and runtime requests unless a method or per-request option overrides them.

OptionDefaultWhen to use it
authRequiredPass your service or personal key
apiBaseUrlhttps://api.nirmos.comChange the management API URL
runtimeBaseUrlhttps://runtime.nirmos.comChange the AI execution URL
timeoutMs60_000Set the timeout per attempt in milliseconds; 0 disables it
maxRetries2Set the number of additional eligible attempts; 0 disables retries
headersNoneAdd default headers to requests to both URLs
fetchglobalThis.fetchProvide a Fetch wrapper or replacement
promptCacheEnabled, 60-second TTL, 100 entriesConfigure the per-client managed-prompt cache; false disables it
onErrorNoneObserve final HTTP API errors centrally

Use nonnegative timeout values and whole, nonnegative retry counts. Invalid constructor values fall back to their defaults. Missing authentication, blank credentials, unavailable Fetch or invalid absolute URLs throw ConfigurationError.

Override one request

Pass request options as the final argument. For methods with query parameters, supply the query object first, even when it is empty:

// Leave filters empty and override the defaults for this call only.
const page = await nirmos.models.list({}, {
  timeoutMs: 10_000, // Limit each attempt to 10 seconds.
  maxRetries: 0, // Make one attempt.
  signal: AbortSignal.timeout(15_000), // Bound the whole call, including body reading.
  headers: { "x-trace-id": `trace_${crypto.randomUUID().replaceAll("-", "")}` },
});

console.log("Models on this page:", page.items.length);
OptionDefaultUse
timeoutMsClient valueOverride the timeout per attempt; 0 disables it
maxRetriesClient valueOverride the number of additional eligible attempts
signalNoneCancel the request, body reading or retry wait
headersClient headersAdd or replace headers, except authentication headers
idempotencyKeyNoneSend a replay key for operations that support server deduplication

Most mutations do not retry automatically. Adding idempotencyKey enables transport retry eligibility, but safe replay requires support from the endpoint. Read retry rules and mutation safety before using it.

Change the API URLs

Set the management and execution URLs independently when targeting another deployment. The SDK does not read these environment variables automatically:

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

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 },
  apiBaseUrl: process.env.NIRMOS_API_URL, // Undefined keeps the hosted API default.
  runtimeBaseUrl: process.env.NIRMOS_RUNTIME_URL, // Set separately for execution.
});

Use absolute URLs without appending /v1; SDK methods already include their endpoint paths. Trailing slashes are removed, and path prefixes are retained. An omitted or undefined URL uses its own hosted default.

Advanced configuration

See the core type reference for the exported option types and method reference for each method's arguments.

On this page