TypeScript SDK
The official Trunkate AI TypeScript SDK provides fully-typed asynchronous bindings for Node.js 18+, Bun, and strictly server-side Edge environments.
Installation
npm install @trunkate-ai/sdk(Or use yarn add, pnpm add, etc).
Setup & Configuration
import { Trunkate } from '@trunkate-ai/sdk';
// Automatically loads process.env.TRUNKATE_API_KEY
const client = new Trunkate();
// Or configure explicitly:
/*
const client = new Trunkate({
apiKey: "tk_live_...",
baseUrl: "https://api.trunkate.ai"
});
*/Usage (Universal Budget)
Trunkate’s budget parameter is Universal. It accepts both absolute token counts and proactive percentage buffers.
// 1. Define your long prompt
const prompt = "Your very long context...";
// OPTION A: Fixed Token Budget (Integer)
// Strict limit for precise cost control.
const optimized = await client.optimize(prompt, "Summarize", 500);
// OPTION B: Proactive Percentage Buffer (String)
// Maintain a dynamic "Smart Buffer" (e.g., 20% of input size).
const proactive = await client.optimize(prompt, "Summarize", "20%");Parameter Reference
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | Yes | The raw prompt to optimize. |
task | string | No | Optional guidance for preservation ranking. |
budget | number|string | No | Absolute tokens (e.g. 500) or percentage (e.g. "20%"). |
model | string | No | Target LLM (e.g. gpt-4o). |
Last updated on