Premip

Monitor usage and balance

Read plan quota, per-proxy and daily usage and your wallet balance, then run a small check from cron that warns you before traffic or balance runs out.

6 min readGET /billing/planGET /usage/analyticsGET /billing/walletGET /billing/invoices
On this page

Before you start

  • An API key. See the quickstart.

1. Read the plan quota

The plan shows quota and traffic used in MB. Traffic is billed per GB and never expires, so dataQuotaMB minus dataUsedMB is what you have left.

curl https://api.premip.com/billing/plan \
  -H "X-Api-Key: $PREMIP_API_KEY"

Example output

20.0 GB left

2. Break usage down by proxy and day

Analytics return a per-proxy breakdown (dataUsedMB) and a daily series (mb). Results are cached for 60 seconds, so polling more often gains nothing.

curl https://api.premip.com/usage/analytics \
  -H "X-Api-Key: $PREMIP_API_KEY"

3. List invoices

Every order has an invoice. Paid invoices carry a receiptUrl that points to the order page in the dashboard.

curl https://api.premip.com/billing/invoices \
  -H "X-Api-Key: $PREMIP_API_KEY"

Complete script: low-balance and low-traffic check

Exits with code 1 and a message when the wallet or the remaining traffic drops under your thresholds, so cron, CI or a monitoring agent can alert you. Edit MIN_BALANCE_USD and MIN_TRAFFIC_GB.

#!/usr/bin/env bash
# Needs curl, jq and awk. Run: PREMIP_API_KEY=premip_... bash script.sh
set -euo pipefail
API=https://api.premip.com
H="X-Api-Key: $PREMIP_API_KEY"

MIN_BALANCE_USD=10
MIN_TRAFFIC_GB=2
problems=0

balance=$(curl -fsS $API/billing/wallet -H "$H" | jq .balance)
echo "Wallet: $balance USD"
if awk -v a="$balance" -v b="$MIN_BALANCE_USD" 'BEGIN { exit !(a < b) }'; then echo "WARNING: balance under $MIN_BALANCE_USD USD"; problems=1; fi

if plan=$(curl -fsS $API/billing/plan -H "$H" 2>/dev/null); then
  left=$(echo "$plan" | jq '(.dataQuotaMB - .dataUsedMB) / 1024')
  echo "Traffic left: $left GB"
  if awk -v a="$left" -v b="$MIN_TRAFFIC_GB" 'BEGIN { exit !(a < b) }'; then echo "WARNING: under $MIN_TRAFFIC_GB GB left"; problems=1; fi
fi
exit $problems

Troubleshooting

ProblemWhat to do
GET /billing/plan returns 404The account has no plan yet. Place an order first.
Usage numbers lag behind what you sentUsage is synced from the gateway and cached for 60 seconds. Check again a minute later.
Numbers look 1024 times too smallQuota and usage are reported in MB. Divide by 1024 for GB.

Keep going

All guides

Usage monitoring guide — Premip