Package Exports
- captar
Readme
captar
Runtime budget and policy enforcement SDK for LLM calls.
captar helps you stop expensive or runaway model calls before execution by enforcing:
- spend limits
- max call counts
- repeated-call loop detection
- reserve/commit cost accounting
Install
npm i captarQuick Start
import OpenAI from "openai";
import { captar } from "captar";
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const client = captar(openai, {
budget: { limitUsd: 10, window: "day" },
policy: {
maxCalls: 100,
maxRepeatedCalls: 5,
},
});
const result = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello" }],
});Status
- Package: Active
- Stability: Early production-ready core
- Provider support: OpenAI-first
- Runtime support: Node.js 20+
- Module formats: ESM + CJS
- Types: Included (
.d.ts)
Error Handling
Blocked requests throw CaptarBlockedError with a structured decision object:
budget_exceededmax_calls_exceededloop_detected
API
captar(client, options)
Wraps a provider client and enforces runtime policy.
options.budget
limitUsd: numberwindow: "hour" | "day" | "session"
options.policy (optional)
maxCalls?: numbermaxRepeatedCalls?: number
options.hooks (optional)
onEvent(event)onBlocked(event)
Development
pnpm install
pnpm --filter captar build
pnpm --filter captar test
pnpm --filter captar lint
pnpm --filter captar typecheckRepository
Source: https://github.com/8dazo/captor