TokenPolice
Docs
Recipes

Per-feature budgets

Budget each feature or workflow separately — so your summarizer and your chat can't eat each other's budget.

Different features have different appetites. A background summarizer, a RAG search, an interactive chat — you often want each on its own budget so a spike in one doesn't starve the others. Tag each feature and give it its own limit.

The rule

Tag your calls with a feature label (below), then click New rule from template on the Firewall page and pick one of these:

Give each team or feature its own budget — set Which tag? to feature and every feature gets its own separate budget. Only the feature that overspends is paused.

Per-user limit for a feature — if you'd rather cap each user inside one named feature. You name the feature and the per-user limit.

For the built-in split between chat and embedding calls you don't need a label at all — filter on operation is embedding. Custom labels are for splits TokenPolice can't infer, like "summarizer" vs "chat". See Filter vs apply-to.

The snippet

Give each feature its own workflow with a feature value in metadata:

import token_police as tp

@tp.workflow(name="summarizer", metadata={"feature": "summarizer"})
def summarize(doc: str):
    return client.chat.completions.create(...)

@tp.workflow(name="chat", metadata={"feature": "chat"})
def chat(user_id: str, query: str):
    return client.chat.completions.create(...)
import { workflow } from "token-police";

const summarize = workflow(
  { name: "summarizer", metadata: { feature: "summarizer" } },
  (doc: string) => client.chat.completions.create(/* ... */),
);

Every call inside summarize is tagged feature=summarizer, every call inside chat is feature=chat, and the rule keeps their budgets apart. Tag values are matched exactly, so keep the spelling stable — see Identity.

Next