← Back to Docs
SDK Reference
@brain-protocol/sdk v0.3.3 — Zero runtime dependencies, native fetch, TypeScript-first.
Installation
npm install @brain-protocol/sdkClient 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.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| client.remember(input) | CreateEntryInput | KnowledgeEntry | Create entry |
| client.recall(query, opts?) | string, QueryOptions | KnowledgeEntry[] | Search entries |
| client.prove(id, vcOptions) | string, BuildVCOptions | VerifiableCredential | Anchor + get W3C VC |
| client.traverse(id, depth?) | string, number | GraphResult | Graph traversal |
| client.link(source, target, type) | string, string, string | KnowledgeEdge | Create edge |
| client.ping() | — | boolean | Health check |
| client.stats() | — | StoreStats | Store statistics |
| client.export() | — | ExportData | Export all data |
client.knowledge
Core CRUD + search + anchoring for knowledge entries.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| create(input) | CreateEntryInput | KnowledgeEntry | Create entry |
| query(options?) | QueryOptions | { entries, total } | FTS + filters |
| get(id) | string | KnowledgeEntry | null | Get by ID |
| update(id, input) | string, Partial<CreateEntryInput> | KnowledgeEntry | Partial update |
| delete(id) | string | boolean | Delete entry |
| prove(id) | string | ProveResult | Anchor to Starknet |
| verify(id) | string | VerifyResult | Verify anchor |
| versions(id) | string | KnowledgeEntry[] | Version history |
CreateEntryInput
| Field | Type | Required | Description |
|---|---|---|---|
| content | string | required | Content text |
| content_type | ContentType | optional | markdown, code, decision, pattern, documentation, git_commit, json |
| category | string | optional | Category (default: documentation) |
| author | string | optional | Author name |
| tags | string[] | optional | Tags array |
| confidence | number | optional | 0-1 (default: 0.8) |
| metadata | Record<string, unknown> | optional | Custom metadata |
| brain_id | string | optional | Target brain UUID |
| is_public | boolean | optional | Public visibility |
QueryOptions
| Field | Type | Required | Description |
|---|---|---|---|
| q | string | optional | Full-text search query |
| category | string | optional | Filter by category |
| author | string | optional | Filter by author |
| tags | string | optional | Comma-separated tags |
| limit | number | optional | Max results |
| offset | number | optional | Pagination offset |
| brain_ids | string[] | optional | Filter by brain IDs |
| confidence_min | number | optional | Minimum confidence |
client.edges
| Method | Parameters | Returns | Description |
|---|---|---|---|
| create(input) | CreateEdgeInput | KnowledgeEdge | Create typed edge |
Edge types: derives_from, validates, extends, implements, conflicts_with, supersedes, tested_by, documented_by, optimizes, related_to
client.graph
| Method | Parameters | Returns | Description |
|---|---|---|---|
| traverse(entryId, depth?) | string, number | GraphResult | Traverse from entry (default depth: 3) |
| overview(options?) | { limit?, brain_id? } | GraphResult | Full graph overview |
client.brains
Multi-tenant knowledge workspaces with member management.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| create(input) | { name, description? } | Brain | Create brain |
| list() | — | Brain[] | List all brains |
| get(id) | string | Brain | Get brain by ID |
| update(id, input) | string, Partial<...> | Brain | Update brain |
| addMember(brainId, address, role?) | string, string, string | BrainMember | Add member |
| removeMember(brainId, accountId) | string, string | void | Remove member |
client.agents
Agent telemetry — log task executions, track cost and performance.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| logTask(task) | AgentTaskInput | AgentTask | Log task execution |
| stats() | — | AgentStats | Aggregated stats |
| taskHistory(agentName, limit?) | string, number | AgentTask[] | Task history |
client.development
Pattern intelligence — analyze code against the knowledge base.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| suggestPatterns(code, fileType) | string, string | PatternSuggestion[] | Suggest design patterns |
| detectAntiPatterns(code, fileType) | string, string | AntiPatternWarning[] | Detect anti-patterns |
| architecturalAdvice(code, context) | string, string | ArchitecturalAdvice[] | Architecture recommendations |
| realtimeAnalysis(content, path) | string, string | RealtimeAnalysisResult | Full analysis |
client.giza
Archive and query Giza zkML proofs as verifiable knowledge entries.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| archiveProof(input) | ArchiveGizaProofInput | KnowledgeEntry | Archive zkML proof |
| queryProofs(options?) | GizaProofQueryOptions | { entries, total } | Query proofs |
| extractProof(entry) | KnowledgeEntry | GizaProofResult | null | Extract proof from metadata |
| linkProofToEntry(proofId, targetId, type?) | string, string, string | KnowledgeEdge | Link proof to entry |
client.billing
| Method | Parameters | Returns | Description |
|---|---|---|---|
| prices() | — | BillingPrices | Get pricing tiers |
| checkout(input) | { tier, success_url, cancel_url } | CheckoutSessionResult | Create Stripe checkout |
| portal(returnUrl) | string | PortalSessionResult | Customer portal URL |
| subscription() | — | BillingSubscription | Current subscription |
client.keys
| Method | Parameters | Returns | Description |
|---|---|---|---|
| create(name) | string | ApiKeyCreateResult | Create API key |
| list() | — | ApiKeyInfo[] | List keys |
| rotate(id) | string | ApiKeyRotateResult | Rotate key (new secret, same ID) |
| revoke(id) | string | { revoked: boolean } | Revoke key |
client.usage
| Method | Parameters | Returns | Description |
|---|---|---|---|
| get(days?) | number | UsageSummary | Usage stats (default 30 days) |
Utilities
| Method | Parameters | Returns | Description |
|---|---|---|---|
| buildVerifiableCredential(entry, anchor, opts) | KnowledgeEntry, AnchorResult, BuildVCOptions | VerifiableCredential | Build W3C VC from entry + anchor |
| withRetry(fn, config?) | () => Promise<T>, RetryConfig | Promise<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",
});