Skip to content

Examples

Ten worked examples ship in the repo at examples/. Each one is a self-contained pnpm project that builds cleanly against the published @llm-ports/*@alpha packages. Pick the one that matches what you're trying to do.

Getting started

ExampleWhat it showsLinesRequired keys
basicThe simplest possible call: one adapter, one generateText.30ANTHROPIC_API_KEY
multi-providerFallback chain across Anthropic + OpenAI, USD cost gating, classifier capability factory.~120both
streaming-chatExpress SSE server: streamText, streamStructured, multi-turn, tool-augmented agent.~200either

Capability factories in practice

ExampleWhat it shows
email-triageCompose createClassifier + createDrafter. Quality tracking. The BEPA-pattern condensed.
extract-from-pdfgenerateStructured + validation retry-with-feedback against a (mock) OCR'd invoice.
agent-with-approvalTool-use security: read-only tools execute freely, destructive tools route through an approval gate.

Migration paths

ExampleWhat it shows
migrate-from-vercel-aiTwo paths: (a) wrap existing Vercel code, (b) progressively port to the typed registry.

Alpha.1+ observability + local LLMs

ExampleWhat it shows
with-onretryThe new onRetry hook (alpha.1) wired to a console-logger and a metrics sink. Fires for transient-auth, capability-fallback, reasoning-starvation, validation-feedback.
local-with-ollama@llm-ports/adapter-ollama end-to-end: health check, generateText, generateStructured, optional cloud fallback chain via FORCE_CLOUD=1.

Live API integration tests

ExampleWhat it shows
live-integration-testsFour .mjs scripts that exercise the full LLMPort surface against real provider APIs (no mocks). Used to close Gate C of the publishing checklist; ~$0.002 to run the full suite. The live-anthropic.mjs runAgent step is the highest-value end-to-end verification of the alpha.1 zod-to-json-schema fix.

Reading next

MIT License