Skip to content
POST AI agent ready /v1/text/truncate

Text Truncate API - Free Smart Truncation

Shortens text to a specified character length, breaking at the nearest word boundary to avoid cutting a word in half. Appends a configurable suffix (default "...") to indicate the text continues.

Parameters

stringrequired

The text to truncate.

numberrequired

Maximum character length of the output.

string

Where to break the text: at a word or sentence boundary.

Code examples

curl -X POST https://api.botoi.com/v1/text/truncate \
  -H "Content-Type: application/json" \
  -d '{"text":"Botoi provides over 150 free developer APIs for common tasks like hashing, encoding, and validation.","max_length":50,"boundary":"word"}'

When to use this API

Generate preview snippets for search results

Truncate article content to 160 characters for search result descriptions that end cleanly at a word boundary.

Fit text into fixed-width UI cards

Shorten product descriptions or titles to a maximum length for card layouts without breaking mid-word.

Frequently asked questions

Does the length include the suffix?
Yes. The total output length, including the suffix, will not exceed the specified length value.
What happens if the text is already shorter than the length?
The text is returned unchanged, and wasTruncated is set to false.
Can I use an empty suffix?
Yes. Pass an empty string as the suffix to truncate without appending anything.
How does word boundary detection work?
The API breaks at the last space character before the length limit. If no space exists, it breaks at the exact length.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.