Skip to content

REST API Reference

FrostWatch exposes a REST API at /api. The interactive Swagger UI is available at http://localhost:8000/docs.

Dashboard

GET /api/dashboard

Returns the 7-day and 30-day summary used by the dashboard page.

Response

{
  "total_credits_7d": 12.34,
  "total_cost_7d": 4.11,
  "total_credits_30d": 55.2,
  "total_cost_30d": 18.4,
  "top_warehouses": [
    { "name": "COMPUTE_WH", "credits": 40.1, "cost_usd": 13.37, "pct_of_total": 72.6 }
  ],
  "top_users": [...],
  "recent_anomalies": [...],
  "last_synced": "2026-04-28T08:00:00Z",
  "query_count_7d": 1240
}

Queries

GET /api/queries

Returns the most expensive queries ordered by credits consumed.

Parameter Type Default Description
days int 7 Lookback window (1–365)
limit int 50 Max rows returned (1–500)

Response — array of QueryRecord:

[
  {
    "query_id": "01b2c3d4-...",
    "warehouse_name": "COMPUTE_WH",
    "user_name": "TRANSFORMER",
    "role_name": "SYSADMIN",
    "execution_time_ms": 4521.0,
    "bytes_scanned": 1073741824,
    "credits_used": 0.000832,
    "start_time": "2026-04-27T14:22:01Z",
    "end_time": "2026-04-27T14:22:05Z",
    "query_text_preview": "SELECT * FROM ...",
    "query_tag": "{\"app\":\"dbt\",\"node_id\":\"model.proj.orders\"}",
    "dbt_model": "orders",
    "status": "SUCCESS"
  }
]

Warehouses

GET /api/warehouses

Returns credit and query aggregates per warehouse.

Parameter Type Default Description
days int 30 Lookback window (1–365)

GET /api/warehouses/timeseries

Returns daily credit usage per warehouse.

Parameter Type Default Description
days int 30 Lookback window (1–365)
warehouse string — Filter to a single warehouse

dbt Models

GET /api/dbt

Returns credit and performance breakdown by dbt model name.

Parameter Type Default Description
days int 30 Lookback window (1–365)

Response — array of DbtModelAgg, sorted by total_credits descending:

[
  {
    "dbt_model": "orders",
    "total_credits": 0.0412,
    "total_cost_usd": 0.0137,
    "query_count": 48,
    "avg_execution_ms": 3210.5
  }
]

dbt Cloud

GET /api/dbt/runs

Returns dbt Cloud job runs stored by the last cloud sync, newest first.

Parameter Type Default Description
days int 30 Look-back window (1–90)
limit int 50 Max rows (1–200)

GET /api/dbt/jobs

Returns credit and performance breakdown by dbt Cloud job, sorted by total credits.

Parameter Type Default Description
days int 30 Look-back window (1–90)

Response — array of DbtJobCostRecord:

[
  {
    "job_id": 101,
    "job_name": "Nightly Production Run",
    "environment_id": 201,
    "environment_name": "production",
    "run_count": 30,
    "total_credits": 1.842,
    "total_cost_usd": 0.614,
    "avg_duration_seconds": 612.3,
    "last_run_at": "2026-05-06T01:04:00Z",
    "last_run_status": "success"
  }
]

GET /api/dbt/environments

Returns credit breakdown by dbt Cloud environment, sorted by total credits.

Parameter Type Default Description
days int 30 Look-back window (1–90)

GET /api/dbt/threshold-alerts

Returns dbt model threshold alerts (models that exceeded dbt_model_credit_threshold credits in a day), newest first.

Parameter Type Default Description
days int 30 Look-back window (1–90)
limit int 50 Max rows (1–200)

Response — array of DbtThresholdAlertRecord:

[
  {
    "id": 1,
    "detected_at": "2026-05-04T23:59:00Z",
    "dbt_model": "revenue_daily",
    "period_start": "2026-05-04T00:00:00Z",
    "period_end": "2026-05-04T23:59:00Z",
    "credits_used": 0.612,
    "threshold": 0.3
  }
]

GET /api/dbt/metadata

Returns enriched model metadata from the last uploaded manifest.json.

POST /api/dbt/sync-cloud

Pulls the last 30 days of run + job + environment metadata from the dbt Cloud API and attributes Snowflake credits to each run. Requires dbt_cloud_account_id and dbt_cloud_api_token in config.

Response:

{ "runs_synced": 87, "jobs_enriched": 3, "environments_enriched": 2 }

POST /api/dbt/manifest

Parses a manifest.json sent as the raw request body and upserts enriched model metadata.

curl -X POST http://localhost:8000/api/dbt/manifest \
     -H "Content-Type: application/json" \
     --data-binary @target/manifest.json

Response: {"models_upserted": N}

Insights

The /api/insights group provides deeper analysis of query patterns, cost trends, and AI-powered optimization suggestions.

GET /api/insights/fingerprints

Groups queries by normalized SQL fingerprint and returns the top patterns by total credits.

Parameter Type Default Description
days int 30 Look-back window (1–90)
limit int 20 Max patterns to return (1–100)

Response — array of QueryFingerprintRecord:

[
  {
    "fingerprint": "a3f1b2c4...",
    "canonical_sql": "SELECT * FROM ORDERS WHERE STATUS = '?' AND CREATED_AT >= ?",
    "example_query_id": "01b2c3d4-...",
    "total_executions": 142,
    "total_credits": 0.8431,
    "avg_credits": 0.005938,
    "avg_execution_ms": 3210.5,
    "first_seen": "2026-04-01T00:00:00Z",
    "last_seen": "2026-04-30T18:42:00Z",
    "most_common_warehouse": "COMPUTE_WH",
    "most_common_user": "TRANSFORMER"
  }
]

GET /api/insights/regressions

Returns query patterns whose average per-execution cost rose this week compared to last week.

Parameter Type Default Description
threshold float 2.0 Min ratio (this week avg / last week avg) to flag (1.1–20.0)
limit int 10 Max patterns to return (1–50)

Response — array of QueryRegressionRecord:

[
  {
    "fingerprint": "a3f1b2c4...",
    "canonical_sql_preview": "SELECT * FROM ORDERS ...",
    "example_query_id": "01b2c3d4-...",
    "avg_credits_this_week": 0.012,
    "avg_credits_last_week": 0.003,
    "regression_ratio": 4.0,
    "executions_this_week": 38,
    "executions_last_week": 41,
    "most_common_warehouse": "COMPUTE_WH",
    "severity": "high"
  }
]

Severity levels: medium (ratio ≥ 2×), high (≥ 3×), critical (≥ 5×).

GET /api/insights/forecasts

Projects per-warehouse credit and USD cost for the next N days using ordinary least-squares regression on historical warehouse metrics.

Parameter Type Default Description
days_ahead int 7 Days to project ahead (1–30)
history_days int 30 History window used to fit the model (7–90)

Response — array of CostForecastPoint:

[
  {
    "warehouse_name": "COMPUTE_WH",
    "forecast_date": "2026-05-05",
    "predicted_credits": 4.21,
    "predicted_cost_usd": 1.40,
    "trend": "up",
    "confidence": "high",
    "projected_30d_credits": 126.3,
    "projected_30d_cost_usd": 42.1
  }
]

trend is up, down, or stable. confidence is low (< 7 data points), medium (7–13), or high (≥ 14).

POST /api/insights/rewrites

Submits an expensive query to your configured LLM and returns an optimization report. Results are persisted and returned idempotently — calling this endpoint twice for the same query_id returns the cached result without making a second LLM call.

Request body:

{ "query_id": "01b2c3d4-..." }

Response — QueryRewriteResponse:

{
  "id": 1,
  "query_id": "01b2c3d4-...",
  "fingerprint": "a3f1b2c4...",
  "rewrite_suggestion": "## Rewrite\n```sql\nSELECT id, status, ...```\n\n## Root Cause\n...\n\n## Recommendations\n- Add clustering key on STATUS\n...\n\n## Estimated Savings\n40–60% credit reduction",
  "generated_at": "2026-05-04T10:00:00Z"
}

Returns 503 if no LLM provider is configured, 404 if the query_id is not found, 404 if no rewrite exists yet (use POST to generate one).

GET /api/insights/pruning

Returns query patterns with poor partition pruning efficiency, sorted by impact (pruning ratio × total credits × executions).

Parameter Type Default Description
days int 30 Look-back window (1–90)
limit int 20 Max patterns to return (1–100)
min_partitions int 100 Min average partitions_total to include (filters out small tables)
min_ratio float 0.5 Min average pruning ratio (0.1–1.0) to flag

Response — array of PartitionPruningRecord:

[
  {
    "fingerprint": "a3f1b2c4...",
    "canonical_sql_preview": "SELECT * FROM ORDERS WHERE STATUS = '?'",
    "example_query_id": "01b2c3d4-...",
    "total_executions": 87,
    "executions_analyzed": 85,
    "avg_pruning_ratio": 0.92,
    "avg_partitions_scanned": 4140.0,
    "avg_partitions_total": 4500.0,
    "avg_credits": 0.0182,
    "total_credits": 1.547,
    "most_common_warehouse": "COMPUTE_WH",
    "most_common_user": "ANALYST_ALICE",
    "severity": "critical",
    "recommendation": "Add a clustering key on the high-cardinality filter column(s)..."
  }
]

Severity levels: medium (ratio ≥ 0.5), high (≥ 0.7), critical (≥ 0.9).

GET /api/insights/rewrites/{query_id}

Fetches the most recent rewrite suggestion for a query. Returns 404 if none has been generated yet.

Anomalies

GET /api/anomalies

Returns detected spend anomalies with optional LLM explanations.

Parameter Type Default Description
days int 30 Lookback window (1–365)

Reports

GET /api/reports

Returns previously generated weekly digest reports.

POST /api/reports/generate

Triggers an on-demand digest report generation.

Sync

POST /api/sync

Triggers a Snowflake data sync in the background. Rate-limited to 10 requests/minute.

Response: {"status": "started"}

GET /api/sync/status

Returns the status of the most recent sync run.

{
  "status": "idle",
  "last_run_at": "2026-04-28T08:00:00Z",
  "last_error": null,
  "rows_synced": 482
}

Settings

GET /api/settings

Returns the current configuration (credentials are redacted — only _set booleans are returned for secrets).

PUT /api/settings

Updates configuration fields. The server restarts the LLM provider and scheduler on success.

POST /api/settings/test-snowflake

Tests the current Snowflake connection by running SELECT 1.

POST /api/settings/test-email

Tests the current SMTP configuration by connecting and issuing EHLO.

Scheduler

GET /api/scheduler/jobs

Returns the list of scheduled APScheduler jobs (sync cron and report cron).

POST /api/scheduler/trigger

Manually triggers the report generation job.

Resource Monitors

GET /api/resource-monitors

Returns all resource monitors synced from SNOWFLAKE.ACCOUNT_USAGE.RESOURCE_MONITORS.

Response — array of ResourceMonitorRecord:

[
  {
    "id": 1,
    "name": "RM_TRANSFORM_WH",
    "credit_quota": 250.0,
    "used_credits": 238.5,
    "remaining_credits": 11.5,
    "level": "WAREHOUSE",
    "frequency": "MONTHLY",
    "notify_at_percentage": 75.0,
    "suspend_at_percentage": 100.0,
    "suspend_immediately_at_percentage": 110.0,
    "warehouses": ["TRANSFORM_WH"],
    "owner": "ACCOUNTADMIN",
    "synced_at": "2026-05-08T08:00:00Z"
  }
]

GET /api/resource-monitors/recommendations

Analyse per-warehouse spend and recommend resource monitor quotas. Uses the p95 daily credits over the history window, multiplied by 30 days and a buffer, then rounded to a clean milestone.

Parameter Type Default Description
history_days int 30 Days of history to use (7–90)
buffer_pct float 0.20 Overhead buffer fraction (0.0–1.0)

Response — array of MonitorRecommendationRecord:

[
  {
    "warehouse_name": "TRANSFORM_WH",
    "avg_daily_credits": 0.85,
    "p95_daily_credits": 1.42,
    "monthly_credits_p95": 42.6,
    "recommended_quota": 50,
    "recommended_cost_usd": 16.67,
    "frequency": "MONTHLY",
    "notify_at_percentage": 75.0,
    "suspend_at_percentage": 100.0,
    "suspend_immediately_at_percentage": 110.0,
    "existing_monitor": "RM_TRANSFORM_WH",
    "current_quota": 250.0,
    "quota_status": "oversized",
    "priority": "medium",
    "history_days_used": 30
  }
]

quota_status is one of uncovered, undersized, oversized, or adequate. priority is high, medium, or low (based on spend volatility and average usage).


GET /api/resource-monitors/generate-sql

Generate a copy-paste-ready CREATE OR REPLACE RESOURCE MONITOR DDL statement for a specific warehouse.

Parameter Type Required Description
warehouse string ✓ Warehouse name
history_days int 7–90 (default 30)
buffer_pct float 0.0–1.0 (default 0.20)

Response:

{
  "warehouse_name": "TRANSFORM_WH",
  "monitor_name": "RM_TRANSFORM_WH",
  "sql": "-- Resource monitor for TRANSFORM_WH\n..."
}

The sql field is a complete DDL block with inline comments, ready to run in a Snowflake worksheet.


GET /api/resource-monitors/proximity-alerts

Returns monitors that are close to a trigger threshold (notify / suspend / suspend-immediately), sorted by used_pct descending.

Response — array of ProximityAlertRecord:

[
  {
    "monitor_name": "RM_TRANSFORM_WH",
    "warehouse_names": ["TRANSFORM_WH"],
    "credit_quota": 250.0,
    "used_credits": 238.5,
    "remaining_credits": 11.5,
    "used_pct": 95.4,
    "nearest_trigger": "suspend",
    "nearest_trigger_pct": 100.0,
    "margin_to_trigger_ppt": 4.6,
    "frequency": "MONTHLY",
    "severity": "critical"
  }
]

Severity bands:

Severity Condition
critical Within 5 pp of a trigger threshold
high Within 15 pp of a trigger threshold
medium Trigger ahead but > 15 pp away

GET /api/resource-monitors/budgets

Return per-user and per-role credit spend vs configured daily budgets.

Parameter Type Default Description
days int 1 Lookback window in days (1–30)

Budgets are configured in user_credit_budgets and role_credit_budgets in your config.yaml. All budgeted entities are always returned, plus any unbudgeted users/roles that had spend in the period.

Response:

{
  "days": 1,
  "users": [
    {
      "name": "ANALYST_ALICE",
      "credits_used": 1.24,
      "daily_budget": 5.0,
      "period_budget": 5.0,
      "pct_of_budget": 24.8,
      "over_budget": false
    }
  ],
  "roles": [
    {
      "name": "TRANSFORMER",
      "credits_used": 12.4,
      "daily_budget": 10.0,
      "period_budget": 10.0,
      "pct_of_budget": 124.0,
      "over_budget": true
    }
  ]
}