Types Reference

Updated

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.

types.ts
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.

types.ts
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.

types.ts
interface InputItem {
  type: "message";
  role: "user" | "system" | "assistant";
  content: string;
}
FieldTypeDescription
type"message"Always "message"
role"user" | "system" | "assistant"The message role
contentstringThe message text

RequestMetadataInput

Request metadata is model-specific. Use WalletRequestMetadataInput for WALLET_MODEL requests and AskRequestMetadataInput for ASK_MODEL requests.

types.ts
interface WalletRequestMetadataInput {
  user_id: string;
  session_id: string;
  wallets?: WalletInfo[];
  walletContextOverride?: WalletContextOverride;
}
 
interface AskRequestMetadataInput {
  user_id: string;
  session_id: string;
}
 
type RequestMetadataInput =
  | WalletRequestMetadataInput
  | AskRequestMetadataInput;
FieldTypeAvailable OnRequiredDescription
user_idstringWALLET_MODEL, ASK_MODELYesUnique user identifier
session_idstringWALLET_MODEL, ASK_MODELYesSession identifier for conversation continuity
walletsWalletInfo[]WALLET_MODELNoArray of wallet addresses for live wallet lookups
walletContextOverrideWalletContextOverrideWALLET_MODELNoInjected wallet state for deterministic testing and simulations

ASK_MODEL requests do not accept wallets or walletContextOverride.

WalletInfo

A wallet address on a specific chain.

types.ts
interface WalletInfo {
  address: string;
  chain: string;
}
example.ts
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.

types.ts
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;
}
wallet-override-example.ts
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().

types.ts
interface ChatCreateResponse {
  id: string;
  kind: "response";
  model: string;
  status: "completed" | "failed";
  messages?: ChaosSDKMessage[];
  error?: ResponseError;
}
 
interface ResponseError {
  message: string;
  type: string;
  code: string;
}
FieldTypeDescription
idstringUnique response identifier
kind"response"Always "response"
modelstringModel used for the response
status"completed" | "failed"Whether the request succeeded
messagesChaosSDKMessage[]Array of streamed messages
errorResponseErrorError details if status is "failed"

ChaosSDKMessage

The discriminated union of all message types streamed during a response.

types.ts
type ChaosSDKMessage =
  | AgentStatusSDKMessage
  | AgentTextSDKMessage
  | BlockSDKMessage
  | FollowUpSuggestionsSDKMessage
  | UserInputSDKMessage;

Each message has a shared shape with kind: "message" and a type discriminant:

typeInterfacedata 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:

types.ts
interface ChaosSDKMessageContext {
  sessionId: string;
  artifactId: string;
  query?: string;
}
Was this helpful?