Official JavaScript SDK for the CerebroChain Bot API — zero dependencies, native fetch
Package Exports
@cerebrochain/bot-sdk
@cerebrochain/bot-sdk/errors
Readme
@cerebrochain/bot-sdk
Official JavaScript SDK for the CerebroChain Bot API. Zero dependencies -- uses native fetch
(Node.js 18+).
Install
npminstall @cerebrochain/bot-sdk
Quick Start (Free Tier - No API Key Required)
import{ CerebroChainClient }from'@cerebrochain/bot-sdk';// Free tier: 100 API calls/day with just your wallet addressconst client =newCerebroChainClient({agentAddress:'0xYourWalletAddress',});// Discover servicesconst catalog =await client.getCatalog();const card =await client.getAgentCard();
console.log(`Free calls remaining: ${client.freeTierRemaining}`);
Full API Key Setup
const client =newCerebroChainClient({apiKey: process.env.CEREBROCHAIN_API_KEY,// Get yours at https://cerebrochain.com/developersagentAddress:'0xYourWalletAddress',// Optional: for trust-tier pricing});// List available servicesconst{ services }=await client.getServices();
console.log(services);// Check your balanceconst{ balance }=await client.getBalance();
console.log(`Credits: ${balance.credits}, Tier: ${balance.tier}`);// Get freight ratesconst rates =await client.getFreightRates({origin:{city:'Los Angeles',state:'CA',zip:'90001',country:'US'},destination:{city:'New York',state:'NY',zip:'10001',country:'US'},packages:[{weight:10,dimensions:{length:12,width:8,height:6}}],});// AI inference (DeepSeek, Groq Llama, OpenRouter free models)const result =await client.aiInference({model:'deepseek-chat',messages:[{role:'user',content:'Summarize supply chain risks for Q1'}],});
Configuration
const client =newCerebroChainClient({apiKey:'cbbot_...',// Optional if using free tieragentAddress:'0x...',// ERC-8004 agent address (for free tier + trust pricing)baseUrl:'https://cerebrochain.com',// DefaultmaxRetries:3,// Auto-retry on 429 (default: 3)retryDelayMs:1000,// Fallback delay when Retry-After header absent});
Error Handling
import{ CerebroChainClient, CerebroChainError, ErrorCodes }from'@cerebrochain/bot-sdk';try{await client.getBalance();}catch(err){if(err instanceofCerebroChainError){
console.log(err.status);// HTTP status (e.g. 401, 429)
console.log(err.code);// Machine-readable code (e.g. "RATE_LIMITED")
console.log(err.details);// Raw API error payload}}
Rate-limited requests (HTTP 429) are automatically retried up to maxRetries times with exponential
back-off. The SDK respects the Retry-After header (both seconds and HTTP-date formats).
All methods validate required parameters client-side and throw CerebroChainError with code
BAD_REQUEST before making a network request if inputs are missing.
Method Reference
Onboarding
Method
Description
HTTP
quickStart({ name, email, description })
Register a bot and get an API key with free credits