mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
| .. | ||
| basic-compress.ts | ||
| ccr-retrieve.ts | ||
| hooks-custom-compression.ts | ||
| middleware-composition.ts | ||
| multi-provider.ts | ||
| openai-anthropic-adapters.ts | ||
| README.md | ||
| shared-context-multi-agent.ts | ||
| simulation-dry-run.ts | ||
| streaming-chat.ts | ||
| structured-output.ts | ||
| tool-calling-agent.ts | ||
| with-headroom-vercel.ts | ||
headroom-ai examples
Runnable examples showing how to use the Headroom TypeScript SDK for context compression.
Prerequisites
- Node.js 18+
- A running Headroom proxy (
pip install "headroom-ai[proxy]" && headroom proxy) OPENAI_API_KEYset in your environment (most examples use OpenAI)- Optional:
ANTHROPIC_API_KEYfor Anthropic examples
Running
cd sdk/typescript
npm install
npx tsx examples/<filename>.ts
Examples
Vercel AI SDK
| Example | Description |
|---|---|
| with-headroom-vercel.ts | One-liner withHeadroom(openai('gpt-4o')) — simplest integration |
| streaming-chat.ts | withHeadroom + streamText for real-time streaming |
| tool-calling-agent.ts | Multi-step agent with tools, context auto-compressed each step |
| structured-output.ts | Extract structured data with Output.object() from compressed context |
| middleware-composition.ts | Stack headroomMiddleware with other middlewares (extractReasoningMiddleware) |
| multi-provider.ts | Same compression across GPT-4o and GPT-4o-mini |
Core SDK
| Example | Description |
|---|---|
| basic-compress.ts | compress() function — compress then send to any LLM |
| simulation-dry-run.ts | simulate() — see what compression would do without calling the LLM |
| hooks-custom-compression.ts | CompressionHooks — customize with pre/post hooks and per-message biases |
| shared-context-multi-agent.ts | SharedContext — compressed handoff between agents (70-90% savings) |
| ccr-retrieve.ts | CCR — retrieve original content after compression (lossless) |
Native SDK Adapters
| Example | Description |
|---|---|
| openai-anthropic-adapters.ts | withHeadroom for native OpenAI and Anthropic SDKs (no Vercel AI SDK) |