Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
deps: Bump @anthropic-ai/sdk from 0.133.0 to 1.3.0 in /sdk/typescript (#4554)
dependabot[bot]74277d47ecfb
diff --git a/scripts/verify_anthropic_peer.mjs b/scripts/verify_anthropic_peer.mjsnew file mode 100644index 000000000..0089bed32--- /dev/null+++ b/scripts/verify_anthropic_peer.mjs@@ -0,0 +1,62 @@+import assert from 'node:assert/strict';+import { createServer } from 'node:http';+import { createRequire } from 'node:module';+import { pathToFileURL } from 'node:url';+import path from 'node:path';++const sdk = path.resolve(process.argv[2]);+const require = createRequire(path.join(sdk, 'package.json'));+const Anthropic = require('@anthropic-ai/sdk').default;+const { withHeadroom } = await import(pathToFileURL(path.join(sdk, 'dist/adapters/anthropic.js')));+assert.ok(['localhost', '127.0.0.1'].includes(new URL(process.env.HEADROOM_BASE_URL).hostname));+const calls = [];+const server = createServer(async (request, response) => {+ const chunks = [];+ for await (const chunk of request) chunks.push(chunk);+ calls.push({ body: JSON.parse(Buffer.concat(chunks).toString()), path: request.url });+ response.writeHead(200, { 'content-type': 'application/json' });+ response.end(JSON.stringify({+ id: 'msg-local-peer-proof', type: 'message', role: 'assistant',+ model: 'claude-sonnet-4-5-20250929',+ content: [{ type: 'text', text: 'fixture answer' }],+ stop_reason: 'end_turn', stop_sequence: null,+ usage: { input_tokens: 100, output_tokens: 8 },+ }));+});+await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));+try {+ const messages = [+ { role: 'user', content: [{ type: 'text', text: 'Read the fixture.', cache_control: { type: 'ephemeral' } }] },+ { role: 'assistant', content: [+ { type: 'thinking', thinking: 'Opaque fixture reasoning.', signature: 'opaque-fixture-signature' },+ { type: 'tool_use', id: 'tool-local-1', name: 'lookup', input: { query: 'fixture' } },+ ] },+ { role: 'user', content: [{+ type: 'tool_result', tool_use_id: 'tool-local-1', content: 'short fixture result',+ cache_control: { type: 'ephemeral' },+ }] },+ ];+ const system = [{ type: 'text', text: 'Return the fixture answer.', cache_control: { type: 'ephemeral' } }];+ const metadata = { user_id: 'local-fixture' };+ const client = withHeadroom(new Anthropic({+ apiKey: 'local-fixture-only',+ baseURL: `http://127.0.0.1:${server.address().port}`,+ }), { baseUrl: process.env.HEADROOM_BASE_URL, fallback: false, retries: 0 });+ const result = await client.messages.create({+ model: 'claude-sonnet-4-5-20250929', max_tokens: 2048,+ thinking: { type: 'enabled', budget_tokens: 1024 }, messages, system, metadata,+ tools: [{ name: 'lookup', input_schema: {+ type: 'object', properties: { query: { type: 'string' } }, required: ['query'],+ } }],+ });+ assert.equal(calls.length, 1);+ assert.equal(calls[0].path, '/v1/messages');+ assert.deepEqual(calls[0].body.messages, messages);+ assert.deepEqual(calls[0].body.system, system);+ assert.deepEqual(calls[0].body.metadata, metadata);+ assert.equal(result.content[0].text, 'fixture answer');+ console.log('PASS: actual Anthropic SDK client + Headroom adapter preserve thinking, cache markers, tool pairs, system and metadata on the wire');+} finally {+ server.closeAllConnections();+ await new Promise(resolve => server.close(resolve));+}diff --git a/scripts/verify_anthropic_peer.py b/scripts/verify_anthropic_peer.pynew file mode 100644index 000000000..05164906b--- /dev/null+++ b/scripts/verify_anthropic_peer.py@@ -0,0 +1,75 @@+import os+import socket+import subprocess+import sys+import tempfile+import threading+import time+from pathlib import Path++os.environ["HEADROOM_SKIP_UPSTREAM_CHECK"] = "1"+os.environ["HEADROOM_DISTRIBUTION"] = "local"+os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"+root = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(__file__).resolve().parents[1]+state = tempfile.TemporaryDirectory(prefix="headroom-sdk-proof-")+os.environ["HEADROOM_WORKSPACE_DIR"] = state.name+os.environ["HEADROOM_CONFIG_DIR"] = str(Path(state.name) / "config")+sys.path.insert(0, str(root))+import uvicorn++from headroom.proxy.server import ProxyConfig, create_app++app = create_app(+ ProxyConfig(+ optimize=True,+ cache_enabled=False,+ rate_limit_enabled=False,+ cost_tracking_enabled=False,+ log_requests=False,+ ccr_inject_tool=False,+ ccr_handle_responses=False,+ ccr_context_tracking=False,+ image_optimize=False,+ disable_kompress=True,+ subscription_tracking_enabled=False,+ stateless=True,+ )+)+seen = []++[email protected]("http")+async def count_compress(request, call_next):+ response = await call_next(request)+ if request.url.path == "/v1/compress":+ seen.append(response.status_code)+ return response+++listener = socket.socket()+listener.bind(("127.0.0.1", 0))+port = listener.getsockname()[1]+server = uvicorn.Server(uvicorn.Config(app, log_level="warning"))+thread = threading.Thread(target=server.run, kwargs={"sockets": [listener]}, daemon=True)+thread.start()+try:+ for _ in range(300):+ if server.started:+ break+ if not thread.is_alive():+ raise RuntimeError("proxy stopped before startup")+ time.sleep(0.1)+ assert server.started+ env = dict(os.environ, HEADROOM_BASE_URL=f"http://127.0.0.1:{port}")+ command = ["node", str(Path(__file__).with_suffix(".mjs")), str(root / "sdk/typescript")]+ if len(sys.argv) > 2:+ command.append(sys.argv[2])+ result = subprocess.run(command, env=env)+ assert seen and all(status == 200 for status in seen), seen+ print("Real Headroom /v1/compress response:", seen, flush=True)+ raise SystemExit(result.returncode)+finally:+ server.should_exit = True+ thread.join(timeout=15)+ listener.close()+ state.cleanup()diff --git a/sdk/typescript/package-lock.json b/sdk/typescript/package-lock.jsonindex 09908fe5c..278088123 100644--- a/sdk/typescript/package-lock.json+++ b/sdk/typescript/package-lock.json@@ -12,7 +12,7 @@"@ai-sdk/anthropic": "^4.0.94","@ai-sdk/openai": "^4.0.106","@ai-sdk/provider": "^4.0.35",- "@anthropic-ai/sdk": "^0.133.0",+ "@anthropic-ai/sdk": "^1.3.0","@types/node": "^26.6.6","ai": "^7.0.159","dotenv": "^18.0.1",@@ -131,12 +131,13 @@}},"node_modules/@anthropic-ai/sdk": {- "version": "0.133.0",- "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.133.0.tgz",- "integrity": "sha512-jlqUN8p8ESTJj+GJnA4KjzbEfF1waEoGzRT8jwytlYGFFgv+/DUQOxlYGvYw10UzhD1kwLqYzxvA3FrTB2YWuQ==",+ "version": "1.3.0",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-1.3.0.tgz",+ "integrity": "sha512-k7z9BlLLPxfZH+ov7dS6EnaN/wiZeV8YNT1LZfrpAHIy7oY7pHr4UzirF9f2OlHtFEnRBOX+AZQ91Y5fK+TPTw==","dev": true,- "license": "MIT",+ "license": "Apache-2.0","dependencies": {+ "@opentelemetry/api": "^1.4.1","json-schema-to-ts": "^3.1.1","standardwebhooks": "^1.0.0"},@@ -643,6 +644,16 @@"@jridgewell/sourcemap-codec": "^1.4.14"}},+ "node_modules/@opentelemetry/api": {+ "version": "1.10.0",+ "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.10.0.tgz",+ "integrity": "sha512-lMkyes8iHrG+mk6WH7X70MdCLI2RS0FwNBY1PyQ8UemaijE2m5mv5A0Niy3HtbYTFrgkUEQjFMXmSAk2hQDuPQ==",+ "dev": true,+ "license": "Apache-2.0",+ "engines": {+ "node": ">=8.0.0"+ }+ },"node_modules/@oxc-project/types": {"version": "0.155.0","resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.155.0.tgz",@@ -770,9 +781,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -791,9 +799,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -812,9 +817,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -833,9 +835,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -854,9 +853,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -875,9 +871,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -1897,9 +1890,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MPL-2.0","optional": true,"os": [@@ -1922,9 +1912,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MPL-2.0","optional": true,"os": [@@ -1947,9 +1934,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MPL-2.0","optional": true,"os": [@@ -1972,9 +1956,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MPL-2.0","optional": true,"os": [diff --git a/sdk/typescript/package.json b/sdk/typescript/package.jsonindex 7099a37be..df6646d15 100644--- a/sdk/typescript/package.json+++ b/sdk/typescript/package.json@@ -123,7 +123,7 @@"@ai-sdk/anthropic": "^4.0.94","@ai-sdk/openai": "^4.0.106","@ai-sdk/provider": "^4.0.35",- "@anthropic-ai/sdk": "^0.133.0",+ "@anthropic-ai/sdk": "^1.3.0","@types/node": "^26.6.6","ai": "^7.0.159","dotenv": "^18.0.1",