AI
AI
Structured LLM calls with budget caps, caching, failover, tool loops and grounded answers.
betaOn npm, API may still change
npm i @dapplelight/signet-aiQuick start
import { z } from "zod"
import { createExtractor, memoryCache, createBudgetLedger } from "@dapplelight/signet-ai"
import { aiSdkProvider } from "@dapplelight/signet-ai/providers/ai-sdk"
import { model } from "./model"
const ai = createExtractor({
providers: [
aiSdkProvider({ name: "primary", model, pricing: { inputPerMTokens: 0.15, outputPerMTokens: 0.6 } }),
],
cache: memoryCache(),
ledger: createBudgetLedger(5, 86_400), // $5 per day, fails closed
})
const { value, meta } = await ai.extract({
schema: z.object({ category: z.string(), maxPrice: z.number().nullable() }),
input: "snowboards under 8000",
instructions: "Pull the category and the price cap from this request.",
})Output is validated against your schema. That guarantees shape, not truth: check values that could do harm against the input.
Modules
Budget
Spend ledger, per-key caps, pluggable stores.
Budget (Durable Object)
Exact global budget on Cloudflare Workers.
Cache
Memory and KV caches keyed by schema and model.
Chat
Tool loops and streaming chat.
Errors
AiError and its codes.
Extract
Typed extraction with retry and failover.
Fake
Deterministic provider for tests.
Ground
Embeddings, search, cited answers.
Jev
Classifier decisions that always have a fallback.
Otel
Usage on spans, spend per subject.
Providers
Vercel AI SDK and Workers AI adapters.
React
useSignetChat for streamed chat.