End‑user plans & quotas
Meter and limit AI usage per end user of your app according to the plans you sell: free, pro or anything else.
On this page
When you sell an app with AI features, your customers are on your plans: free, pro, team. Worksi can enforce those plans on every model call. Tell the gateway who the end user is and which of your plans they are on, and an end_user_quota policy decides how much they may use.
1. Send the end user and their plan#
Add two headers to each gateway call:
| Header | Value |
|---|---|
X-AIW-End-User | A stable, pseudonymous id for the user, such as a salted hash. Never an email address or a name. |
X-AIW-End-User-Plan | The user’s plan in your app, for example free or pro |
import osfrom openai import OpenAI client = OpenAI( base_url="https://gateway.worksi.ai/v1", api_key=os.environ["AIW_API_KEY"],) def answer( user_id_hash: str, user_plan: str, messages: list[dict],) -> str | None: headers = { # a pseudonymous id, not an email "X-AIW-End-User": user_id_hash, # your own plan name, e.g. "free" "X-AIW-End-User-Plan": user_plan, } res = client.chat.completions.create( model="gpt-5-mini", messages=messages, extra_headers=headers, ) return res.choices[0].message.contentimport OpenAI from "openai" const client = new OpenAI({ baseURL: "https://gateway.worksi.ai/v1", apiKey: process.env.AIW_API_KEY,}) export async function answer( userIdHash, userPlan, messages,) { const headers = { // a pseudonymous id, not an email "X-AIW-End-User": userIdHash, // your own plan name, e.g. "free" "X-AIW-End-User-Plan": userPlan, } const res = await client.chat .completions.create( { model: "gpt-5-mini", messages }, { headers }, ) return res.choices[0]?.message.content}With the Python SDK, set them once on the run and every call inside it carries them:
with aiw.run("customer-chat", end_user=user_id_hash, end_user_plan="free"): ...2. Create an end‑user quota policy#
Create an end‑user quota policy in Governance → Policies, or post it to /api/v1/policies. Every limit is per end user and each one is optional.
{ "name": "Plan limits for app users", "type": "end_user_quota", "scope_type": "org", "enforcement": "enforce", "rules": { "plans": { "free": { "requests_per_day": 50, "tokens_per_day": 50000, "models": ["gpt-5-mini"] }, "pro": { "requests_per_day": 2000, "cost_usd_per_month": 20 } }, "default_plan": "free" }}| Rule | Meaning |
|---|---|
requests_per_day | Model calls per end user per UTC day |
tokens_per_day | Input plus output tokens per end user per UTC day |
cost_usd_per_month | Model spend per end user per calendar month |
models | The only models this plan may use |
default_plan | The plan applied when a call carries no X-AIW-End-User-Plan |
Plan names use lowercase letters, digits, - and _. Like every policy, the quota can be scoped to the whole organization, a workspace, an environment, an agent, a workflow or a team, and it can start in monitor mode, which records what would have been limited without blocking anyone.
3. Handle the limits in your app#
| Response | When | What your app should do |
|---|---|---|
429 end_user_quota_exceeded | A request, token or cost limit of the user’s plan is reached | Show an upgrade prompt or a “try again later” message. Retry-After tells you when the window resets, and the error details name the plan, the limit and the window. |
403 model_not_allowed | The requested model is not in the plan’s models | Fall back to a model the plan allows |
Blocked calls never reach your provider, so they cost nothing, and they don’t count toward your Worksi plan’s monthly requests.
4. See usage per end user#
Performance → End users lists your end users with requests, tokens, cost, errors, plan and last activity. Filter by plan or search for a user, and open one to see their usage over time and their recent traces. Every span also carries the plan as aiw.end_user_plan.
Good practice#
- Hash user ids with a secret salt before sending them. The end‑user id is stored as it is and is not redacted.
- Keep plan names in step with your billing system, so every user gets the limits they pay for.
- Start in monitor mode for a few days, compare what would have been limited with what you expect, then enforce.
- End‑user plans and quotas are included in every Worksi plan.
Questions? Email info@xeoo.io.