跳转到内容
POST AI agent ready /v1/text/truncate

文本截断 API - 免费智能截断

将文本缩短到指定的字符长度,在最近的单词边界处断开以避免将单词切成两半。 附加可配置的后缀(默认“...”)以指示文本继续。

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

生成搜索结果的预览片段

将文章内容截断为 160 个字符,以便搜索结果描述在单词边界处干净地结束。

将文本调整到固定宽度的 UI 卡中

将产品描述或标题缩短至卡片布局的最大长度,而不会破坏中间的单词。

Frequently asked questions

长度包含后缀吗?
是的。 包括后缀在内的总输出长度不会超过指定的长度值。
如果文本已经短于长度会发生什么?
文本原封不动地返回,并且 wasTruncated 设置为 false。
我可以使用空后缀吗?
是的。 传递一个空字符串作为后缀以截断而不附加任何内容。
单词边界检测如何工作?
API 在长度限制之前的最后一个空格字符处中断。 如果不存在空格,则会在精确长度处断开。

Get your API key

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