Skip to Content

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

ParameterTypeRequiredDescription
textstringYesThe raw prompt to optimize.
taskstringNoOptional guidance for preservation ranking.
budgetnumber|stringNoAbsolute tokens (e.g. 500) or percentage (e.g. "20%").
modelstringNoTarget LLM (e.g. gpt-4o).
Last updated on