Skip to main content
All posts
Updated

The LevelFour API: Cost and Savings Data Over REST

One REST API for your spend and savings, with scoped keys, one response envelope, and signed webhooks when a saving moves.

Gabriel Nielsen
Ler em portuguêsA API da LevelFour: dados de custo e economia via REST

Cost data does more work where your team already looks: an internal dashboard, a finance model, a CI job, a ticket queue. The LevelFour API serves the same spend and savings data as the dashboard, so you can take it into any of them.

One base URL, one envelope

Endpoints sit under https://api.levelfour.ai and take your API key as a bearer token in the Authorization header. Every response comes back in the same envelope, with success, then data or error, then a timestamp, so one parser handles all of them.

Terminal
curl -H "Authorization: Bearer $LEVELFOUR_API_KEY" \
  https://api.levelfour.ai/api/v1/recommendations/summary

An error sets success to false and puts a code such as NOT_FOUND, a message, and details under error. A list puts its rows in items beside a pagination object with total_pages and has_next, and pages count from 1. Each key can make 600 requests a minute. Past that, the API answers 429 with RATE_LIMIT_EXCEEDED.

What you can reach

  • Costs: spend summaries, breakdowns, trends, usage, allocation, and forecasts across the providers you connected.
  • Recommendations: the savings LevelFour found and the decisions on them. You can accept one, reject it with a reason, or request its execution.
  • Realized savings: what each completed recommendation saved, from the audit of your bill.
  • Commitments and anomalies: your Reserved Instances and Savings Plans, and the spend spikes LevelFour detected.
  • Cost alerts: create, change, pause, and delete budget, spend change, and commitment alerts, and read what they said.
  • Tags and cost views: provider tags, the virtual tags LevelFour assigns from your rules, and saved views you can read back.

The API reference has every endpoint, with its parameters and response shapes.

Keys with a scope

Each key carries a scope and an optional expiry of 30, 60, or 90 days, both set when you create it in the dashboard. A read key covers the reads, and a write call made with one gets 403 Forbidden. A read-write key adds the endpoints that record a decision in LevelFour, such as accepting a recommendation or requesting its execution. Neither scope changes anything in your cloud account: requesting execution starts the rollout in LevelFour.

Use read keys for dashboards, reports, and CI checks, and keep read-write keys for the automation that records decisions. When that automation retries a POST, send an Idempotency-Key header with a version 4 UUID: the API keeps a successful response for 24 hours and returns it to a retry with the same key instead of running the write again.

Webhooks when a saving moves

Register an endpoint and LevelFour posts an event when a recommendation changes state or a rollout moves:

recommendation.accepted
When it fires
Someone accepted a savings recommendation
recommendation.rejected
When it fires
Someone rejected one
recommendation.rejection_reason_added
When it fires
Someone added a reason to a rejection
recommendation.terms_accepted
When it fires
Someone accepted the terms for applying a recommendation
recommendation.implementation_method_set
When it fires
Someone chose how a recommendation is delivered
execution.approval_requested
When it fires
A member sent a recommendation to an admin to release
optimization.started, optimization.completed, optimization.failed
When it fires
A rollout moved forward, finished, or failed

Each request carries an HMAC-SHA256 signature in the Standard Webhooks format, with webhook-id, webhook-timestamp, and webhook-signature headers, so your endpoint can confirm LevelFour sent it before acting on it. By default, the SDK verifiers reject a timestamp more than five minutes off, and LevelFour retries a delivery that gets no 2xx, so deduplicate on webhook-id. Webhooks come with the Scale and Enterprise plans.

Terminal
curl -X POST https://api.levelfour.ai/api/v1/webhooks/endpoints \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://your-app.com/webhooks/levelfour", "event_types": ["recommendation.accepted", "optimization.completed"]}'

Get started

Create a key in the dashboard under Settings > API Keys, then read the API reference for every endpoint. From a shell, l4 api sends an authenticated request to any of them.

Start with LevelFour and bring your cost data into your own tools.

Frequently asked questions

Can the LevelFour API change resources in my cloud?

No key changes anything in your cloud account. A read-write key records decisions in LevelFour, such as accepting a recommendation or requesting its execution, and the rollout runs from there.

How do I verify that a webhook came from LevelFour?

Check the HMAC-SHA256 signature on each request against your endpoint's signing secret, which starts with whsec_. The headers follow the Standard Webhooks format, so any Standard Webhooks library can run the check.

Which key should a CI job use?

A read key. It covers the reads a report or a check needs, and it cannot record a decision.

More posts

See what LevelFour can save you