← All examples
05 / Shell
Usage budget in CI
Read the current cycle from the control API and stop jobs before they exceed the team budget.
You will build
A simple cost guard before each batch
FinOpsCI
Shell
#!/usr/bin/env bash
set -euo pipefail
billing_json=$(curl --fail --silent -H "Authorization: Bearer ${PROXYAPI_KEY}" https://api.proxyapi.se/v1/customer/billing)
remaining=$(jq -r '.current_cycle.gb_remaining' <<<"${billing_json}")
if ! awk "BEGIN { exit !(${remaining} >= 2) }"; then
echo "Proxy budget guard: less than 2 GB remains" >&2
exit 1
fi Before production
- ✓Set the threshold using the job’s reasonable worst case, not its average.
- ✓Rotate CI keys regularly and mask them in build logs.