> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anpord.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Resolving prompts

> Reading the right version at runtime

## In production

Ask for the prompt by id and let the production channel decide the version:

```ts theme={null}
const prompt = await anpord.prompts.get({ id: "support-reply" });

const completion = await model.complete(prompt.content);
```

## Pinning a version

Pass a version to address one exactly:

```ts theme={null}
const prompt = await anpord.prompts.get({ id: "support-reply", version: 3 });
```

Useful for reproducing a past run, or for an evaluation that has to compare versions against each other rather than follow whatever is live.

<Note>
  `version` wins when you pass both `version` and `channel` — the channel is ignored rather than rejected.
</Note>

## Reading history

There is no separate versions call. Ask `get` to include the history:

```ts theme={null}
const prompt = await anpord.prompts.get({
  id: "support-reply",
  includeVersions: true,
});

for (const version of prompt.versions ?? []) {
  console.log(version.version, version.message, version.createdAt);
}
```

History is omitted unless you ask for it, so the common read stays small. Each entry carries `version`, `message`, and `createdAt` — not the content. Fetch a specific version to read its text.

## Caching

Every resolve is a network call. If you resolve on a hot path, cache the result for as long as you are willing to wait for a promotion to take effect:

```ts theme={null}
const cache = new Map<string, { at: number; content: string }>();
const TTL = 60_000;

const content = async (id: string) => {
  const hit = cache.get(id);
  if (hit && Date.now() - hit.at < TTL) {
    return hit.content;
  }

  const prompt = await anpord.prompts.get({ id });
  cache.set(id, { at: Date.now(), content: prompt.content });
  return prompt.content;
};
```

<Warning>
  A cache is also a failure mode: a promoted version will not reach callers until entries expire. Keep the window short enough that a rollback still counts as fast.
</Warning>

## Falling back

Treat a resolve like any other network call. Keeping a copy of the prompt in your code means an outage degrades quality rather than breaking the feature:

```ts theme={null}
import { AnpordError } from "anpord";

const FALLBACK = "You are a support agent. Be brief.";

const resolve = async (id: string) => {
  try {
    const prompt = await anpord.prompts.get({ id });
    return prompt.content;
  } catch (error) {
    if (error instanceof AnpordError) {
      return FALLBACK;
    }
    throw error;
  }
};
```
