AI Analysis & Workflows
Updated
The portfolios namespace includes three methods for AI-powered analysis: analyse for asking questions about a specific portfolio, createSession for starting a new portfolio analysis session, and analyze for running portfolio workflow operations.
analyse(portfolioId, query?, clientRequestId?)
Ask the AI a question about a specific portfolio. This creates a conversational session with analysis results.
Signature:
analyse(portfolioId: string, query?: string, clientRequestId?: string): Promise<SessionData>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
import { Chaos } from '@chaoslabs/ai-sdk';
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
// Ask a question about a portfolio
const session = await chaos.portfolios.analyse(
'portfolio-id',
'What are my biggest risk exposures and how should I rebalance?'
);
console.log(`Session: ${session.sessionId}`);
console.log(`Title: ${session.title}`);
console.log(`Workflow: ${session.workflowName}`);
console.log(`Blocks: ${session.blocks.length}`);
// Without a query — runs default portfolio analysis
const defaultSession = await chaos.portfolios.analyse('portfolio-id');
// With a client request ID for idempotency
const trackedSession = await chaos.portfolios.analyse(
'portfolio-id',
'Show me my allocation breakdown',
'req-abc-123'
);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
portfolioId | string | Yes | Portfolio to analyze |
query | string | No | Question to ask the AI about this portfolio |
clientRequestId | string | No | Client-side request ID for idempotency/tracking |
createSession(params)
Create a new portfolio analysis session tied to a specific workflow.
Signature:
createSession(params: CreatePortfolioSessionParams): Promise<SessionData>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
import { Chaos } from '@chaoslabs/ai-sdk';
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
const session = await chaos.portfolios.createSession({
query: 'Analyze my DeFi exposure across all chains',
workflow_id: 'portfolio-analysis-v2',
});
console.log(`Session: ${session.sessionId}`);
console.log(`Workflow: ${session.workflowId}`);
console.log(`Title: ${session.title}`);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
CreatePortfolioSessionParams
| Field | Type | Required | Description |
|---|---|---|---|
query | string | Yes | The analysis question or prompt |
workflow_id | string | Yes | ID of the portfolio workflow to use |
analyze(params)
Run a portfolio analysis workflow. This is a lower-level method that accepts arbitrary workflow parameters.
Signature:
analyze(params: PortfolioWorkflowParams): Promise<PortfolioWorkflowResponse>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
import { Chaos } from '@chaoslabs/ai-sdk';
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
const result = await chaos.portfolios.analyze({
portfolioId: 'portfolio-id',
action: 'risk-assessment',
});
console.log(result);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
SessionData
All analysis methods that return SessionData provide a full session object:
| Field | Type | Description |
|---|---|---|
sessionId | string | Unique session identifier |
userId | string | Owner of the session |
createdAt | number | Unix timestamp of creation |
updatedAt | number | Unix timestamp of last update |
type | string | Session type |
workflowId | string | Workflow that generated this session |
workflowName | string | Human-readable workflow name |
title | string | AI-generated session title |
isBookmarked | boolean | Whether the session is bookmarked |
isPublished | boolean | Whether the session is published |
blocks | unknown[] | Content blocks (analysis results, charts, etc.) |
agentMessages | unknown[] | Raw agent message history |
Was this helpful?