The context-aware splitting endpoint provides intelligent text splitting capabilities for documents up to 4000 words. Unlike simple character-based splitting, context-aware splitting preserves the semantic meaning and context between chunks, making it ideal for processing long-form content while maintaining coherence.

Use cases

  • Breaking down long articles or research papers for improved readability
  • Preparing content for chunked processing in RAG (Retrieval-Augmented Generation) systems
  • Splitting lengthy legal documents while maintaining context around clauses and references
  • Creating digestible sections of educational content while preserving logical flow
  • Processing large documentation files for knowledge base creation

You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.

We recommend setting the API key as an environment variable in a .env file with the name WRITER_API_KEY.

Endpoint overview

URL: POST https://api.writer.com/v1/tools/context-aware-splitting

curl --location 'https://api.writer.com/v1/tools/context-aware-splitting' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $WRITER_API_KEY" \
--data '{
  "text": "text to split",
  "strategy": "llm_split"
}'

Request body

The request body includes the following parameters:

ParameterTypeDescription
textstringThe text content to be split. The text should be fewer than 4000 words.
strategystringThe splitting strategy to use. Options include: llm_split, fast_split, and hybrid_split. See below for more details.

Splitting strategies

  • llm_split: Uses an LLM for precise semantic splitting
  • fast_split: Uses heuristic-based approach for quick splitting
  • hybrid_split: Combines both approaches

Response format

Returns an array of text chunks, with at least one chunk guaranteed. Each chunk maintains semantic coherence while preserving the context of the original text.

ParameterTypeDescription
chunksarray[string]An array of text chunks as strings.
{
  "chunks": ["chunk1", "chunk2", "chunk3"]
}