Guides
Scheduled Execution
Overview
LevelFour identifies cost optimization opportunities and executes them when you approve. This guide shows how to monitor recommendation and execution status on a schedule using the SDKs.
Monitor Recommendations
Get an Overview
from levelfour import LevelFour
client = LevelFour()
overview = client.recommendations.get_overview()
print(overview)Check In-Progress Executions
processing = client.recommendations.list_in_progress()
print(processing)List Recommendations Sorted by Savings
for rec in client.recommendations.list(
page_size=50,
sort_by="monthly_savings",
sort_order="desc",
):
print(f"{rec.service}: ${rec.monthly_savings}/mo")Cron Schedule
Run a monitoring script on a schedule using cron:
0 6 * * 1-5 LEVELFOUR_API_KEY=l4_live_... python monitor.py >> /var/log/levelfour.log 2>&1Or with GitHub Actions:
name: Monitor Savings
on:
schedule:
- cron: '0 6 * * 1-5'
jobs:
monitor:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install levelfour
- name: Check recommendations
env:
LEVELFOUR_API_KEY: ${{ secrets.LEVELFOUR_API_KEY }}
run: python monitor.pyWebhook-Based Monitoring
Instead of polling on a schedule, use webhooks to react to events in real time:
from levelfour import LevelFour
client = LevelFour()
client.webhooks.register(
url="https://your-app.com/webhooks/levelfour",
event_types=[
"recommendation.accepted",
"recommendation.rejected",
"optimization.started",
"optimization.completed",
"optimization.failed",
],
)See the Slack Integration and Google Chat Integration guides for complete webhook receiver implementations.