Billing and Usage
Read invocation usage, understand billing models, and check reload availability.
#Billing and usage
#Per-invocation usage
Agent.invoke(), Swarm.invoke(), and their async forms return an InvokeResponse. Its token_usage field is a JSON dictionary when the runtime reports usage. It is not a TokenUsage attribute model.
from maivn import Agent
agent = Agent(name="assistant", api_key="...")
response = agent.invoke("Summarize the latest release notes")
usage = response.token_usage
if usage is not None:
print(usage.get("input_tokens"))
print(usage.get("output_tokens"))
print(usage.get("total_tokens"))The dictionary holds input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens, reasoning_tokens and total_tokens. total_tokens is input plus output. Provider and runtime versions may add keys, so treat the dictionary as an extensible payload and guard optional values.
Work a run schedules after it answers, such as memory extraction, is not in the response. client.session_usage(session_id) returns provider-reported counts for the whole session once that work finishes.
The two counts can differ even for a run with no follow-up work. input_tokens on the response counts only the request content you supplied or can inspect: it leaves out the platform's own orchestration prompt that some hosted model runtimes include in their input. session_usage() reports what the provider counted, which includes that prompt, so its input_tokens can be higher.
Each model counts its tokens as standard tokens at its own list price. See Models and rates for every model, its provider and its rates.
For provider-reported counts and a clearly illustrative cost calculation, see Usage and Cost. Do not treat that example's placeholder rates or model names as the live catalog.
#Plan limits
When a Team has used up a plan allowance, the platform refuses to start the next run with HTTP 429 and the code plan_limit_exceeded. The SDK raises PlanLimitExceededError, a subclass of MaivnHTTPError, and never retries it: the same refusal comes back until the period resets or the plan changes. The error carries meter, plan, limit, used, remaining, period_resets_at and upgrade, and describe() returns one sentence you can show a user. See Errors & Exceptions.
from maivn import PlanLimitExceededError
try:
response = agent.invoke("Summarize the latest release notes")
except PlanLimitExceededError as error:
print(error.describe())The meters are tokens (monthly processing allowance), fires (monthly runs) and spend (a spend guardrail). Runs that start while you are at 75% or 90% of an allowance are not blocked. They carry an X-Maivn-Plan-Warning response header, and a stream also shows an enrichment event with the phase plan_warning. See Frontend Events.
Team owners also get an email when the team reaches 75% and 90% of its standard tokens or runs for the billing period, once for each level. These two emails are not sent on the Free plan. If a scheduled trigger is skipped because an allowance is used up, the owners get one email for that trigger in the billing period. A skipped run is not run later.
#What counts as a run
Each run you start uses one run from the fires allowance, whether you start it through the API, as a hosted job or from a trigger. Resuming a paused run, answering an approval and decision calls do not use a run. Work inside a run, such as tool calls and sub-agents, does not use more than the one run.
A run that fails because of a fault on mAIvn's side or at the model provider is not counted against the runs allowance. A run you cancel, or one that stops at one of your own limits or on invalid input, is counted.
#Concurrent jobs
Concurrent jobs are the number of runs your team has in progress at once. They are counted across every way a run starts: an API call, a thread message, a hosted job and a trigger. A run that is paused while it waits on a person does not count. Resuming a run, answering an approval and decision calls do not start a run, and tool calls and sub-agents inside a run do not count separately.
When your team is at the limit, a new run start is refused with HTTP 429 and the code concurrent_jobs_limit_reached. The refused start did not begin a run, so sending it again is safe. The SDK does that for you: it waits as long as the platform asks and sends the same start again, for up to 60 seconds in total, and then raises ConcurrentJobsLimitError. Set concurrent_jobs_wait_seconds on Client or ClientConfig to change that wait budget. See Errors & Exceptions.
A paused run needs a free slot to resume. If your team is at the limit when you answer it (an approval, an interrupt or a follow-up question), the answer is refused with the same HTTP 429 and nothing is recorded. The SDK waits and sends the same answer again within the same wait budget, and then raises ConcurrentJobsLimitError.
A trigger event that arrives while your team is at the limit is rejected with the reason concurrency_cap, the same reason a trigger's own concurrency option uses.
The plan limit is the ceiling for the whole team. Two narrower limits still apply inside it: a project can have two hosted jobs running at once (see Hosted Jobs), and each trigger runs at most 4 at once unless you change its concurrency option (see Scheduled Invocation).
#Aggregated billing models
The SDK exports BillingUsage, BillingPlan, BillingCurrentUsage, and nested breakdown models. These validate data obtained by an authorized application integration. They do not fetch it.
from maivn import BillingUsage
usage = BillingUsage.model_validate(application_payload)
print(usage.organization_id)
print(usage.breakdown.totals.billed_tokens)The public Client does not provide get_usage(). Do not infer a billing URL or call an undocumented HTTP helper. Returned plan fields describe the supplied payload. The supplying service is authoritative for current availability and prices, as well as allowances and enforcement.
#Automatic reload
Automatic reload lets an eligible Team pre-authorize a fixed-dollar reload when remaining usage reaches a selected threshold. It is off by default. The control requires a saved payment method and an environment where billing is enabled. It is unavailable while hosted billing is disabled. Confirm availability in your provisioned environment.
When the control is available, you choose:
Read the quote shown by the Portal before saving. It is the current source for what the selected amount buys. Avoid copying plan names, rates or allowance figures from documentation into application logic.
Saving the setting does not charge the payment method. When billing is enabled, reload attempts use an idempotent identity so a network retry refers to the same charge. A failed charge adds no allowance and may pause automatic reload. The environment's Portal and receipts are the source of truth for status, retry behavior and credited allowances.
Amounts are whole dollars from $10 to $10,000. One-time top-ups, where available, use the same range.
See Billing models for the SDK read-model boundary.
#In the Portal
Usage & billing in the sidebar opens a team's billing area. It has an overview, a usage page, invoices, payment methods and a change-plan page. The Runs page lists runs for the team. Owners and admins can change billing settings. Any member can read them.
#Payment methods
A saved payment method needs a United States billing address. A card without one is not saved, and nothing is charged to it. At launch, mAIvn accounts are for businesses located in the United States; see Portal Authentication.