@spendgraph/prompt
v0.15.0
Published
Pull a stored prompt or build one in code, render it, and record what it cost.
Maintainers
Readme
@spendgraph/prompt
Pull a stored prompt or build one in code, render it, and record what it cost.
npm install @spendgraph/promptimport { PromptClient } from "@spendgraph/prompt";
const prompts = new PromptClient({ apiKey, baseUrl });
const prompt = await prompts.pull("billing-explainer");
const reply = await prompt.call({ audience: "students" }, async ({ messages }) => {
const res = await anthropic.messages.create({ model, max_tokens: 400, messages });
return { output: res.content[0].text, model, inputTokens: 400, outputTokens: 12 };
});What you get
- Two ways in, one object.
pullPromptfetches the wording from the dashboard,buildCustomPromptdeclares it in code, and everything downstream behaves the same either way. - The model call stays yours. This package never sees the provider response — it renders, hands you the messages, and records what happened around them.
- One record, two paths. What was sent is built once and shared by the success and failure paths, so the two cannot disagree.
- A missing field throws before anything is sent, not after you paid for the call.
packContextfits competing sources into one window — instructions and the question kept whole, retrieval held to its own share, and whatever is left going to the history.
Docs
| | | | --- | --- | | Overview | Two ways in, one prompt | | Fields | Placeholders, types, and history | | Calling a prompt | call, bind, tools, and what is recorded | | Caching | Stale-while-refresh, and both handles | | Running server-side | run, sample, runAll, and the ceiling | | Versions and datasets | The split the server decides, and why |
Example
examples/04-with-tools/01-tool-loop.mjs
shows a prompt composed with @spendgraph/tools.
License
Apache-2.0
