Configuration
Configuration
This page covers all configuration options for the Chaos SDK client.
ChaosConfig Interface
The ChaosConfig interface defines the configuration options for initializing the Chaos client:
/**
* Configuration for the Chaos client.
*/
export interface ChaosConfig {
/** API key for authentication */
apiKey: string;
/** Base URL for the API (defaults to https://ai-staging.chaoslabs.co) */
baseUrl?: string;
/** Request timeout in milliseconds (defaults to 120000) */
timeout?: number;
}Configuration Options
apiKey (required)
Your Chaos API key for authentication. This is the only required configuration option.
baseUrl (optional)
The base URL for the API. Defaults to https://ai-staging.chaoslabs.co.
timeout (optional)
Request timeout in milliseconds. Defaults to 120000 (2 minutes). If a request exceeds this timeout, a ChaosTimeoutError will be thrown.
Basic Configuration
import Chaos from '@chaoslabs/ai-sdk';
// Minimal configuration (uses defaults)
const client = new Chaos({
apiKey: process.env.CHAOS_API_KEY!,
});Full Configuration
import Chaos from '@chaoslabs/ai-sdk';
// Full configuration with all options
const client = new Chaos({
apiKey: process.env.CHAOS_API_KEY!,
baseUrl: 'https://ai-staging.chaoslabs.co',
timeout: 180000, // 3 minutes
});Model Constants
The SDK exports two model constants for use with the model parameter in requests:
import { WALLET_MODEL, ASK_MODEL } from '@chaoslabs/ai-sdk';
// WALLET_MODEL = 'wallet'
// Use for DeFi operations like swap, supply, borrow, withdraw, etc.
// Requires wallet_id in metadata
// ASK_MODEL = 'ask'
// Use for research queries and informational requests
// Does not require wallet_idModel Selection Guide
| Use Case | Model | Example |
|---|---|---|
| Swap tokens | WALLET_MODEL | "Swap 1 ETH for USDC" |
| Supply to protocol | WALLET_MODEL | "Supply 1000 USDC to Aave" |
| Borrow assets | WALLET_MODEL | "Borrow 500 DAI from Compound" |
| Research TVL | ASK_MODEL | "What is the TVL of Uniswap?" |
| Market analysis | ASK_MODEL | "Compare lending rates across protocols" |
| Protocol info | ASK_MODEL | "How does Aave liquidation work?" |
Environment Setup
We recommend storing your API key in environment variables:
Using dotenv
import 'dotenv/config';
import Chaos from '@chaoslabs/ai-sdk';
const client = new Chaos({
apiKey: process.env.CHAOS_API_KEY!,
});Environment file
# Chaos AI SDK
CHAOS_API_KEY=your-api-key-here
# Optional: Custom base URL
# CHAOS_BASE_URL=https://custom-api.example.comNext Steps
- Response Handling - Work with API responses
- Block Types - Understand block types