Brains Session API
The Session API from Brains — 1 operation(s) for session.
The Session API from Brains — 1 operation(s) for session.
Every API here is available over the APIs.io API and to AI agents over MCP.
One button, every client — Claude, Cursor, VS Code and the rest.
https://apis.io/mcp
find_apisBrowse and filter every API in the catalog.get_api_artifactsOne API's artifacts, grouped by type.get_openapiThe primary OpenAPI for this API.find_similar_apisAPIs that look like this one.apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.resolveTurn a domain, URL or GitHub org into the provider it belongs to.find_cohortsEvery scored population of providers in the catalog.curl "https://apis.io/api/v1/apis/usebrains-app:usebrains-app-session-api"
curl "https://apis.io/api/v1/apis?limit=25"
Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.
Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.
A second provider on the same verified email joins the account you already have.
openapi: 3.2.0
info:
title: brains Wiki Session API
version: 1.0.0
description: API-first interface for the brains second-brain wiki. OAuth 2.0 authorization-code flow is designed for ChatGPT Actions and Claude integrations.
servers:
- url: https://lets.usebrains.app
security:
- ApiKeyAuth: []
- OAuth2:
- wiki.read
- wiki.write
tags:
- name: Session
paths:
/api/v1/session/bundle:
get:
tags:
- Session
summary: Pull a filtered slice as a plain-text bundle
description: Returns pages matching the given tag or folder filter as a single plain-text bundle. At least one of 'tags' or 'folder' must be provided. Requires wiki.read scope.
parameters:
- name: tags
in: query
required: false
schema:
type: string
description: Comma-separated tag filter (e.g. 'brainsapp,open-loop'). Pages with any matching tag are included.
- name: folder
in: query
required: false
schema:
type: string
description: Path prefix filter (e.g. 'projects/brainsapp'). Pages whose path starts with this prefix are included.
responses:
'200':
description: Bundle of matching pages as plain text
headers:
X-Page-Count:
schema:
type: integer
description: Number of pages included in the bundle
X-Session-Token:
schema:
type: string
description: UUID identifying this session pull
content:
text/plain:
schema:
type: string
'400':
description: Missing required filter parameter
'401':
description: Missing or invalid authentication
operationId: getApiV1SessionBundle
x-operation-id-source: derived
post:
tags:
- Session
summary: Push edited pages back from a bundle
description: Accepts a plain-text bundle (same format as GET response) and upserts each page into the wiki. Requires wiki.write scope.
requestBody:
required: true
content:
text/plain:
schema:
type: string
responses:
'200':
description: Upsert result
content:
application/json:
schema:
type: object
properties:
ok:
type: boolean
updated:
type: integer
created:
type: integer
failed:
type: array
items:
type: object
properties:
name:
type: string
error:
type: string
'400':
description: Invalid bundle format
'401':
description: Missing or invalid authentication
operationId: postApiV1SessionBundle
x-operation-id-source: derived
components:
securitySchemes:
OAuth2:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://lets.usebrains.app/oauth/authorize
tokenUrl: https://lets.usebrains.app/oauth/token
scopes:
wiki.read: Read wiki content and metadata
wiki.write: Create, update, patch, and move wiki content
ApiKeyAuth:
type: apiKey
in: header
name: x-api-key
x-tools:
- name: list_pages
summary: List Pages
description: 'List wiki pages with optional filtering by tag or status. PRIMARY routing tool: call list_pages first to get a full inventory. When running with Supabase/Postgres index enabled, this is fast with no file reads; otherwise it falls back to a storage scan. Use the returned names to select candidates, then read_page only those candidates.'
inputSchema:
type: object
properties:
tag:
type: string
status:
type: string
enum:
- active
- archived
- draft
folder:
type: string
compact:
type: boolean
limit:
type: number
offset:
type: number
- name: read_page
summary: Read Page
description: 'Read a wiki page by filename, returning content, frontmatter, fileId, revision, and outbound_link_count. If you already pulled a session bundle, do NOT call this for any page listed in that bundle — its full content is already in your context; read it from there. Otherwise the REQUIRED retrieval workflow is: (1) list_pages first to get inventory, (2) LLM selects candidate files from results, (3) read_page only those candidates, (4) LLM performs synthesis. Do NOT read index.md for routing — when Supabase/Postgres index is enabled the DB index is authoritative; otherwise use list_pages. For small edits, prefer patch_page (especially replace_lines). Use update_page only for intentional full-body rewrites. Pages above the 100 KB inline cap (some pages predate the cap and are still legally larger) come back with `truncated: true` and a `size` field (full byte length) instead of the full body — the returned `content` is a valid head slice you can still use as a `find` anchor for patch_page. `truncated` does NOT mean the page is unwritable; patch_page (especially `append`) works on it regardless of size.'
inputSchema:
type: object
properties:
name:
type: string
required:
- name
- name: search_pages
summary: Search Pages
description: Full-text search across wiki pages. Uses Postgres FTS when Supabase/Postgres index is enabled (fast); falls back to a local scan otherwise. Use for keyword lookups; use list_pages for full inventory and routing. Set rerank=true to reorder the top matches by relevance. Each result then has a relevance value from 0 to 1. The rerank runs only for paid tiers (solo, pro, unlimited). For other tiers, rerank.reason is 'not_entitled'. If the rerank is not available, search returns the lexical order and reranked=false.
inputSchema:
type: object
properties:
query:
type: string
tag:
type: string
folder:
type: string
maxCandidates:
type: number
maxResults:
type: number
maxConcurrency:
type: number
rerank:
type: boolean
minRelevance:
type: number
required:
- query
- name: create_page
summary: Create Page
description: 'Create a new wiki page with frontmatter and body content. Name is auto-normalized to a wiki-safe .md path. Returns bytesWritten (UTF-8 byte count of the written file). Ingest responsibility rule: if source material contains stable facts, active tasks, and decisions, you MUST split it across taxonomy folders (canonical/, projects/, decisions/) and keep data/ as raw synthesis only.'
inputSchema:
type: object
properties:
name:
type: string
title:
type: string
body:
type: string
tags:
type: array
items:
type: string
summary:
type: string
required:
- name
- title
- body
- name: create_pages
summary: Create Pages
description: Create multiple pages in one call (fast path for ingest decomposition into canonical/projects/decisions/data). Returns compact timing/count summary by default; set verbose=true for per-page results. Response includes totalBytesWritten (sum of UTF-8 bytes across all created pages) and per-page bytesWritten when verbose=true.
inputSchema:
type: object
properties:
pages:
type: array
items:
type: object
properties:
name:
type: string
title:
type: string
body:
type: string
tags:
type: array
items:
type: string
summary:
type: string
required:
- name
- title
- body
verbose:
type: boolean
runLabel:
type: string
logTiming:
type: boolean
required:
- pages
- name: import_brain_source
summary: Import Brain Source
description: Deterministic importer for source brain folders. Supports preview mode (execute=false) and execute mode (execute=true) with folder-based routing and car-profile consolidation.
inputSchema:
type: object
properties:
sourceRoot:
type: string
execute:
type: boolean
maxFiles:
type: number
skipRawCatalogs:
type: boolean
excludeDirs:
type: array
items:
type: string
chunkSize:
type: number
runLabel:
type: string
logTiming:
type: boolean
previewLimit:
type: number
required:
- sourceRoot
- name: export_wiki
summary: Export Wiki
description: Export wiki pages to a ZIP archive. Without outputPath, the server returns a downloadUrl on the issuing deployment. Send GET to this URL without another credential. The token grants access to that archive for 24 hours. Keep the URL private. Repeat calls within that period reuse the archive. With outputPath, the server writes the ZIP to that path instead. Optional filters select a folder prefix or any matching tag.
inputSchema:
type: object
properties:
outputPath:
type: string
includeSystem:
type: boolean
folder:
type: string
tags:
type: array
items:
type: string
- name: import_wiki
summary: Import Wiki
description: 'Import a wiki from a ZIP archive. Agent-friendly: pass zipData (a base64-encoded ZIP, e.g. downloaded from export_wiki''s downloadUrl and re-encoded) instead of zipPath for fully agent-reachable round-trips. Supports preview (execute=false) and execute (execute=true). Modes: mode=''additive'' updates/creates ZIP pages without deleting others; mode=''replace'' mirrors the ZIP exactly (imports all ZIP pages and deletes pages absent from the ZIP, always overwrite). When execute applies changes, response includes instructionRefreshRequired/discoveredFolders/nextAction hints for instruction refresh.'
inputSchema:
type: object
properties:
zipData:
type: string
zipPath:
type: string
execute:
type: boolean
mode:
type: string
enum:
- additive
- replace
conflictStrategy:
type: string
enum:
- skip
- overwrite
- merge
folder:
type: string
confirmWholeWiki:
type: boolean
includeSystem:
type: boolean
logTiming:
type: boolean
- name: pull_session_bundle
summary: Pull Session Bundle
description: 'Downloads all relevant wiki pages for your project as a single plain-text bundle (no ZIP decode needed). The returned bundle IS your working set: every listed page is included in full, so do NOT call read_page on any of them afterwards. Work locally in this conversation, then push back with push_session_bundle when done. Measured 10.04s of individual read_page calls versus 3.47s for the same ten pages bundled. For a project, prefer folder=projects/<slug> over tags — folder membership is structural and cannot drift, whereas tags are hand-maintained and frequently incomplete (measured on a real wiki: tags returned 0 of 39 pages for one project and 2 of 49 for another, while the folder selector returned all of them). Use tags only for cross-cutting themes that span folders. If you do not know the project slug, do NOT guess one: list_pages with folder=''projects'' shows the available projects — resolve the slug first, then pull. Leave maxBytes at its default unless you need a smaller slice. The default already matches the largest response this transport can carry without dropping the connection. A value above that hard cap returns an error, not a slice. Paginate via nextCursor to reach the rest of a large folder. Each entry in the returned ''pages'' array includes a ''revision'' — pass it back on the matching page in push_session_bundle''s pages mode to get conflict protection against other concurrent writers (e.g. a shared project).'
inputSchema:
type: object
properties:
folder:
type: string
tags:
type: array
items:
type: string
query:
type: string
includeSystem:
type: boolean
cursor:
type: string
maxBytes:
type: number
maxPages:
type: number
session_audience:
type: string
enum:
- internal
- client-safe
- public
- name: push_session_bundle
summary: Push Session Bundle
description: 'PREFERRED write-back tool when paired with pull_session_bundle. Two modes: (1) pages mode (recommended) — pass pages=[{name,content,revision?}] for each page you modified; avoids token-limit issues with large bundles. (2) bundle mode (small bundles <20 KB only) — pass bundle string + manifest array. Both modes use the same conflict-strategy semantics. In pages mode, include the ''revision'' you got from pull_session_bundle/read_page for each page — if someone else changed that page in the meantime, the write is rejected as a conflict (returned in ''conflicts'') instead of overwriting their change; re-read the page, reconcile, and push again with the fresh revision. Omitting revision falls back to conflictStrategy-only behavior (no conflict protection). Returns ok, created, updated, skipped, conflicts, and any per-page errors.'
inputSchema:
type: object
properties:
bundle:
type: string
manifest:
type: array
items:
type: object
properties:
name:
type: string
required:
- name
pages:
type: array
items:
type: object
properties:
name:
type: string
content:
type: string
revision:
type: string
required:
- name
- content
conflictStrategy:
type: string
enum:
- overwrite
- skip
- error
includeSystem:
type: boolean
- name: purge_wiki
summary: Purge Wiki
description: Permanently delete all wiki pages. Returns a warning and file list when confirm=false. Set confirm=true to proceed. Set exportBeforeDelete=true with exportOutputPath to create a ZIP backup first.
inputSchema:
type: object
properties:
confirm:
type: boolean
exportBeforeDelete:
type: boolean
exportOutputPath:
type: string
includeSystem:
type: boolean
- name: update_page
summary: Update Page
description: 'FULL REWRITE tool: replaces the page body. Requires fileId and revision from read_page to prevent conflicts — both come from a full read, so this tool cannot be used on a page too large to read or re-emit in one call. Returns bytesWritten (UTF-8 byte count of the written file). Prefer patch_page for targeted edits (use replace_lines when possible); use update_page when intentionally rewriting most/all content. For adding one entry to a large page, use patch_page with a single {"type": "append"} operation instead — it needs no prior read_page and no revision/fileId (it still counts against the page''s byte size cap like any other write). Ingest responsibility rule: when refining ingest docs, distribute content into canonical/, projects/, and decisions/ pages where appropriate instead of leaving everything in data/.'
inputSchema:
type: object
properties:
name:
type: string
fileId:
type: string
revision:
type: string
body:
type: string
frontmatterPatch: {}
summary:
type: string
required:
- name
- revision
- body
- name: patch_page
summary: Patch Page
description: 'PREFERRED EDIT tool for small/medium changes, and the ONLY edit tool safe on a page too large to read or re-emit in full: {"type": "append"} appends to the raw file server-side and needs no prior read_page and no revision/fileId (GH #632) — it is still subject to the page''s byte size cap and will throw PageSizeError if the result exceeds it. Patch a page with surgical edits in one call. Returns bytesWritten (UTF-8 byte count of the file after patching). Supports text anchors and line-range replacement (replace_lines with 1-based line numbers over the page BODY only — the same ''content'' field read_page returns, never counting YAML frontmatter), and accepts multiple operations in an array. Each operation MUST include a ''type'' field (one of: replace, insert_after, insert_before, append, replace_lines). Example replace op: {"type": "replace", "find": "## Status\nOld text", "replace": "## Status\nNew text"}.'
inputSchema:
type: object
properties:
name:
type: string
operations:
type: array
items: {}
summary:
type: string
required:
- name
- operations
- name: move_page
summary: Move Page
description: Archive (prefix with 'archive-') or rename a wiki page. No hard deletion in v1.
inputSchema:
type: object
properties:
name:
type: string
action:
type: string
enum:
- archive
- rename
newName:
type: string
required:
- name
- action
- name: append_log
summary: Append Log
description: Append an entry to the wiki log. Use for ingest, query, lint, and error events.
inputSchema:
type: object
properties:
type:
type: string
enum:
- ingest
- query
- update
- create
- move
- lint
- error
title:
type: string
detail:
type: string
required:
- type
- title
- name: health_check
summary: Health Check
description: 'Check server health: storage backend connectivity (Supabase Storage), search index status (Postgres FTS), uptime, and session log status. Call once at session start to confirm the server is reachable before doing work.'
inputSchema:
type: object
properties: {}
- name: component_manifest
summary: Component Manifest
description: Look up the brains-web UI component library (apps/web/components/ui) before writing a new button, input, card, or alert. Call with no arguments to list every component with its variants. Call with `name` for one component's full prop list and example usage from its Storybook stories. Call with `query` to search names, descriptions, and prop names by keyword. Check this before hand-rolling a className="btn" or similar — reuse an existing component if one fits.
inputSchema:
type: object
properties:
name:
type: string
query:
type: string
- name: generate_claude_instructions
summary: Generate Claude Instructions
description: Refresh the Claude instruction block for an EXISTING Brains-connected project. Returns a markdown block the user can paste into their Claude Project system prompt. For NEW projects, call init_project first — it scaffolds the brain pages and emits the same instruction block.
inputSchema:
type: object
properties:
projectName:
type: string
variant:
type: string
enum:
- minimal
- extended
- pointer
projectPage:
type: string
inScopePaths:
type: array
items:
type: string
materialOutcomeDefinition:
type: string
includeExamples:
type: boolean
required:
- projectName
- name: generate_gpt_instructions
summary: Generate Gpt Instructions
description: Refresh the ChatGPT instruction block for an EXISTING Brains-connected project. Returns a markdown block the user can paste into their ChatGPT system prompt. For NEW projects, call init_project first — it scaffolds the brain pages and emits the same instruction block.
inputSchema:
type: object
properties:
projectName:
type: string
variant:
type: string
enum:
- minimal
- extended
- pointer
projectPage:
type: string
inScopePaths:
type: array
items:
type: string
materialOutcomeDefinition:
type: string
includeExamples:
type: boolean
required:
- projectName
- name: resolve_project
summary: Resolve Project
description: 'Call this FIRST when the user refers to a project, vehicle, property, client or topic by name and you do not already know its brains project slug. Turns freeform context into the project slug plus the path to its instruction file, so you can pull the right project instead of guessing a tag. Returns ranked matches with a confidence and an `ambiguous` flag — when ambiguous is true or confidence is low, ask the user rather than loading a project. Does not load anything itself: follow up with pull_session_bundle(folder: "projects/<slug>").'
inputSchema:
type: object
properties:
context:
type: string
platform:
type: string
enum:
- claude
- gpt
limit:
type: number
required:
- context
- name: init_project
summary: Init Project
description: FIRST CALL for any new Brains setup. Creates the project brain pages (projects/instructions/decisions scaffolding) and returns a ready-to-paste instruction block for Claude or ChatGPT. Idempotent — safe to re-run. To refresh instructions on an already-initialized project, use generate_claude_instructions or generate_gpt_instructions instead.
inputSchema:
type: object
properties:
projectSlug:
type: string
projectName:
type: string
platform:
type: string
enum:
- claude
- gpt
variant:
type: string
enum:
- minimal
- extended
writeInstructionFile:
type: boolean
seedFoundation:
type: boolean
ensureActiveTrackingPages:
type: boolean
execute:
type: boolean
required:
- projectName
- name: audit_index
summary: Audit Index
description: Diagnose and repair index/storage drift. Reads the Postgres index, checks each entry against the storage backend, and reports ghost rows (in index but not in storage) and unindexed pages (in storage but not in index). Safe read-only by default. Set cleanup=true to delete ghost rows and re-index missing pages. Writes a log entry when cleanup runs. Requires Postgres index to be configured.
inputSchema:
type: object
properties:
cleanup:
type: boolean
skipReadConfirmation:
type: boolean
- name: extract_links
summary: Extract Links
description: Run link extraction over a filtered set of wiki pages. Inserts/updates rows in the server-side wiki_links graph for pages where the on-write hook missed (e.g. legacy pages, ingest backfill). Requires at least one of tags or folder. Returns { pagesConsidered, pagesProcessed, linksExtracted }. pagesConsidered is every page matching the tags/folder filter; pagesProcessed is the subset that was stale and got re-indexed. pagesProcessed=0 with pagesConsidered>0 means every matching page was already up to date — that is success, not failure. pagesConsidered=0 means the filter matched no pages at all.
inputSchema:
type: object
properties:
tags:
type: array
items:
type: string
folder:
type: string
- name: get_backlinks
summary: Get Backlinks
description: Return the list of pages that link TO the given page (incoming references). Uses the server-side wiki_links graph; pages not yet indexed produce empty results — call extract_links first if needed.
inputSchema:
type: object
properties:
name:
type: string
required:
- name
- name: get_related
summary: Get Related
description: Return pages that share outbound link targets with the given page (second-degree neighbors). Uses the server-side wiki_links graph; pages not yet indexed produce empty results — call extract_links first if needed.
inputSchema:
type: object
properties:
name:
type: string
required:
- name
- name: suggest_links
summary: Suggest Links
description: 'Retroactive linking audit: find wiki pages that lack a ''## Related pages'' section and return ready-to-apply markdown patches suggesting cross-references. Filters by tags or folder. Uses the server-side link graph (shared outbound targets, backlinks) when available; falls back to tag-overlap heuristics. Never writes — patches require explicit review and confirmation before applying with patch_page.'
inputSchema:
type: object
properties:
tags:
type: array
items:
type: string
folder:
type: string
maxPages:
type: number
- name: delete_page
summary: Delete Page
description: Archive-then-delete a single wiki page. On confirm=true, writes a recoverable archived_pages row (origin path/folder, content, metadata, deleted_by, optional reason) before deleting from live storage/index. Set confirm=false (default) for a dry-run preview. Protected system pages (instructions/brain-routing.md, decisions/readme.md, history/readme.md, log.md, index.md) cannot be deleted.
inputSchema:
type: object
properties:
name:
type: string
confirm:
type: boolean
reason:
type: string
required:
- name
- name: batch_delete_pages
summary: Batch Delete Pages
description: Archive-then-delete up to 50 wiki pages in one call. For each page, writes a recoverable archived_pages row before deleting from live storage/index. Set confirm=false (default) for a dry-run manifest. Set confirm=true to execute. Protected system pages are silently skipped.
inputSchema:
type: object
properties:
names:
type: array
items:
type: string
confirm:
type: boolean
reason:
type: string
required:
- names
- name: list_archived_pages
summary: List Archived Pages
description: List archived_pages rows for the current user (id, original path/folder, deleted_at, deleted_by, reason, restore status). Use this to discover restore candidates.
inputSchema:
type: object
properties:
limit:
type: number
includeRestored:
type: boolean
originalPath:
type: string
- name: stale_pages
summary: Stale Pages
description: 'Read-only cold-page report (GH #497 milestone 1): pages in the caller''s own wiki last modified before olderThanDays (default 90) with zero search_relevance_signals engagement since that cutoff, sorted coldest-first. Surfaces candidates only — does not archive or delete. Falls back to age-only results with signalsAvailable:false if the signals table is unreachable or Postgres search is not configured.'
inputSchema:
type: object
properties:
olderThanDays:
type: number
limit:
type: number
- name: restore_page
summary: Restore Page
description: Restore a previously archived page by archiveId or originalPath (+ optional deletedAt). Recreates the page at original path or targetPath, re-indexes it, and stamps restored_at/restored_by on the archive row. Enforces page-limit checks.
inputSchema:
type: object
properties:
archiveId:
type: string
originalPath:
type: string
deletedAt:
type: string
targetPath:
type: string
- name: set_webhook
summary: Set Webhook
description: Create or update an outbound webhook rule. The rule fires a signed POST to the target URL whenever a page matching one of its glob/regex patterns is created or updated. Omit 'id' to create a new rule; pass an existing 'id' to update it. Patterns use glob syntax (e.g. 'projects/brainsapp/open-loop-*.md') or /regex/ syntax.
inputSchema:
type: object
properties:
id:
type: string
name:
type: string
url:
type: string
patterns:
type: array
items:
type: string
events:
type: array
items:
type: string
enum:
- create
- update
secret:
type: string
enabled:
type: boolean
required:
- name
- url
- patterns
- name: list_webhooks
summary: List Webhooks
description: List all outbound webhook rules configured for the current user.
inputSchema:
type: object
properties: {}
- name: remove_webhook
summary: Remove Webhook
description: Permanently delete an outbound webhook rule by ID.
inputSchema:
type: object
properties:
id:
type: string
required:
- id
- name: add_webhook_pattern
summary: Add Webhook Pattern
description: Append a glob or regex pattern to an existing webhook rule's pattern list. Idempotent — adding a pattern that already exists is a no-op.
inputSchema:
type: object
properties:
id:
type: string
pattern:
type: string
required:
- id
- pattern
- name: list_page_history
summary: List Page History
description: List the version history for a wiki page. Returns snapshots captured before each update_page or patch_page call, newest-first. Use read_page_version to retrieve the content of a specific snapshot.
inputSchema:
type: object
properties:
name:
type: string
required:
- name
- name: read_page_version
summary: Read Page Version
description: Read a specific historical snapshot of a wiki page. Use list_page_history to get the timestamp key, then call this tool to retrieve the full content of that version.
inputSchema:
type: object
properties:
name:
type: string
timestamp:
type: string
required:
- name
- timestamp