Cost report

From AltimateAI/altimate-code · View interactive version

Cost report is an AI agent skill from the GitHub repository AltimateAI/altimate-code. Analyze Snowflake query costs and identify optimization opportunities

How to use this skill

Skill file

Cost Report

Requirements

Agent: any (read-only analysis)

Tools used: sql_execute, sql_analyze, finops_analyze_credits, finops_expensive_queries, finops_warehouse_advice, finops_unused_resources, finops_query_history

Analyze Snowflake warehouse query costs, identify the most expensive queries, detect anti-patterns, and recommend optimizations.

Workflow

  1. Query SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY for the top 20 most expensive queries by credits used:

```sql

SELECT

query_id,

query_text,

user_name,

warehouse_name,

query_type,

credits_used_cloud_services,

bytes_scanned,

rows_produced,

total_elapsed_time,

execution_status,

start_time

FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY

WHERE start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP())

AND execution_status = 'SUCCESS'

AND credits_used_cloud_services > 0

ORDER BY credits_used_cloud_services DESC

LIMIT 20;

```

Use sql_execute to run this query against the connected Snowflake warehouse.

  1. Group and summarize the results by:

Present each grouping as a markdown table.

  1. Analyze the top offenders - For each of the top 10 most expensive queries:
  1. Classify each query into a cost tier:

| Tier | Credits | Label | Action |

|------|---------|-------|--------|

| 1 | < $0.01 | Cheap | No action needed |

| 2 | $0.01 - $1.00 | Moderate | Review if frequent |

| 3 | $1.00 - $100.00 | Expensive | Optimize or review warehouse sizing |

| 4 | > $100.00 | Dangerous | Immediate review required |

  1. Warehouse analysis - Run finops_warehouse_advice to check if warehouses used by the top offenders are right-sized.
  1. Unused resource detection - Run finops_unused_resources to find:

Include findings in the report under a "Waste Detection" section.

  1. Query history enrichment - Run finops_query_history to fetch recent execution patterns:
  1. Output the final report as a structured markdown document:

```

# Snowflake Cost Report (Last 30 Days)

## Summary

## Cost by User

| User | Total Credits | Query Count | Avg Credits/Query |

|------|--------------|-------------|-------------------|

## Cost by Warehouse

| Warehouse | Total Credits | Query Count | Avg Credits/Query |

|-----------|--------------|-------------|-------------------|

## Cost by Query Type

| Query Type | Total Credits | Query Count | Avg Credits/Query |

|------------|--------------|-------------|-------------------|

## Top 10 Expensive Queries (Detailed Analysis)

### Query 1 (X credits) - DANGEROUS

User: user_name | Warehouse: wh_name | Type: SELECT

Anti-patterns found:

Optimization suggestions:

1. Select only needed columns

2. Add LIMIT clause

3. Consider partitioning strategy

Cost tier: Tier 1 (based on credits used)

...

## Waste Detection

### Unused Tables

| Table | Last Accessed | Size | Recommendation |

|-------|--------------|------|----------------|

### Idle Warehouses

| Warehouse | Last Query | Size | Recommendation |

|-----------|-----------|------|----------------|

## Recommendations

1. Top priority optimizations

2. Warehouse sizing suggestions

3. Unused resource cleanup

4. Scheduling recommendations

```

Usage

The user invokes this skill with:

Use the tools: sql_execute, sql_analyze, finops_analyze_credits, finops_expensive_queries, finops_warehouse_advice, finops_unused_resources, finops_query_history.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.