Types Reference
All types are exported from @chaoslabs/ai-sdk and are auto-generated from the Chaos AI contracts schema.
ChatCreateRequest
The base request type for creating a chat response.
interface ChatCreateRequest {
model: string;
input: InputItem[];
stream?: boolean;
metadata: RequestMetadata;
}ChatCreateRequestParams
Extends ChatCreateRequest with an optional streaming callback. This is the type you pass to chaos.chat.responses.create().
type ChatCreateRequestParams = ChatCreateRequest & {
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 |
RequestMetadata
Metadata attached to every request. Contains user identity, session tracking, and wallet configuration.
interface RequestMetadata {
user_id: string;
session_id: string;
wallets?: WalletInfo[];
wallet_context_override?: WalletContextOverride;
}| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | Unique user identifier |
session_id | string | Yes | Session identifier for conversation continuity |
wallets | WalletInfo[] | No | Array of wallet addresses (required for WALLET_MODEL) |
wallet_context_override | WalletContextOverride | No | Override wallet context for deterministic testing |
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 } from '@chaoslabs/ai-sdk';
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 response = await chaos.chat.responses.create({
model: WALLET_MODEL,
input: [{ type: 'message', role: 'user', content: 'Show my portfolio' }],
metadata: {
user_id: 'test-user',
session_id: 'test-session',
wallets: [{ address: '0xTestWallet', chain: 'ethereum' }],
wallet_context_override: override,
},
});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;
}