← All posts

Automatic Top-Ups: Buy API Credits Before the Hard Stop

Automatic top-up buys more credits or traffic when use reaches 80 to 95% of an allowance, so an overnight client feed keeps running. Here's how it decides.

What's New

Running out of credits at 3 p.m. costs you a click on Buy. Running out at 3 a.m. costs you the morning delivery.

Since October 24, the Billing page in your Dashboard can buy a top-up for you before an allowance runs out. You pick the point where it kicks in (80, 85, 90 or 95% of the allowance used), how much each purchase adds, and how many times it may buy in one billing period. It charges your saved card, and every purchase arrives as an ordinary invoice.

We built it after a customer's overnight job ran into its plan's hard stop with nobody awake to buy more by hand. If you deliver a daily feed to a client, you know what that morning looks like: a sheet with half the rows, and a message asking why.

How It Works

Open Billing, stay on the Plan & Usage tab, and look at the header of the Top-ups table. The Automatic top-up button sits there, next to a line that says what the rule does now. It only appears when your plan sells at least one top-up, and each allowance your plan can top up gets its own rule:

Allowance What it tops up
Credits API credits
Bandwidth Standard traffic
Premium traffic Premium-exit traffic

On a plan sold by credits, Bandwidth means the proxy port's own gigabytes; on a plan sold by traffic, it's the API and the proxy port together. How Your Plan Is Metered has the whole model on one page.

A rule has three terms. The threshold defaults to 95%. The amount each purchase adds comes in steps of 100,000 credits or whole gigabytes, and starts at what your plan includes in one period. And the period maximum (once, twice, 3, 5 or 10 times) defaults to 3. The dialog prices the amount on our side, shows what each purchase costs with VAT, and names the card it charges.

From then on FourA checks every minute. It measures against the same number the API holds you to: what your plan includes this period plus everything you've bought on top. When your use reaches the threshold, it buys once. That purchase raises the allowance, so the next automatic top-up can only fire at the new, higher threshold, and two checks can never buy against the same one. The full set of options is on the Automatic Top-Up docs page.

Your code doesn't change. What changes is how rarely it meets this branch:

import requests

API = "https://eu.api.foura.ai/api/single/"
HEADERS = {"X-API-Key": "YOUR_API_KEY", "Content-Type": "application/json"}

def fetch_all(urls):
    pages, metered = {}, 0
    for url in urls:
        resp = requests.post(API, headers=HEADERS, json={"method": "GET", "url": url})
        metered += int(resp.headers.get("X-FourA-Credits", "0"))

        if resp.headers.get("X-FourA-Limit") == "plan_limit_credits":
            stop = resp.json()
            # hard_stop already includes every top-up, bought by hand or automatically.
            # With automatic top-up on, reaching it means the rule used its period
            # maximum or paused on a failed charge. Retrying in a minute fixes neither.
            print(f"Stopped at {stop['used']:,} of {stop['hard_stop']:,} credits, "
                  f"resets {stop['resets_at']}")
            break

        pages[url] = resp.json()

    print(f"{len(pages)} pages, {metered} credits metered")
    return pages

Read hard_stop from the refusal body instead of computing it on your side. Each plan-limit refusal, with its body and headers, is in Rate Limits.

Impact

The feature is a month old, so we won't quote adoption numbers yet. What we can describe is the shape of the change.

Before, the only way to keep a job running past a spent allowance was the Buy button, pressed by a person. Now the hard stop shows up in two situations only, and you either chose it or can see it:

  • You set the ceiling. The rule reached its period maximum. It stays on, and it starts again when the next billing period does.
  • A payment didn't go through. The rule pauses, and the dialog shows the date and the reason.

Each automatic purchase is a normal top-up: its own invoice, its own row in the Top-ups table, and an email when it happens. It lasts twelve months as a balance, and your plan's included allowance is always used first, so a top-up bought on the 28th that you never touch isn't lost when the month resets.

Two honest limits. It pays with a saved card only, so without one the rule can't be saved. And a plan that sells no top-ups doesn't show the button at all.

For Power Users

Pick the threshold from your burn rate. The check runs once a minute, so the gap between your threshold and 100% has to cover at least a minute of your fastest job. If a backfill can eat 5% of the period's credits in a minute, 95% sits too close: drop to 85%, or raise the amount each purchase adds.

Treat "Add" times "At most" as your worst night. Multiplied, those two terms are the most the rule can buy in one period. Keep the maximum low. It's there to stop a runaway loop from buying again and again overnight; it isn't a budget, and purchases you make by hand don't count toward it. If you quote client work, that worst-night figure belongs in the quote (we walked through costing the run in How to Price a Web Scraping Project).

Premium runs out quietly on the API. When premium traffic is spent, most requests that ask for exitClass: premium aren't refused. They're served from the standard pool, and the response says so in X-FourA-Exit-Class: standard. A Proxy Finder request that names an exit location is the exception and gets a 403. If a target only answers premium exits, watch that header, or give Premium traffic its own rule so the allowance is bought before it runs dry.

A declined card isn't retried, on purpose. A card declined at 03:00 will be declined at 03:01 too, and a run of declines on one card is exactly what a bank's fraud checks look for. So a decline pauses the rule at once. A charge that got no answer is different: it's sent once more a few minutes later under the same payment key, so it can't be paid twice. To restart a paused rule, fix the cause (usually the card on Payment Methods), open the dialog and click Save.

What's Next

Automatic top-up answers "keep going". The next billing item on our public roadmap answers "stop here": spend alerts and budget caps, meaning a threshold that tells you when you cross it and a cap on what a single API key can spend, so one runaway job can't take the whole month with it. Organization billing is planned beside it, so a company's plan and invoices stop depending on whoever happened to open the account.

Between the two, the hard stop becomes a line you draw yourself, not something that happens to you at 3 a.m.