How do I split AI spend by environment and compare prompt versions on cost?
Tag calls with X-Cost-Environment to see production vs staging vs CI spend and budget each one; tag them with X-Cost-Variant to compare prompt versions or models side by side on real cost, tokens, latency and errors.
Environments
Send X-Cost-Environment on every call. Use any names you like; common ones are production, staging, ci, eval and dev.
With the Python wrapper, pass cognocient_environment="staging" instead.
Observe → Environments shows spend, share, calls, tokens and error rate for each environment, a daily stacked chart, and how much of your spend is outside production. Calls without the header are grouped as (untagged).
Budget an environment
Create a budget with scope Environment and the environment name (for example ci). It behaves like any other budget: alert, degrade or block, but only for calls that carry that environment. A common setup is a hard block budget on ci and eval so a runaway test loop cannot eat into production's headroom.
X-Cost-Environment is not counted against any environment budget, but it still counts against global, feature, department, user and key budgets.Variants (Experiments)
Tag each call with the version it ran under:
With the Python wrapper, pass cognocient_variant="prompt-v2".
Intelligence → Experiments (Growth) compares the variants side by side:
| Metric | Notes |
|---|---|
| Avg cost per call, total spend, calls | From your own traffic, not list prices |
| Avg prompt / completion tokens | Shows whether a prompt change really shrank context |
| p50 / p95 latency, error rate | |
| Outcomes reached, spend per outcome | Only if you record outcomes. An outcome counts for a variant when any call it was matched to carries that variant. Spend per outcome is the variant's total spend divided by those outcomes. |
Pick a baseline and every other column shows its change against it. Filter by feature, environment or outcome. Variants with fewer than 30 calls are flagged as a small sample.
You can also compare by model (did the cheaper model, or the Auto Router, really save money on this feature?) or by environment.
The same comparison is available to AI assistants through the MCP server (compare_variants).
Related articles