Package Exports
- @rhun/sdk
- @rhun/sdk/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rhun/sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Rhun SDK
A TypeScript SDK for interacting with Rhun AI Agents.
Installation
npm install @rhun/sdkGetting Started
1. Get Your API Key
- Visit https://beta.rhun.io
- Connect your wallet
- Your API key will be available in the account section
- Store your API key securely - never commit it to version control
2. Set Up Environment Variables
Create a .env file in your project root:
RHUN_API_KEY=your_api_key_hereDevelopment Setup
If you want to build the SDK from source:
- Clone the repository:
git clone https://github.com/rhun-ai/rhun-sdk.git
cd rhun-sdk- Install dependencies:
npm install- Build the project:
npm run build- Run tests:
npm testUsage
import { RhunClient } from '@rhun/sdk';
// Initialize the client
const client = new RhunClient({
apiKey: process.env.RHUN_API_KEY, // Best practice: use environment variables
baseUrl: 'https://beta.rhun.io'
});
// Create a crypto research agent
const agent = await client.createAgent({
name: 'Token Scout',
description: 'Crypto research specialist focusing on token discovery, market analysis, and due diligence. Equipped with comprehensive token database access and real-time market data.',
coreCapabilities: 'Token search and analysis, market data aggregation, contract verification, liquidity analysis',
interactionStyle: 'Informative and precise, with clear risk disclaimers',
analysisApproach: 'Multi-factor analysis combining on-chain data, market metrics, and social signals',
riskCommunication: 'Detailed risk assessment with contract audit status and liquidity metrics',
responseFormat: 'Token summary followed by key metrics and risk factors'
});
// Example: Search for tokens and analyze market data
await client.streamChat(agent.id, 'Find new DeFi tokens and analyze their metrics', (chunk) => {
if (chunk.type === 'message') {
// Handle narrative responses
console.log('Analysis:', chunk.data.content);
} else if (chunk.type === 'tool_invocation') {
const tool = chunk.data;
switch (tool.tool) {
case 'getRecentlyLaunchedCoins':
// Handle newly launched tokens
console.log('New tokens:', tool.output.tokens.map(t => ({
name: t.name,
chain: t.chain,
launchDate: t.launchDate
})));
break;
case 'getTokenInfo':
// Handle detailed token information
console.log('Token details:', {
price: tool.output.price,
volume24h: tool.output.volume24h,
marketCap: tool.output.marketCap,
holders: tool.output.holders
});
break;
case 'getTopHolders':
// Handle holder distribution analysis
console.log('Top holders:', tool.output.holders.map(h => ({
address: h.address,
percentage: h.percentage,
balance: h.balance
})));
break;
case 'getFearAndGreedIndex':
// Handle market sentiment data
console.log('Market sentiment:', tool.output.value, tool.output.classification);
break;
}
}
});
// Example: Get technical analysis with TradingView charts
const response = await client.chat(agent.id, 'Show me technical analysis for SOL');
console.log('Analysis:', response.message.content);
// Update agent with enhanced capabilities
const updatedAgent = await client.updateAgent(agent.id, {
description: 'Advanced market analyst with real-time technical analysis and sentiment tracking',
coreCapabilities: 'Technical analysis, market sentiment, holder analysis, trend prediction'
});API Reference
RhunClient
The main client class for interacting with the Rhun API.
Constructor
new RhunClient(config: RhunClientConfig)config.apiKey: Your Rhun API key (will be sent as a Bearer token)config.baseUrl: (optional) The base URL for the API. Defaults to https://beta.rhun.io
Methods
createAgent(config: AgentConfig): Promise<Agent>getAgent(agentId: string): Promise<Agent>updateAgent(agentId: string, config: Partial<AgentConfig>): Promise<Agent>deleteAgent(agentId: string): Promise<void>listAgents(): Promise<Agent[]>chat(agentId: string, message: string): Promise<ChatResponse>streamChat(agentId: string, message: string, onChunk: (chunk: StreamChatResponse) => void): Promise<void>
Types
AgentConfig
Configuration for creating/updating an agent:
Required fields:
name: string- Agent namedescription: string- Agent description
Optional fields:
image?: Buffer | string- Agent profile image (Buffer or file path)
Advanced Configuration (all optional):
coreCapabilities?: string- Core capabilities and knowledge domainsinteractionStyle?: string- How the agent should interactanalysisApproach?: string- How the agent should analyze problemsriskCommunication?: string- How to communicate risksresponseFormat?: string- Structure for responseslimitationsDisclaimers?: string- Agent limitationsprohibitedBehaviors?: string- What the agent must not doknowledgeUpdates?: string- How to handle knowledge updatesstyleGuide?: string- Communication style guidelinesspecialInstructions?: string- Special handling instructionsresponsePriorityOrder?: string- Priority order for responses
System-managed fields (do not set these manually):
userId?: string- Set automatically from authenticationcreatedAt?: string- Set automatically on creationupdatedAt?: string- Set automatically on updates
Other Types:
Agent: An agent instanceChatMessage: A message in a chatToolInvocation: A tool invocation by an agentChatResponse: Response from a chat requestStreamChatResponse: Response chunk from a streaming chat request
License
MIT