Skip to main content
Apidly

Optional cookies only if you accept. Cookie policy

Controlling GPU spend for AI workloads: prepaid credit, per-second billing and caps

Layer prepaid credit, per-second billing, a monthly budget, auto-stop, per-key limits and endpoint caps so a forgotten GPU or a leaked key cannot run up a bill.

Published December 3, 202610 min read

A GPU workload fails on cost in a few predictable ways. A notebook is left running over a weekend. A training job hangs and keeps billing. A script launches servers in a loop. An API key ends up in a public repository. A serverless endpoint gets more traffic than you planned for. No single setting covers all of these, because each one spends money in a different place.

This post walks through the controls Apidly has for this, in the order that money flows: the prepaid balance, the per-second meter, and then the limits you can put on a server, a budget, an API key, a team member and a serverless endpoint. Every command below is in the CLI reference. The dollar amounts are examples to show the arithmetic, not real prices; your real prices are shown before you launch anything.

Layer 1: prepaid credit is the outer wall

Apidly is prepaid. You add credit to a balance, and usage is taken from that balance. There is no invoice at the end of the month for usage you did not know about, and no subscription to cancel. The most a mistake can cost is the credit you chose to add, plus whatever auto top-up adds if you have turned it on. If you want a hard ceiling, leave auto top-up off, or set its threshold and amount to what you can afford to lose.

When the balance reaches zero, servers do not keep running on credit that does not exist. We email the account owner and start a grace period, then stop the servers if the balance is still at or below zero. The console shows the exact times, and Billing and balance covers the rules in full. One setting makes the wall easier to see coming:

apidly budget set --low-balance 25

That sets the balance, in dollars, under which the low-balance warning is sent. Nothing is stopped by it; it is a notice, so you can add credit or stop something before the zero-balance rules apply.

Layer 2: per-second billing keeps small mistakes small

The meter runs by the second, and charges are booked to the balance every minute. For a plan priced per hour, the charge for a period is:

price per hour × seconds ÷ 3600

Suppose a plan costs 1.20 dollars per hour (an example, not a quote) and a test run takes 25 minutes. That is 1,500 seconds, so 1.20 × 1,500 ÷ 3,600 = 0.50 dollars. With hourly rounding the same test would be charged as a full hour. When you run many short jobs, that difference is most of the bill. How billing by the second works has the full rules, including what is charged while a server is stopped (the disk, not the GPU).

Per-second billing does not stop a server from running; it only makes sure you pay for what ran. The rest of this post is about making things stop.

Check the price before you spend

Before launching, ask what it will cost per running hour. In the CLI, apidly up prints the server, its price per hour, the cost for the hours you ask for (--hours) and what the disk costs while stopped, then waits for your answer unless you pass --yes. --budget is a ceiling per running hour, disk included:

apidly up images --hours 3 --budget 0.80

If nothing fits under the ceiling, the cheapest server that fits is shown and marked as over it. The same guard exists for code: the Terraform provider takes max_hourly_usd on a server and sends nothing when the plan costs more, and the MCP server takes --max-hourly-usd for every launch of a session. Both are covered in the MCP post and the Terraform post of this series.

Layer 3: stop each server by rule

The most common bill is a server that kept running after the work finished. Automatic stop rules fix that for one server at a time. Set them in the console under the server's Settings, in the last step of the deploy form, or from the CLI:

apidly automation set SERVER_ID \
  --max-runtime-hours 8 \
  --idle-threshold 5 --idle-minutes 30 \
  --spend-cap 20

This gives one server three independent stops, and whichever comes first wins:

  • --max-runtime-hours 8 stops it after 8 hours of running. Starting it again begins a new run.
  • --idle-threshold 5 --idle-minutes 30 stops it when GPU use stays under 5% for 30 minutes. The rule needs fresh usage readings across the whole period, so a server that has just started, or one that reports nothing, is never stopped by it. That is deliberate: wrongly stopping a busy job costs more than a few extra idle minutes.
  • --spend-cap 20 stops it once it has been charged 20 dollars over its whole life. The smallest cap is 0.10 dollars. A server you start again after that stops again, so raise or clear the cap first.

There are also --stop-at and --stop-after-hours for a stop at a set time, --destroy-at for deleting the server and its disk at a date (this cannot be undone), and --schedule-file for weekly windows. apidly automation get SERVER_ID shows what is in force. The full rules are on the Automation page.

Two details matter when you rely on this. First, a stop keeps the disk, and the disk keeps billing by the second until you destroy the server. A stopped server is cheap, not free. Second, rules are evaluated every minute, so a server can run for up to about a minute past a limit. The spend cap counts charges that are not yet booked, so it acts close to the amount you set.

Layer 4: a monthly budget for the whole organization

Server rules protect one server. A monthly budget protects the account. An owner or admin sets a budget in US dollars; it counts server usage in the current calendar month, in UTC.

apidly budget set --monthly 500 --alert 50,80,100
apidly budget status

The alert levels are 50%, 80% and 100% of the budget. Each level sends one email to the organization owner per month and shows a notice in the console. apidly budget status compares this month's spend with the budget at any time.

By default a budget only alerts. If you want it to act, turn on the hard stop:

apidly budget set --monthly 500 --hard-stop --confirm-hard-stop

With the hard stop on, when the month's usage reaches the budget, every running server is stopped, and new launches and starts are refused with 403 budget_reached until you raise or remove the budget. Disks are kept; nothing is deleted. Work that was not saved to a disk is lost when a server stops, which is why the CLI makes you confirm the flag. In the next month, servers stay stopped until you start them yourself.

How far past the budget can you go? The meter books spend every minute, and the budget check runs right after each booking. The overshoot is therefore the usage of one tick, plus the disk charges of the stopped servers for the rest of the month, since the budget stops servers but does not delete their disks. If spend must stop entirely, destroy what you do not need.

Layer 5: limits for API keys and team members

Servers launched by automation need their own guard, because scripts do not read emails. A key can carry a monthly spending limit. It counts the usage charges of the servers and endpoints launched with that key, and the storage of volumes created with it, in the current UTC month.

apidly api-keys create ci-training --scope servers --monthly-limit 50
apidly api-keys limit KEY_ID --monthly-limit 100
apidly api-keys limit KEY_ID --monthly-limit none

When the limit is reached, launches, starts and volume creates with that key are refused with 403 key_limit_reached, and the owner gets one email that month. Rotating a key does not reset its month: what the old key launched counts toward the new one.

Read the next sentence twice, because it is the most common misunderstanding about spending limits: a key limit is a launch gate, not a cap. Servers that are already running are not stopped, and they keep billing. A server launched at 99% of the limit keeps running until something else stops it. So pair a key limit with an automatic stop rule on the servers the key launches (the organization can set a default automatic stop for new servers), and with the budget hard stop from layer 4. The limit's job is to stop a leaked or looping key from starting more servers, and it does that. Changing a limit needs the full scope, and a key that has a limit of its own cannot change limits. See API keys.

Team members have the same kind of limit, by launcher instead of by key:

apidly team limit USER_ID 200
apidly team limit USER_ID --clear

It counts this month's charges of the servers the member launched, from the console or with any key. At the limit their launches and starts are refused with 403 member_limit_reached; running servers keep running. Unlike the key limit, no email is sent. Details are in Team roles.

Layer 6: a monthly cap on a serverless endpoint

A serverless endpoint is different from a server: you do not start it, requests do, and a burst of traffic can start workers you did not plan for. Two limits bound that. The hourly spending cap (max_hourly_spend_usd in Terraform) bounds how many workers can run at once, because the endpoint never runs more workers than that amount pays for per hour. The monthly cap bounds the total.

apidly endpoints update ENDPOINT_ID --monthly-cap 200
apidly endpoints update ENDPOINT_ID --monthly-cap none

The cap counts what the endpoint's workers were charged this month, the same entries your ledger shows. When the total reaches the cap, the endpoint pauses itself, releases its workers and emails the owner. After that:

  • New jobs are refused with 409 spend_cap_reached, and calls to the endpoint's address get 503 endpoint_paused, so callers get a clear answer instead of a slow one.
  • Resuming is refused with 409 spend_cap_reached until you raise or remove the cap, or a new month starts.
  • Charges are checked every minute, so a month can end a few minutes of worker time above the cap.
  • By default the endpoint stays paused after a month change. --resume-at-new-month on makes it resume by itself when a new UTC month starts below the cap, with an email to the owner. Only an endpoint paused by its cap resumes this way; one paused for its balance, for failed workers or by a person never does.
  • A stopped endpoint is not paused by the cap, so the disks and model cache of its stopped workers keep billing. --release-stopped-at-cap on releases them at the cap so spending actually stops. The next start is then a cold one. The endpoint card shows what keeps charging per hour.

The honest trade-off is availability. A cap turns overspend into downtime, and the endpoint stays down until a person or the next month decides otherwise. For a production endpoint, set the cap high enough to be a safety net rather than a daily limit, and get warned earlier with the budget levels. The Endpoints page has the full behavior.

Putting the layers together

Here is one way to combine them for a small team that trains in the evenings and serves a model during the day. The numbers are examples.

Where Control Example setting What it stops
Account Prepaid balance, low-balance warning --low-balance 25 Running on credit that is gone
Account Monthly budget with hard stop --monthly 500 --hard-stop A month that runs away
Key Monthly limit --monthly-limit 50 on the CI key A leaked or looping key launching more
Member Monthly limit apidly team limit USER_ID 200 One person's launches
Server Auto-stop rules 8 hours, idle 30 minutes, 20 dollar cap A forgotten or stuck server
Endpoint Monthly cap --monthly-cap 200 A traffic burst

Each row covers a gap the others leave. The budget hard stop catches what a key limit lets keep running. The server rules catch what the budget would only catch at month end. The prepaid balance catches everything else, at the price of a stop you did not choose.

What none of this does

Be clear about the edges, because a control you misunderstand is worse than none.

  • Limits act on spend the meter has booked, once a minute. They are tight, not instantaneous, and several launches in the same minute can each pass a check that they would together exceed.
  • Key and member limits stop new work, not running work.
  • A hard stop stops servers; it does not delete disks, and disks keep billing.
  • None of these limits is a promise about your total bill. They make a surprise unlikely; the balance is the only hard ceiling, and only while auto top-up is off.

A good first setup takes about ten minutes: add a modest amount of credit, set a monthly budget with alerts at 50, 80 and 100 percent, put an auto-stop rule on every server you launch, and give each script its own key with a limit. Then watch the first week of usage and tighten from there.

Try what this guide shows

Try it on a real GPU server

Create a free account and add a balance from $10. Servers are billed by the second, and the review step shows the price per hour before you request one.

Related guides