Endpoint
GET /api/v2/brain
The brain endpoint assembles and returns your project's complete memory as a structured markdown document. This is the primary endpoint used by MCP servers and CLI tools to load project context at the start of a session.
Authentication
Supports Bearer token or session cookie authentication.
Query parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
projectId | string | Required | The project ID |
tokenBudget | number | 6000 | Approximate token budget for the assembled document |
Token budget
The tokenBudget parameter controls the maximum approximate size of the returned brain document. The assembler prioritizes higher-tier items and truncates lower-priority content to stay within budget:
# Default budget (6000 tokens)
curl https://contox.dev/api/v2/brain?projectId=proj_abc123 \
-H "Authorization: Bearer contox_sk_yourkey"
# Larger budget for detailed context
curl "https://contox.dev/api/v2/brain?projectId=proj_abc123&tokenBudget=12000" \
-H "Authorization: Bearer contox_sk_yourkey"
Response
Headers
| Header | Description |
|---|---|
ETag | Cache identifier for the current brain state |
Content-Type | application/json |
Body
{
"markdown": "# Project Memory\n\n## Architecture\n...",
"metadata": {
"itemCount": 42,
"tokenEstimate": 5847,
"assembledAt": "2025-01-20T14:00:00Z",
"schemaKeys": ["root/architecture", "root/conventions", "root/implementation"]
}
}
| Field | Type | Description |
|---|---|---|
markdown | string | The assembled brain document in markdown format |
metadata.itemCount | number | Number of memory items included |
metadata.tokenEstimate | number | Estimated token count of the document |
metadata.assembledAt | string | ISO timestamp of assembly |
metadata.schemaKeys | array | Schema keys of included sections |
ETag caching
The brain endpoint supports ETag-based caching to avoid unnecessary data transfer. Use the If-None-Match header with the ETag from a previous response:
# First request
curl -i https://contox.dev/api/v2/brain?projectId=proj_abc123 \
-H "Authorization: Bearer contox_sk_yourkey"
# Response includes ETag
# ETag: "brain-abc123-1705312200"
# Subsequent request with ETag
curl -i https://contox.dev/api/v2/brain?projectId=proj_abc123 \
-H "Authorization: Bearer contox_sk_yourkey" \
-H "If-None-Match: \"brain-abc123-1705312200\""
# Returns 304 Not Modified if brain hasn't changed
A 304 Not Modified response means the brain has not changed since the last request, and your cached version is still valid.
Brain assembly
The brain document is assembled from approved memory items organized by schema key. Items are grouped into sections and sorted by section order:
- Layer 0 -- Project metadata and configuration
- Layer 1 -- Architecture, conventions, and tech stack (Tier 1 items)
- Layer 2 -- Implementation journal, decisions, and bugs (Tier 2 items)
- Layer 3 -- Todos, session logs, and supplementary data (Tier 3 items)
Higher layers are included first. If the token budget is reached before all items are included, lower-priority items are truncated.
See Brain Assembly Guide for a detailed explanation of the assembly process.
Example usage in MCP server
async function loadBrain(projectId, apiKey) {
const response = await fetch(
`https://contox.dev/api/v2/brain?projectId=${projectId}&tokenBudget=8000`,
{
headers: {
'Authorization': `Bearer ${apiKey}`,
'If-None-Match': cachedETag || '',
},
}
);
if (response.status === 304) {
return cachedBrain; // Use cached version
}
cachedETag = response.headers.get('ETag');
const data = await response.json();
cachedBrain = data.markdown;
return data.markdown;
}
Next steps
- Brain Assembly Guide -- Detailed assembly process with diagrams
- Context Packs -- Task-focused context retrieval
- V2 Items -- Manage individual memory items