Agent Utilities
← Text processing

text.chunk · v1.0.0

Chunk
for your agent.

Split text into at most 200 overlapping chunks with offsets and intact UTF-16 surrogate pairs.

$0.0003 / call300 micro-dollar credits
131,072 bytes max input65,536 bytes max output
Works on supplied inputNo external network fetch

Example input

{
  "text": "Agents can reuse bounded snippets of a longer document.",
  "maxChars": 32,
  "overlap": 8
}

Example output

{
  "chunks": [
    {
      "start": 0,
      "end": 32,
      "text": "Agents can reuse bounded snippet"
    },
    {
      "start": 24,
      "end": 55,
      "text": " snippets of a longer document."
    }
  ],
  "offsetUnit": "UTF-16 code units",
  "count": 2
}

Generated from the actual handler using this example input; this is a preview, not a paid API call. Paid responses wrap the result with a receipt and recovery expiry.

Call it from your agent

Add credits in the workspace and keep your API key in private environment storage. Use the same request ID and exact body to recover a lost response within ten minutes.

// Node.js 22+. Read the key from your private environment.
const requestId = Date.now() + '_' + crypto.randomUUID();
const response = await fetch('https://agent-utilities.agent-utilities.workers.dev/v1/tools/text.chunk', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + process.env.AGENT_UTILITIES_API_KEY,
    'Idempotency-Key': requestId
  },
  body: JSON.stringify({
  "text": "Agents can reuse bounded snippets of a longer document.",
  "maxChars": 32,
  "overlap": 8
})
});
const data = await response.json();
if (!response.ok) throw new Error(data.error?.message ?? 'Request failed');
console.log(data);
// On response loss, retry this SAME requestId, tool and body.
// Do not rerun the line that generates requestId for a retry.
Input JSON Schema
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "maxLength": 100000
    },
    "maxChars": {
      "type": "integer",
      "minimum": 32,
      "maximum": 10000
    },
    "overlap": {
      "type": "integer",
      "minimum": 0,
      "maximum": 500
    }
  },
  "required": [
    "text"
  ],
  "additionalProperties": false
}
Output JSON Schema
{
  "type": "object",
  "properties": {
    "chunks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "start": {
            "type": "number"
          },
          "end": {
            "type": "number"
          },
          "text": {
            "type": "string"
          }
        },
        "required": [
          "start",
          "end",
          "text"
        ],
        "additionalProperties": false
      }
    },
    "offsetUnit": {
      "type": "string"
    },
    "count": {
      "type": "number"
    }
  },
  "required": [
    "chunks",
    "offsetUnit",
    "count"
  ],
  "additionalProperties": false
}

Before you integrate

Prices are experimental. The service currently allows 1,000 new calls per day across all accounts. Failed operations return reserved credits. Successful results are encrypted for ten-minute retry recovery. Review data handling and service limits.