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>
get-report.ts
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`);
}

PortfolioReport

FieldTypeDescription
statusstringReport status (e.g., 'ready', 'pending', 'generating')
retry_afternumber | nullSeconds 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>
refresh-report.ts
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);

Refresh and Poll Pattern

Combine refreshReport and report to generate and wait for a report:

refresh-poll-pattern.ts
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}`);
[@portabletext/react] Unknown block type "callout", specify a component for it in the `components.types` prop

transactions(portfolioId)

Retrieve the transaction history for a portfolio.

Signature:

transactions(portfolioId: string): Promise<PortfolioTransactions>
transactions.ts
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);
}

RefreshReportResponse

FieldTypeDescription
taskIdstringIdentifier for the background report generation task
messagestringHuman-readable status message
retryAfternumberSuggested seconds to wait before polling
Was this helpful?