Skip to content

truncateToTokenBudget

function truncateToTokenBudget(text, maxTokens): string;

Truncates a text string to fit within a token budget. Truncation is at the nearest sentence boundary when possible.

Parameter Type

text

string

maxTokens

number

string