Text Truncate

Truncate text to a maximum length with smart word boundary breaking.

POST 1 credit /v1/text-truncate
curl -X POST "https://devtools.toolkitapi.io/v1/text-truncate" \
  -H "Content-Type: application/json" \
  -d '{"text": "The quick brown fox jumps over the lazy dog", "max_length": 20}'
import httpx

resp = httpx.post(
    "https://devtools.toolkitapi.io/v1/text-truncate",
    json={"text": "The quick brown fox jumps over the lazy dog", "max_length": 20},
)
print(resp.json())
const resp = await fetch("https://devtools.toolkitapi.io/v1/text-truncate", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"text": "The quick brown fox jumps over the lazy dog", "max_length": 20}),
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "text": "The quick brown...",
  "truncated": true,
  "original_length": 43,
  "truncated_length": 18,
  "estimated_tokens": 9
}

Try It Live

Live Demo

Description

Truncate text to a maximum length with smart word boundary breaking.

How to Use

1

1. Send a POST request with `text` and `max_length`.

2

2. Optionally configure `suffix` (default `...`) and `word_boundary` (default `true`).

3

3. If the text is already within the limit, `truncated` will be `false` and the original text is returned.

About This Tool

Text Truncate shortens text to a maximum character length, optionally breaking at word boundaries to avoid cutting words in half. It appends a configurable suffix (default `...`) and reports the original and truncated lengths.

Why Use This Tool

Frequently Asked Questions

How does word boundary breaking work?
When `word_boundary` is `true`, the truncation point is moved back to the last space character, avoiding mid-word cuts. It won't break more than halfway back to prevent excessively short results.
Is the suffix included in the max_length?
Yes. The suffix length is subtracted from `max_length` to determine how many characters of the original text to keep.

Start using Text Truncate now

Get your free API key and make your first request in under a minute.