Skip to content
ACS Infra

Tokens and Holds

Before Inference runs a Completion, the API holds the most tokens that the Completion can use, from the tokens you have left this month. Requests that run at once never spend more tokens than you have.

Your tokens a month

You may spend a set number of tokens in each calendar month, in UTC, across your API keys and the App. An approval gives you 5,000,000 tokens a month by default, and an Invite can add more on top. Tokens lists the default.

On the first day of each month, the count of the tokens that you used starts again from 0. Tokens that you did not spend do not carry over. A Hold counts toward the month in which it started. Tokens that it gives back after the month changed do not change the new month's count.

To get more, ask in the App (Ask for more tokens). When an admin approves your request, they add tokens to each month, and the added tokens count this month at once. An admin can also set your tokens a month to another number.

When a request ends and the tokens that you spent this month reach 90%, the API emails you once in that month. The tokens that your other requests still hold do not count toward the 90%, because a Hold gives back what its request does not use. The email's subject gives the share of tokens that you spent. Its tokens left count what your running requests hold as used, as GET /v1/quota does. A line says how many tokens they hold. The email also says the day your tokens refill. It links to the App's Usage page and to the form to ask for more. If the email service is busy and refuses the email, a request that ends past 90% at least 10 minutes later sends it again. The API sends the email at most once a month. GET /v1/quota always answers with the tokens left (Check your tokens from a script).

The Hold

Before the API sends a request to Inference, it takes a Hold: the most tokens that the request can use. For each prompt, the Hold is the prompt's tokens and n × max_tokens, with max_tokens counted as at least 1. With echo and max_tokens: 0, Inference still generates and counts 1 token for each choice.

A request with Activations or Steering vectors and more than one choice holds each prompt's tokens once for each choice. Inference reads the prompt again for each choice, and the request pays for each read (Steer many prompts and choices).

The API counts a text prompt with the model's own tokenizer, the files that Inference loads. It counts the tokens that Inference reads. The count includes the BOS token when add_special_tokens is on, as it is by default. A prompt of token ids counts one token for each id.

Some models have no tokenizer in the API. For them, a text counts one token for each byte of its UTF-8 text, and 1 for the BOS token. A byte-level tokenizer never makes more tokens than bytes, so this count can only be too high. The tokenizer reads at most 8 bytes of a request's texts for each token of the model's context. The texts after that count by their bytes in the same way.

For example, "The sky is" with max_tokens: 2 on llama-8b holds 6 tokens: 4 for the prompt with its BOS token, and 2 for max_tokens. A request that stops before max_tokens gives back the tokens that it did not write.

While a request runs, its Hold counts as spent. Requests that run at once never hold more tokens than you have, and each one sees what the others hold. The App's Usage page shows the tokens left after their Holds, and which requests still run, as Read your usage says. GET /v1/quota answers the same count to a script, so its left is the largest Hold that your next request can take.

How a Hold ends

Each Hold ends once, by one rule for POST /v1/completions, Jobs, Looms, and the Playground. It settles to the tokens that the request used, or the API releases it and the request costs nothing.

A Hold settles in these cases:

  • When Inference answers, you pay the Usage that it reports, and the rest of the Hold goes back. With Activations or Steering vectors and more than one choice, you pay each prompt once for each choice. That can be more than usage says.
  • When a stream stops early, because you closed it or it broke, you pay for the tokens that it sent. A Loom Node runs as a stream, so a Node that you stop pays for the text that it grew.
  • When a request without a stream stops after it reached Inference, you pay the whole Hold. A Job that you cancel while it runs is such a request.
  • A Completion with Activations or Steering vectors and more than one choice can fail in one choice after others answered. You pay the Usage of the choices that answered, and the request gets the error (Steer many prompts and choices).

A request without a stream pays its whole Hold because Inference reports its Usage only at the end. When the request stops in the middle, the API has no count of the tokens, and Inference may have done the work. A stream tells the API how many tokens it sent so far, so a cut stream pays only for those.

A released Hold costs nothing, and the Usage page does not list its Completion. The API releases a Hold in these cases:

  • Inference refuses the request, or fails before it sends any token, a timeout included. For a request with Activations or Steering vectors and more than one choice, that is before any of its choices answered.
  • The request stopped before it reached Inference.
  • The API itself failed.
  • The API stopped a request of a Job, a Node, a Playground Run, or a harvest, so that it runs again later.

If a Completion uses more tokens than its Hold, the API counts the extra tokens in this month too, even past your tokens a month.

Near the end of your tokens

When the tokens that you have left cannot hold a request to POST /v1/completions, the API does not refuse the request at once. It lowers max_tokens to the most that fits, and runs the request, so that a script near the end of its tokens keeps making progress. The answer then has this header:

Header
X-Acs-Max-Tokens-Clamped: requested=200,applied=21,reason=budget,source=client

Here, 25 tokens were left, and the prompt "The sky is" holds 4 of them on llama-8b. The API lowered max_tokens from 200 to 21, and a choice can end at 21 tokens with finish_reason: "length". source is client when you set max_tokens, and default when you left it out. reason is budget here. It is deadline+budget when the API first lowered a max_tokens that you left out to the time limit of a request without a stream. Requests without a stream explains that limit.

Only when not even one token for each choice fits does the API refuse the request. It answers 429 budget_exceeded, and the request does not reach Inference. The message says how many tokens the request can use, and the day on which your tokens refill. Not enough tokens shows the error.

Jobs, Loom Branches, and Playground Runs never lower a max_tokens that you set. A request of theirs that your tokens cannot hold fails with 429 budget_exceeded, and its max_tokens stays as you set it.

Holds of background work

A Job, a Branch, or a Run holds no tokens when you make it. Each Job, each Node, and each Run takes its own Hold when it starts to run, as a request to POST /v1/completions does.

When you make a Job, a Branch, or a Run, the API checks only that your tokens can hold its smallest request. If they cannot, it refuses the work with 429 budget_exceeded and makes nothing. The request can still find too few tokens when it runs. A Job then fails, and its result is the 429 error object. A Node fails with the same error.

A harvest generates no tokens, so it holds the tokens of its prompts only. It counts one token for each byte of each prompt's UTF-8 text, and 1 more for each start token. When you submit it, the API checks that your tokens can cover that, and answers 429 budget_exceeded if they cannot. The harvest takes its Hold when the API starts it, and keeps it while its GPU run lasts.

A harvest's Hold ends by its own rule, because Inference counts its tokens only when it completes:

  • A completed harvest pays the tokens that Inference read, up to its Hold. Its tokens field shows them.
  • A harvest that you cancel while it is running and its GPU run started pays its whole Hold. Any other cancel costs nothing.
  • A failed harvest costs nothing.

The App's Usage page lists a harvest's Hold under the source Harvests.

A Node's prompt is the text of the path from the root to its parent. A Node deep in a Loom holds more tokens than a Node near the root. A Branch of 4 Nodes takes 4 Holds, one for each Node.

A Completion that waits in its API key's line for a place to run holds no tokens until it starts. Traffic gives the size of that line.

Activations and Steering vectors cost no tokens of their own. A request with them holds and spends tokens as any other Completion does.

Next steps

Handle the end of your tokens reads the header and the 429 errors in code. Ask for more tokens says whom to write to. Tokens lists every number about tokens.

On this page