Nirmos
Prompt management

Versions, branches and releases

Save content snapshots, manage branches, publish releases, and handle conflicts.

Use prompt:create and prompt:update for saved content and branch changes, prompt:read for inspection, and prompt:publish for release changes. A saved draft can be evaluated without publication.

Model names beginning with configured/ are placeholders. Replace them with an accessible provider-qualified identifier from model discovery. The snippets reuse the server client from the quickstart.

Save and publish

const prompt = await nirmos.prompts.create({ name: "Support reply", slug: "support-reply" });
await nirmos.prompts.update(prompt.promptId, {
  name: "Support reply", slug: "support-reply", description: "Reviewed support instructions",
});
const version = await nirmos.prompts.versions.create(prompt.promptId, {
  branchId: prompt.branchId,
  commitMessage: "Initial support instructions",
  temperature: 0.2,
  maxTokens: 500,
  topP: 1,
  messages: [{
    order: 0,
    role: "system",
    contentBlocks: [{ order: 0, type: "text", text: "Answer support questions concisely." }],
  }],
});
if (!version.versionId) throw new Error("Version creation did not return an ID");
await nirmos.prompts.versions.publish(prompt.promptId, version.versionId);

// Saving another version leaves the published v1 active.
const draft = await nirmos.prompts.versions.create(prompt.promptId, {
  branchId: prompt.branchId, commitMessage: "Unpublished refinement",
  temperature: 0.2, maxTokens: 500, topP: 1,
  messages: [{ order: 0, role: "system", contentBlocks: [
    { order: 0, type: "text", text: "Answer support questions concisely and cite the supplied policy." },
  ] }],
});
const stillLive = await nirmos.managedPrompts.retrieveActive(prompt.promptId, { cache: "reload" });
if (stillLive.version.number !== 1) throw new Error("Unexpected live release");
if (!draft.versionId) throw new Error("Draft save did not return an ID");
await nirmos.prompts.versions.publish(prompt.promptId, draft.versionId);
// Management mutations do not invalidate this client's separate runtime cache.
const active = await nirmos.managedPrompts.retrieveActive(prompt.promptId, { cache: "reload" });
const rendered = await nirmos.managedPrompts.render(active, {});
const answer = await nirmos.gateway.chat.create({
  model: "configured/chat-model", // Or an explicitly selected route.
  messages: [...rendered.messages, { role: "user", content: "What is the refund policy?" }],
  maxOutputTokens: 100,
});
console.log(active.version.number, answer.outputText);

Create returns { promptId, branchId }. Versions use string version IDs for management publication; managedPrompts.versions.activate uses a number. Management versions.get(id) retrieves a version directly by its ID, not a prompt/version-number pair.

Branch operations

const branch = await nirmos.prompts.branches.create("prompt-id", {
  name: "Experiment", slug: "experiment", sourceVersionId: "version-id",
});
await nirmos.prompts.update("prompt-id", {
  name: "Support reply", slug: "support-reply", description: "Reviewed support policy",
});
console.log(branch);

Update requires name and slug. Additional operations include list/get, branches list/merge/delete, version list/get, duplicate/archive/restore/delete and compile/preview. Management mutations do not invalidate the separate managedPrompts cache: reload or clear it when using both protocols.

Conflicts, invalid branches, missing versions and permission failures surface as API errors. See prompt reference, managed protocol reference and REST prompts.

Publication and concurrency

Each successful version save advances that branch's headVersionId atomically with its immutable snapshot. Pass the last reviewed saved version as parentVersionId to reject stale saves. An omitted parent uses the current saved ancestry; it does not assert what your editor previously loaded. Merge uses saved content without requiring branch publication, creates a target draft and leaves production active content unchanged. Publish explicitly after reviewing the merge. Publishing a default-branch draft marks it published and moves the live release pointer. Republishing a previously published default-branch snapshot restores that exact immutable content, without duplicating the version or moving saved heads backward. Republishing the active snapshot succeeds without another release change. Eligible statuses are draft and published; archived versions return 409 CONFLICT, deleted/missing or wrong-prompt version IDs return 404 NOT_FOUND. Restore an archived prompt before publication. A concurrent release write returns 409 CONFLICT; reload current state before deciding whether to retry.

Management publication on a non-default branch marks that snapshot published but does not change the global live release. Merge it into the default branch and publish the merge to release it. Runtime managedPrompts.versions.activate(id, numericVersion) explicitly activates a selected eligible snapshot through the same release transition; it can activate snapshots from another branch. Both paths preserve saved heads and append an audit record when the live pointer changes. Version lists retain immutable snapshots; release audits record pointer changes separately, including rollbacks. Authorization requires prompt:publish.

Management uses string version IDs, such as version.versionId. Runtime uses numeric version numbers, such as active.version.number; these are distinct. The global latest saved version and a branch's headVersionId can remain V3 while latestVersionId points to live V1. Existing client caches keep their previous value until expiry, explicit invalidation or { cache: "reload" }. A management publication does not invalidate another process's SDK cache.

Supply expectedSourceVersionId and expectedTargetVersionId from the reviewed branch heads when merging. A changed head rejects with a conflict; refresh and compare before retrying. Merge currently replaces target content with source content, rather than combining conflicting edits. Historical versions remain available. Existing clients' managed-prompt caches still require reload/expiry after publication; management saves/merges do not invalidate them.

Merge rejects a branch whose saved snapshots and recorded head are inconsistent. Review latest saved content and save a new draft from it before merging; no bulk history rewrite or publication occurs.

Rollback example · Prompt lifecycle

Runtime numbered versions

const prompt = await nirmos.managedPrompts.update("support-reply", {
  description: "Reviewed support policy", tags: ["support", "reviewed"],
});
const version = await nirmos.managedPrompts.versions.create(prompt.id, {
  content: { type: "text", role: "system", text: "Help {{customerName}}. Never invent account details." },
  variables: [{ name: "customerName", type: "string", required: true }],
  commitMessage: "Clarify account guidance",
});
console.log(version.number, version.status);

Metadata update changes name/slug/description/metadata/tags/folder/status, not content. Content changes create a new version. Version create also accepts optional metadata and activate; drafts can be tested before activation.

let cursor: string | undefined;
do {
  const page = await nirmos.managedPrompts.versions.list("support-reply", { limit: 20, cursor });
  for (const version of page.data) console.log(version.number, version.status);
  cursor = page.hasMore ? page.nextCursor : undefined;
} while (cursor);
const version = await nirmos.managedPrompts.versions.retrieve("support-reply", 3);
const active = await nirmos.managedPrompts.versions.activate("support-reply", version.number);
console.log(active.active);

Runtime list defaults to 20 versions and caps at 100. Treat returned cursor strings as opaque even when runtime uses numeric version boundaries. Mutations invalidate this client's cache; other processes keep their own entries until expiry or explicit invalidation.

Managed prompt reference · Cache behavior · Management releases

On this page