Skip to content

feat: analytics trends and budget forecast API endpoints #771

@Aureliolo

Description

@Aureliolo

Phase 3.1 -- Analytics Trends & Forecast

Parent: #762

Context

The new dashboard needs sparkline trend data and budget forecast projections. The backend has the raw data (CostRecord, TaskMetricRecord) but no time-series aggregation endpoints.

Scope

GET /api/v1/analytics/trends

  • Query params: period (7d/30d/90d), metric (tasks_completed, spend, active_agents, success_rate)
  • Response: array of {timestamp, value} datapoints bucketed by day (or hour for 7d)
  • Data sources: CostRecord (spend), TaskMetricRecord (tasks, success rate), agent status snapshots

GET /api/v1/analytics/forecast

  • Query params: horizon_days (7/14/30)
  • Response: {projected_total, daily_projections: [{day, value}], days_until_budget_exhausted, confidence}
  • Data source: CostTracker's internal trending logic (needs to be exposed as public method)

Extend GET /api/v1/analytics/overview

  • Add fields: budget_remaining_usd, budget_used_percent, cost_7d_trend (sparkline array), active_agents_count, idle_agents_count

Deliverables

  • Trends endpoint with 4 metric types
  • Forecast endpoint with daily projections
  • Extended overview response
  • Unit tests with realistic test data
  • OpenAPI schema updated

Notes

  • Can start immediately -- no dependency on frontend work
  • Expose CostTracker's trend logic via new public methods, don't duplicate

Metadata

Metadata

Assignees

No one assigned

    Labels

    prio:highImportant, should be prioritizedscope:medium1-3 days of workspec:apitype:featureNew feature implementationv0.5Minor version v0.5v0.5.0Patch release v0.5.0

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions