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.
| Option | Default | When to use it |
|---|---|---|
auth | Required | Pass your service or personal key |
apiBaseUrl | https://api.nirmos.com | Change the management API URL |
runtimeBaseUrl | https://runtime.nirmos.com | Change the AI execution URL |
timeoutMs | 60_000 | Set the timeout per attempt in milliseconds; 0 disables it |
maxRetries | 2 | Set the number of additional eligible attempts; 0 disables retries |
headers | None | Add default headers to requests to both URLs |
fetch | globalThis.fetch | Provide a Fetch wrapper or replacement |
promptCache | Enabled, 60-second TTL, 100 entries | Configure the per-client managed-prompt cache; false disables it |
onError | None | Observe 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);| Option | Default | Use |
|---|---|---|
timeoutMs | Client value | Override the timeout per attempt; 0 disables it |
maxRetries | Client value | Override the number of additional eligible attempts |
signal | None | Cancel the request, body reading or retry wait |
headers | Client headers | Add or replace headers, except authentication headers |
idempotencyKey | None | Send 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.