Get Document Chunks
Retrieve all chunks from a document.
GET /v1/documents/:id/chunks
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Document ID |
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
version | integer | latest | Document version |
limit | integer | 100 | Results per page (1-500) |
cursor | string | - | Pagination cursor |
Example Request
- cURL
- Python
- JavaScript
curl "https://api.inherent.systems/v1/documents/doc_abc123/chunks" \
-H "Authorization: Bearer $INHERENT_API_KEY"
import requests
response = requests.get(
"https://api.inherent.systems/v1/documents/doc_abc123/chunks",
headers={"Authorization": f"Bearer {api_key}"}
)
const response = await fetch(
'https://api.inherent.systems/v1/documents/doc_abc123/chunks',
{
headers: {
'Authorization': `Bearer ${apiKey}`,
},
}
);
Response
{
"chunks": [
{
"id": "chunk_001",
"content": "# API Authentication\n\nAll API requests require authentication...",
"position": {
"index": 0,
"start": 0,
"end": 512
},
"tokens": 128,
"embedding_model": "text-embedding-3-small"
},
{
"id": "chunk_002",
"content": "## Creating an API Key\n\nTo create an API key...",
"position": {
"index": 1,
"start": 512,
"end": 1024
},
"tokens": 135,
"embedding_model": "text-embedding-3-small"
}
],
"document_id": "doc_abc123",
"document_version": 3,
"pagination": {
"has_more": false,
"total": 24
}
}
Response Fields
| Field | Type | Description |
|---|---|---|
chunks | array | Document chunks |
chunks[].id | string | Chunk ID |
chunks[].content | string | Chunk text |
chunks[].position.index | integer | Chunk order index |
chunks[].position.start | integer | Start character position |
chunks[].position.end | integer | End character position |
chunks[].tokens | integer | Token count |
chunks[].embedding_model | string | Embedding model used |
document_id | string | Document ID |
document_version | integer | Document version |
pagination | object | Pagination info |
Use Cases
Rebuild Full Document
response = requests.get(
f"https://api.inherent.systems/v1/documents/{doc_id}/chunks",
headers={"Authorization": f"Bearer {api_key}"}
)
chunks = response.json()["chunks"]
# Chunks are ordered by position.index
full_content = "".join([c["content"] for c in chunks])
Custom Context Assembly
# Get chunks for custom RAG context
chunks = response.json()["chunks"]
# Select specific chunks by index
context = "\n\n".join([
chunks[i]["content"]
for i in [0, 2, 5] # Specific chunk indices
])
Errors
| Code | Description |
|---|---|
404 | Document not found |
404 | Version not found |