Types Reference
The SDK root exports curated request, conversation, response, and contract types. Request and conversation typing is SDK-authored; many response and block types come from the generated Chaos AI contracts.
ChatCreateRequestInput
The SDK exports model-specific request input types plus a convenience union for shared handling.
type ChatCreateRequestInput =
| WalletChatCreateRequestInput
| AskChatCreateRequestInput;
interface WalletChatCreateRequestInput {
model: typeof WALLET_MODEL;
input: InputItem[];
stream?: boolean;
metadata: WalletRequestMetadataInput;
}
interface AskChatCreateRequestInput {
model: typeof ASK_MODEL;
input: InputItem[];
stream?: boolean;
metadata: AskRequestMetadataInput;
}ChatCreateRequestParams
chaos.chat.responses.create() accepts the exported discriminated union ChatCreateRequestParams, which adds an optional onStreamEvent callback to the model-specific request inputs.
type ChatCreateRequestParams =
| WalletChatCreateRequestParams
| AskChatCreateRequestParams;
interface WalletChatCreateRequestParams extends WalletChatCreateRequestInput {
onStreamEvent?: (message: ChaosSDKMessage) => void;
}
interface AskChatCreateRequestParams extends AskChatCreateRequestInput {
onStreamEvent?: (message: ChaosSDKMessage) => void;
}InputItem
A single message in the conversation input array.
interface InputItem {
type: "message";
role: "user" | "system" | "assistant";
content: string;
}| Field | Type | Description |
|---|---|---|
type | "message" | Always "message" |
role | "user" | "system" | "assistant" | The message role |
content | string | The message text |
RequestMetadataInput
Request metadata is model-specific. Use WalletRequestMetadataInput for WALLET_MODEL requests and AskRequestMetadataInput for ASK_MODEL requests.
interface WalletRequestMetadataInput {
user_id: string;
session_id: string;
wallets?: WalletInfo[];
walletContextOverride?: WalletContextOverride;
}
interface AskRequestMetadataInput {
user_id: string;
session_id: string;
}
type RequestMetadataInput =
| WalletRequestMetadataInput
| AskRequestMetadataInput;| Field | Type | Available On | Required | Description |
|---|---|---|---|---|
user_id | string | WALLET_MODEL, ASK_MODEL | Yes | Unique user identifier |
session_id | string | WALLET_MODEL, ASK_MODEL | Yes | Session identifier for conversation continuity |
wallets | WalletInfo[] | WALLET_MODEL | No | Array of wallet addresses for live wallet lookups |
walletContextOverride | WalletContextOverride | WALLET_MODEL | No | Injected wallet state for deterministic testing and simulations |
ASK_MODEL requests do not accept wallets or walletContextOverride.
WalletInfo
A wallet address on a specific chain.
interface WalletInfo {
address: string;
chain: string;
}const wallets: WalletInfo[] = [
{ address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', chain: 'ethereum' },
{ address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', chain: 'arbitrum' },
];WalletContextOverride
Provide a complete wallet context to bypass the server-side portfolio fetch. Useful for deterministic testing and simulations.
interface WalletContextOverride {
wallet_address: string;
balances: BalanceOverride[];
protocol_positions?: ProtocolPositionOverride[];
prices?: { [k: string]: number };
}
interface BalanceOverride {
symbol: string;
amount: number;
chain: string;
price?: number;
value_usd?: number;
}
interface ProtocolPositionOverride {
id: string;
name: string;
chain: string;
portfolio_items: PositionItemOverride[];
}
interface PositionItemOverride {
name: string;
assets: PositionAssetOverride[];
}
interface PositionAssetOverride {
symbol: string;
amount: number;
price: number;
}import { Chaos, WALLET_MODEL } from '@chaoslabs/ai-sdk';
import type {
WalletContextOverride,
WalletRequestMetadataInput,
} from '@chaoslabs/ai-sdk';
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
const override: WalletContextOverride = {
wallet_address: '0xTestWallet',
balances: [
{ symbol: 'ETH', amount: 10, chain: 'ethereum', price: 3500 },
{ symbol: 'USDC', amount: 50000, chain: 'ethereum', price: 1 },
],
protocol_positions: [
{
id: 'aave-v3',
name: 'Aave V3',
chain: 'ethereum',
portfolio_items: [
{
name: 'Supply',
assets: [{ symbol: 'WETH', amount: 5, price: 3500 }],
},
{
name: 'Borrow',
assets: [{ symbol: 'USDC', amount: 10000, price: 1 }],
},
],
},
],
prices: { ETH: 3500, USDC: 1, WETH: 3500 },
};
const metadata: WalletRequestMetadataInput = {
user_id: 'test-user',
session_id: 'test-session',
wallets: [{ address: '0xTestWallet', chain: 'ethereum' }],
walletContextOverride: override,
};
const response = await chaos.chat.responses.create({
model: WALLET_MODEL,
input: [{ type: 'message', role: 'user', content: 'Show my portfolio' }],
metadata,
});ChatCreateResponse
The response object returned by chaos.chat.responses.create().
interface ChatCreateResponse {
id: string;
kind: "response";
model: string;
status: "completed" | "failed";
messages?: ChaosSDKMessage[];
error?: ResponseError;
}
interface ResponseError {
message: string;
type: string;
code: string;
}| Field | Type | Description |
|---|---|---|
id | string | Unique response identifier |
kind | "response" | Always "response" |
model | string | Model used for the response |
status | "completed" | "failed" | Whether the request succeeded |
messages | ChaosSDKMessage[] | Array of streamed messages |
error | ResponseError | Error details if status is "failed" |
ChaosSDKMessage
The discriminated union of all message types streamed during a response.
type ChaosSDKMessage =
| AgentStatusSDKMessage
| AgentTextSDKMessage
| BlockSDKMessage
| FollowUpSuggestionsSDKMessage
| UserInputSDKMessage;Each message has a shared shape with kind: "message" and a type discriminant:
type | Interface | data Contents |
|---|---|---|
"status" | AgentStatusSDKMessage | { status: "processing" | "done" } |
"text" | AgentTextSDKMessage | { text: string } |
"block" | BlockSDKMessage | { block: Block; order?: number } |
"follow_up_suggestions" | FollowUpSuggestionsSDKMessage | { suggestions: string[] } |
"input" | UserInputSDKMessage | { prompt?: string; options: UserInputOption[] } |
All messages share a context object:
interface ChaosSDKMessageContext {
sessionId: string;
artifactId: string;
query?: string;
}