Chunker API v1
The chunker
API endpoint allows you to split your content into smaller chunks. This is particularly useful when you want to use document chunks in a RAG pipeline or just use specific parts of a document for your tasks.
Generate a User/Org API key
You will need to generate an API key to authenticate your requests. For more information, visit the User/Org API key documentation.
Chunk content
Split content into chunks by sending them to chunk API endpoint.
Headers
- Name
Content-Type
- Type
- string
- Required
- Required
- Description
Request content type. Needs to be
application/json
.
- Name
Authorization
- Type
- string
- Required
- Required
- Description
Replace
<YOUR_API_KEY>
with your user/org API key.
Request Body
- Name
content
- Type
- string
- Required
- Required
- Description
The content of the document to be chunked.
- Name
chunkMaxLength
- Type
- number
- Description
The maximum length for each document chunk. Must be between
1024
and30000
characters.Default:
1024
- Name
chunkOverlap
- Type
- number
- Description
The number of characters to overlap between chunks. Must be greater than or equal to
256
and less than chunkMaxLength.Default:
256
Usage example
Install the SDK
npm i langbase
Environment variables
.env file
LANGBASE_API_KEY="<USER/ORG-API-KEY>"
Chunk content
Chunk content
import { Langbase } from 'langbase';
const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY!,
});
async function main() {
const content = `Langbase is the most powerful serverless AI platform for building AI agents with memory. Build, deploy, and scale AI agents with tools and memory (RAG). Simple AI primitives with a world-class developer experience without using any frameworks.`;
const chunks = await langbase.chunker({
content,
chunkMaxLength: 1024,
chunkOverlap: 256
});
console.log('Chunks:', chunks);
}
main();
Response
- Name
Response
- Type
- string[]
- Description
The response is an array of chunks created from the content.
Chunker API Response
type ChunkerResponse = string[];
API Response
[
"Langbase is the most powerful serverless AI platform for building AI agents with memory. Build, deploy, and scale AI agents with tools and memory (RAG). Simple AI primitives with a world-class developer experience without using any frameworks."
]