Skip to content

Contexts

Contexts let you attach curated knowledge — documents, notes, web pages, or chain outputs — to your account or workspace. Once ingested, contexts are semantically indexed and automatically injected into your AI twin's prompt pipeline.

Base path

text
/api/v1/agents/contexts

Authentication

All endpoints require a valid JWT Bearer token.

bash
export BASE_URL="https://api.chainabit.com/api/v1"
export TOKEN="your-access-token"
export WORKSPACE_ID="your-workspace-id"

Endpoints

MethodPathDescription
GET/agents/contextsList contexts
GET/agents/contexts/:idGet a context by ID
POST/agents/contextsCreate a context
PATCH/agents/contexts/:idUpdate title or description
DELETE/agents/contexts/:idDelete a context
POST/agents/contexts/searchSemantic search over contexts

GET /agents/contexts

List contexts owned by your account.

Request

Query parameters

ParameterTypeDefaultDescription
limitnumber20Records per page
offsetnumber0Pagination offset
workspaceIdstringFilter to a specific workspace

Response

json
{
  "data": [
    {
      "id": "ctx_01...",
      "title": "Q1 Strategy",
      "description": "Leadership OKR notes",
      "status": "ready",
      "content_summary": "A concise AI-generated summary...",
      "created_at": "2026-04-01T10:00:00Z"
    }
  ],
  "meta": { "total": 12, "limit": 10, "offset": 0 }
}

Code Example

bash
curl "$BASE_URL/agents/contexts?limit=10" \
  -H "Authorization: Bearer $TOKEN"

GET /agents/contexts/:id

Get a single context by ID.

Response

Returns 404 if the context does not exist or belongs to another account.

Code Example

bash
curl "$BASE_URL/agents/contexts/ctx_01..." \
  -H "Authorization: Bearer $TOKEN"

POST /agents/contexts

Create a new context. Ingestion — AI summarisation and embedding — runs asynchronously. The returned record has status: "processing".

Request

Query parameters

ParameterTypeDescription
workspaceIdstringOptional — attach to a workspace

Request body

FieldTypeRequiredDescription
titlestringYesDisplay name (max 200 chars)
descriptionstringNoOptional description (max 500 chars)
sourceTypestringYesdocument, note, web, or chain_output
rawContentstringNoText content for document, note, chain_output (max 100 000 chars)
urlstringNoURL for web sources (max 2048 chars)
chainIdstringNoChain ID for chain_output sources

Response

json
{
  "data": {
    "id": "ctx_01...",
    "title": "Q1 Strategy",
    "status": "processing",
    "created_at": "2026-04-11T09:00:00Z"
  }
}

Code Examples

Example — document

bash
curl -X POST "$BASE_URL/agents/contexts" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Q1 Strategy",
    "description": "Leadership OKR notes",
    "sourceType": "document",
    "rawContent": "In Q1 we aim to grow revenue by 30%..."
  }'

Example — web page

bash
curl -X POST "$BASE_URL/agents/contexts" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Competitor Analysis",
    "sourceType": "web",
    "url": "https://example.com/analysis"
  }'

PATCH /agents/contexts/:id

Update the title and/or description of a context.

Request

Request body

FieldTypeDescription
titlestringNew title (max 200 chars)
descriptionstring | nullNew description, or null to clear

Code Example

bash
curl -X PATCH "$BASE_URL/agents/contexts/ctx_01..." \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "title": "Q1 Strategy — Revised" }'

DELETE /agents/contexts/:id

Delete a context. Soft-delete — the record is hidden but not physically removed.

Response

json
{ "data": { "deleted": true } }

Code Example

bash
curl -X DELETE "$BASE_URL/agents/contexts/ctx_01..." \
  -H "Authorization: Bearer $TOKEN"

POST /agents/contexts/search

Semantic search over your ready contexts. Results are ranked by a combination of cosine similarity and recency.

Request

Request body

FieldTypeRequiredDescription
querystringYesNatural language search query (max 1000 chars)
topKnumberNoMax results, 1–20 (default 3)
workspaceIdstringNoScope to a specific workspace

Response

json
{
  "data": [
    {
      "id": "ctx_01...",
      "title": "Q1 Strategy",
      "contentSummary": "A concise AI-generated summary...",
      "score": 0.873
    }
  ]
}

Code Example

bash
curl -X POST "$BASE_URL/agents/contexts/search" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Q1 product strategy",
    "topK": 5
  }'

Context statuses

StatusMeaning
processingIngestion running — not yet searchable
readyIndexed and available for semantic search
failedIngestion failed — not searchable

Notes

  • Only ready contexts appear in search results.
  • Contexts with status: "processing" are still listed by GET /agents/contexts and GET /agents/contexts/:id.
  • Deleting a context removes it from future prompt injections immediately, even if the twin was previously using it.

Built with purpose.