Skip to main content
← Back to Docs

SDK Reference

@brain-protocol/sdk v0.3.3 — Zero runtime dependencies, native fetch, TypeScript-first.

Installation

npm install @brain-protocol/sdk

Client Initialization

import { BrainClient } from"@brain-protocol/sdk";

const client = new BrainClient({
 baseUrl:"https://brain.api.vauban.tech",
 apiKey:"sk_...", // API key auth
 // OR
 jwtToken:"eyJ...", // JWT auth
});

API keys use X-API-Key header. JWT uses Authorization: Bearer.

Fluent API (Top-Level)

Convenience methods on the client for the most common operations.

MethodParametersReturnsDescription
client.remember(input)CreateEntryInputKnowledgeEntryCreate entry
client.recall(query, opts?)string, QueryOptionsKnowledgeEntry[]Search entries
client.prove(id, vcOptions)string, BuildVCOptionsVerifiableCredentialAnchor + get W3C VC
client.traverse(id, depth?)string, numberGraphResultGraph traversal
client.link(source, target, type)string, string, stringKnowledgeEdgeCreate edge
client.ping()booleanHealth check
client.stats()StoreStatsStore statistics
client.export()ExportDataExport all data

client.knowledge

Core CRUD + search + anchoring for knowledge entries.

MethodParametersReturnsDescription
create(input)CreateEntryInputKnowledgeEntryCreate entry
query(options?)QueryOptions{ entries, total }FTS + filters
get(id)stringKnowledgeEntry | nullGet by ID
update(id, input)string, Partial<CreateEntryInput>KnowledgeEntryPartial update
delete(id)stringbooleanDelete entry
prove(id)stringProveResultAnchor to Starknet
verify(id)stringVerifyResultVerify anchor
versions(id)stringKnowledgeEntry[]Version history

CreateEntryInput

FieldTypeRequiredDescription
contentstringrequiredContent text
content_typeContentTypeoptionalmarkdown, code, decision, pattern, documentation, git_commit, json
categorystringoptionalCategory (default: documentation)
authorstringoptionalAuthor name
tagsstring[]optionalTags array
confidencenumberoptional0-1 (default: 0.8)
metadataRecord<string, unknown>optionalCustom metadata
brain_idstringoptionalTarget brain UUID
is_publicbooleanoptionalPublic visibility

QueryOptions

FieldTypeRequiredDescription
qstringoptionalFull-text search query
categorystringoptionalFilter by category
authorstringoptionalFilter by author
tagsstringoptionalComma-separated tags
limitnumberoptionalMax results
offsetnumberoptionalPagination offset
brain_idsstring[]optionalFilter by brain IDs
confidence_minnumberoptionalMinimum confidence

client.edges

MethodParametersReturnsDescription
create(input)CreateEdgeInputKnowledgeEdgeCreate typed edge

Edge types: derives_from, validates, extends, implements, conflicts_with, supersedes, tested_by, documented_by, optimizes, related_to

client.graph

MethodParametersReturnsDescription
traverse(entryId, depth?)string, numberGraphResultTraverse from entry (default depth: 3)
overview(options?){ limit?, brain_id? }GraphResultFull graph overview

client.brains

Multi-tenant knowledge workspaces with member management.

MethodParametersReturnsDescription
create(input){ name, description? }BrainCreate brain
list()Brain[]List all brains
get(id)stringBrainGet brain by ID
update(id, input)string, Partial<...>BrainUpdate brain
addMember(brainId, address, role?)string, string, stringBrainMemberAdd member
removeMember(brainId, accountId)string, stringvoidRemove member

client.agents

Agent telemetry — log task executions, track cost and performance.

MethodParametersReturnsDescription
logTask(task)AgentTaskInputAgentTaskLog task execution
stats()AgentStatsAggregated stats
taskHistory(agentName, limit?)string, numberAgentTask[]Task history

client.development

Pattern intelligence — analyze code against the knowledge base.

MethodParametersReturnsDescription
suggestPatterns(code, fileType)string, stringPatternSuggestion[]Suggest design patterns
detectAntiPatterns(code, fileType)string, stringAntiPatternWarning[]Detect anti-patterns
architecturalAdvice(code, context)string, stringArchitecturalAdvice[]Architecture recommendations
realtimeAnalysis(content, path)string, stringRealtimeAnalysisResultFull analysis

client.giza

Archive and query Giza zkML proofs as verifiable knowledge entries.

MethodParametersReturnsDescription
archiveProof(input)ArchiveGizaProofInputKnowledgeEntryArchive zkML proof
queryProofs(options?)GizaProofQueryOptions{ entries, total }Query proofs
extractProof(entry)KnowledgeEntryGizaProofResult | nullExtract proof from metadata
linkProofToEntry(proofId, targetId, type?)string, string, stringKnowledgeEdgeLink proof to entry

client.billing

MethodParametersReturnsDescription
prices()BillingPricesGet pricing tiers
checkout(input){ tier, success_url, cancel_url }CheckoutSessionResultCreate Stripe checkout
portal(returnUrl)stringPortalSessionResultCustomer portal URL
subscription()BillingSubscriptionCurrent subscription

client.keys

MethodParametersReturnsDescription
create(name)stringApiKeyCreateResultCreate API key
list()ApiKeyInfo[]List keys
rotate(id)stringApiKeyRotateResultRotate key (new secret, same ID)
revoke(id)string{ revoked: boolean }Revoke key

client.usage

MethodParametersReturnsDescription
get(days?)numberUsageSummaryUsage stats (default 30 days)

Utilities

MethodParametersReturnsDescription
buildVerifiableCredential(entry, anchor, opts)KnowledgeEntry, AnchorResult, BuildVCOptionsVerifiableCredentialBuild W3C VC from entry + anchor
withRetry(fn, config?)() => Promise<T>, RetryConfigPromise<T>Retry with exponential backoff (5xx/network, fail-fast 4xx)
import { withRetry } from"@brain-protocol/sdk";

const result = await withRetry(
 () => client.knowledge.query({ q:"patterns" }),
 { maxAttempts: 4, initialDelayMs: 100 }
);

Examples

Create, Query, Link
// Create entries
const entry1 = await client.remember({
 content:"Circuit breaker pattern prevents cascade failures",
 category:"pattern",
 confidence: 0.95,
});

const entry2 = await client.remember({
 content:"Retry with exponential backoff for transient errors",
 category:"pattern",
 confidence: 0.9,
});

// Link them
await client.link(entry2.id, entry1.id,"extends");

// Query
const results = await client.recall("circuit breaker");

// Traverse graph
const graph = await client.traverse(entry1.id, 2);
Anchor + Verify
// Anchor to Starknet
const proof = await client.knowledge.prove(entry.id);
// proof.tx_hash — Starknet transaction
// proof.content_hash — Poseidon hash

// Get W3C Verifiable Credential
const vc = await client.prove(entry.id, {
 issuer:"my-app",
 explorerBaseUrl:"https://starkscan.co",
});
ESC
Navigation
Admin
Docs
↑↓NavigateSelectescClose
SDK Reference — Brain Protocol | Brain Protocol