TypeScript support
Use inferred responses, checked request objects and public SDK types in your application.
The SDK includes TypeScript declarations. Method calls infer their response types, and your editor can suggest request fields as you write. Import the client and public types from @nirmos/sdk.
Let method calls infer the result
You can use typed responses without adding a type annotation:
const page = await nirmos.models.list({ capability: "chat", limit: 25 });
// TypeScript knows the fields on each model returned by this method.
for (const model of page.items) {
console.log(model.id, model.slug, model.availability);
}When you extract a request into a reusable object, use satisfies to check it against the SDK type while preserving its inferred shape:
import type { ChatCreateParams } from "@nirmos/sdk";
const request = {
route: "production-chat", // Replace with a configured route.
messages: [{ role: "user", content: "Hello" }],
maxOutputTokens: 200,
} satisfies ChatCreateParams;
// The response is inferred as ChatCompletion.
const completion = await nirmos.gateway.chat.create(request);
console.log(completion.outputText);ChatCreateParams requires exactly one of model or route. The SDK also checks that choice at runtime. See chat completions for request fields and model selection.
Import public types
Use import type for annotations such as ChatCreateParams, ChatCompletion, EmbeddingResponse and RequestOptions. The package includes declarations for ESM and CommonJS; only the package root is exported.
Management types are grouped into three maps:
| Export | Describes | Example |
|---|---|---|
Requests | Request bodies | Requests["createPrompt"] |
Queries | Query parameters, including filters and pagination | Queries["listModels"] |
Responses | Returned data | Responses["createPrompt"] |
import type { Queries, Requests, Responses } from "@nirmos/sdk";
// Use a query type when sharing filters between calls.
const filters = { capability: "embeddings", limit: 25 } satisfies Queries["listModels"];
const models = await nirmos.models.list(filters);
console.log(models.items.length);
// Check the body separately from the method call.
const input = { name: "Support", slug: "support" } satisfies Requests["createPrompt"];
const created: Responses["createPrompt"] = await nirmos.prompts.create(input);
console.log(created.promptId);The map keys are HTTP operation IDs, not SDK method names. For example, prompts.create uses createPrompt, and models.list uses listModels. Find the operation ID in the method's reference page.
Derive a type from a method
Use Parameters and Awaited<ReturnType<...>> when you want a helper's types to follow the SDK method directly:
import type { Nirmos } from "@nirmos/sdk";
// Extract the first argument and the resolved response from public methods.
type CreateKnowledgeBase = Parameters<Nirmos["knowledge"]["create"]>[0];
type KnowledgeBase = Awaited<ReturnType<Nirmos["knowledge"]["get"]>>;
const input: CreateKnowledgeBase = {
name: "Support knowledge",
embeddingModel: "configured/embedding-model", // Use your embedding model.
embeddingDimensions: 1536, // Match the dimensions supported by that model.
};
const base: KnowledgeBase = await nirmos.knowledge.create(input);
console.log(base.id);The type reference lists package-root exports, including gateway, Memory and evaluation types.
Validate data at runtime
TypeScript checks your code before it runs. Validate data from user input, external JSON or fields typed as unknown before using it. Most SDK methods rely on backend validation for request rules.
Handle optional properties explicitly, such as a missing request ID. null and an absent property are distinct values. The SDK leaves date strings as strings; convert them to Date when your application needs date operations.