Reports & Transactions
Updated
Portfolio reports are AI-generated analytics that summarize portfolio performance, risk exposure, and allocation. Reports are generated asynchronously — request a refresh and poll until the report is ready.
report(portfolioId)
Get the latest report for a portfolio. The response includes a status field indicating whether the report is ready or still processing.
Signature:
report(portfolioId: string): Promise<PortfolioReport>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 report = await chaos.portfolios.report('portfolio-id');
console.log(`Report status: ${report.status}`);
if (report.retry_after) {
console.log(`Report is generating — retry after ${report.retry_after} seconds`);
}Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
PortfolioReport
| Field | Type | Description |
|---|---|---|
status | string | Report status (e.g., 'ready', 'pending', 'generating') |
retry_after | number | null | Seconds to wait before polling again (if not ready) |
refreshReport(portfolioId, force?)
Trigger a report refresh. Pass force: true to regenerate even if a recent report exists. Returns a task ID and a suggested retry interval for polling.
Signature:
refreshReport(portfolioId: string, force?: boolean): Promise<RefreshReportResponse>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! });
// Refresh only if stale
const refresh = await chaos.portfolios.refreshReport('portfolio-id');
console.log(`Task: ${refresh.taskId}`);
console.log(`Message: ${refresh.message}`);
console.log(`Retry after: ${refresh.retryAfter}s`);
// Force regeneration
const forceRefresh = await chaos.portfolios.refreshReport('portfolio-id', true);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
Refresh and Poll Pattern
Combine refreshReport and report to generate and wait for a report:
import { Chaos } from '@chaoslabs/ai-sdk';
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
async function getOrRefreshReport(portfolioId: string) {
let report = await chaos.portfolios.report(portfolioId);
if (report.status === 'ready') {
return report;
}
const refresh = await chaos.portfolios.refreshReport(portfolioId, true);
console.log(`Generating report (task: ${refresh.taskId})...`);
// Poll until ready
let attempts = 0;
while (report.status !== 'ready' && attempts < 10) {
await new Promise(r => setTimeout(r, refresh.retryAfter * 1000));
report = await chaos.portfolios.report(portfolioId);
attempts++;
}
return report;
}
const report = await getOrRefreshReport('portfolio-id');
console.log(`Report status: ${report.status}`);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
transactions(portfolioId)
Retrieve the transaction history for a portfolio.
Signature:
transactions(portfolioId: string): Promise<PortfolioTransactions>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 { transactions } = await chaos.portfolios.transactions('portfolio-id');
console.log(`${transactions.length} transactions`);
for (const tx of transactions) {
console.log(tx);
}Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
RefreshReportResponse
| Field | Type | Description |
|---|---|---|
taskId | string | Identifier for the background report generation task |
message | string | Human-readable status message |
retryAfter | number | Suggested seconds to wait before polling |
Was this helpful?