Skip to content

AI limits and blocks: cap spending, requests and tokens

Describes AI 0.29.1.

AI calls cost money, so PhoenixKit lets you cap them. Each AI task can have limits for the whole task and for each person using it, in money, requests and tokens, per day and per month. You can also block a person from a task, for example after their requests were flagged as off-purpose.

Where to find it

Open AI, then Tasks (/admin/ai/tasks). Each task card has a Limits and use: table and, below it, its flags and blocks. Anyone with the AI permission can see them. Changing them needs the Manage the AI task guard permission; without it the values are shown read-only.

A task on the AI Tasks page with its Limits and use table: money, requests and tokens used today and this month, and fields for a daily and monthly limit A task on the AI Tasks page with its Limits and use table: money, requests and tokens used today and this month, and fields for a daily and monthly limit

Each task's limits, set on the Tasks page.

The limits table

There is one row each for Money (US dollars), Requests and Tokens. The columns:

  • Used today and Used this month: what the task has used so far.
  • Task, a day and Task, a month: limits for the whole task.
  • Each user, a day and Each user, a month: the default limit for every person. These columns are missing when the task’s module sets per-user limits itself; the card then says Limits per user are set by the task’s module.

Days and months follow the site time zone. An empty field inherits the task’s default limit when its module gives one (shown greyed in the field), and otherwise means no limit. 0 allows nothing. Money takes dollars, such as 0.50; the others take whole numbers.

Warn at, % (80 unless set) is when a warning goes out: a person nearing their own limit is told, and the people under Who is notified are told when the task nears its limit. When a limit is reached, both are told. Save limits saves the table.

Only successful calls count toward a limit. Calls running at the same time can each go past a limit by their own size, so a limit can be overshot a little.

If the card says Money is not counted for this task’s calls on some endpoints, nothing prices those calls: the provider reports no cost, and no price applies. Request and token limits still work there. Entering a price on the endpoint fixes it (see the AI endpoints guide).

When a limit is reached

A reached limit refuses further calls in that task until the day or month is over. The refused calls are marked Refused on the Usage page.

  • When the task has reached one of its own request or token limits, the card says Reached: and names it, with a Forgive button.
  • People at a limit now: lists people who reached their personal or per-user limit, each with Forgive.

Forgive restarts the count from that moment until the end of the day or month. The limit itself stays the same.

Personal limits

Personal limits: lists people with their own limits for this task (None if nobody has). Find a person with Set personal limits for…, enter their daily and monthly limits, and Save. Remove takes a person’s personal limits away, so the per-user defaults apply to them again.

Off-purpose flags and blocks

Some tasks ask the model to refuse and flag requests that don’t match the task’s purpose. For those, the switch The model flags off-purpose requests turns that on or off; off, the model gets no such instruction and no flags are written.

  • Off-purpose flags, last 30 days: each Person with their number of Flags, and the recent flags with When, Person and Reason. For a private task, the reason shows Hidden: the task is private unless you have the Manage the AI task guard permission.
  • Block: opens a short form. Why (seen by those who manage the guard) takes the reason. The person then can’t use the tasks of that task’s group until the block is lifted.
  • Blocked now: lists blocked people with Since, By and Reason (Nobody when empty). Lift asks for an optional Note and ends the block.

Only an Owner can block an Owner or lift an Owner’s block. A person who isn’t an Owner can’t lift a block on themselves.

What it doesn’t do

  • The page has no site-wide spending cap. Those caps exist but are set in code (see below).
  • A limit doesn’t stop a call already running.
  • Flags and blocks apply only to tasks that use them; a call without a task isn’t flagged or blocked.

For developers

Site-wide caps apply to every AI call, with or without a task: a daily cap for the whole site, per endpoint, per user and per user in calls, and a monthly cap for the site. Daily caps look at the last 24 hours; the monthly one at the calendar month in the site time zone. Set them in US dollars with PhoenixKitAI.Budget.set_limit/2, for example PhoenixKitAI.Budget.set_limit(:global_month, "100"); "0" means no cap. A module can give its tasks default limits with default_limits in its task declaration.