Run several products in one workspace
Say your company runs two products on Limitry, a writing assistant and a support bot, and both pay per token for their AI features. Each of your users gets a monthly AI budget in each product, and each product has a monthly total you don’t want to go over. You can do all of this in one workspace, with one team and one bill.
Limitry has no separate “project” to set up. A product is one more subject, and your action names say which product a check is for.
1. Name actions after the product
Section titled “1. Name actions after the product”Prefix each action with the product, so the two never share a limit by
accident: writer.ai-call and support.ai-call. Action names are your
own text, and a limit matches an action by its exact name (or * for
every action). Count in cents, so Limitry charges each call at its price:
import { createClient } from "@limitry/sdk";
const limitry = createClient();
await limitry.limits.create({ name: "Writer AI budget", subjectKind: "user", action: "writer.ai-call", amount: 200, unit: "cents", window: "month",});await limitry.limits.create({ name: "Support AI budget", subjectKind: "user", action: "support.ai-call", amount: 100, unit: "cents", window: "month",});from limitry import Limitry
limitry = Limitry()
limitry.limits.create( name="Writer AI budget", subject_kind="user", action="writer.ai-call", amount=200, unit="cents", window="month",)limitry.limits.create( name="Support AI budget", subject_kind="user", action="support.ai-call", amount=100, unit="cents", window="month",)limitry limits create --name "Writer AI budget" --subject-kind user \ --action writer.ai-call --amount 200 --unit cents --window monthlimitry limits create --name "Support AI budget" --subject-kind user \ --action support.ai-call --amount 100 --unit cents --window monthcurl -X POST https://api.limitry.com/v1/limits \ -H "Authorization: Bearer $LIMITRY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name":"Writer AI budget","subjectKind":"user","action":"writer.ai-call", "amount":200,"unit":"cents","window":"month"}'
curl -X POST https://api.limitry.com/v1/limits \ -H "Authorization: Bearer $LIMITRY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name":"Support AI budget","subjectKind":"user","action":"support.ai-call", "amount":100,"unit":"cents","window":"month"}'2. Give each product a budget
Section titled “2. Give each product a budget”A product’s total is a limit on a subject of kind product, with the
product’s id. Use * as the action, so it counts every check made for
that product. Here the writing assistant may spend $5,000 a month on
its AI features:
import { createClient } from "@limitry/sdk";
const limitry = createClient();
await limitry.limits.create({ name: "Writer total", subjectKind: "product", subjectId: "writer", action: "*", amount: 500000, unit: "cents", window: "month",});from limitry import Limitry
limitry = Limitry()
limitry.limits.create( name="Writer total", subject_kind="product", subject_id="writer", action="*", amount=500000, unit="cents", window="month",)limitry limits create --name "Writer total" \ --subject-kind product --subject-id writer --action "*" \ --amount 500000 --unit cents --window monthcurl -X POST https://api.limitry.com/v1/limits \ -H "Authorization: Bearer $LIMITRY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name":"Writer total","subjectKind":"product","subjectId":"writer", "action":"*","amount":500000,"unit":"cents","window":"month"}'3. Check with the product as a shared subject
Section titled “3. Check with the product as a shared subject”Name the user as the subject and the product in shared. Limitry
allows the call only if the estimate fits the user’s monthly budget and
the product’s monthly total, and then charges what the call actually
cost to both:
import { createClient } from "@limitry/sdk";
const limitry = createClient(); // reads LIMITRY_API_KEY
const draft = await limitry.hold( { subject: { kind: "user", id: user.id }, shared: [{ kind: "product", id: "writer" }], action: "writer.ai-call", estimate: 5, }, async (held) => { const res = await callModel(prompt); held.cost(priceCents(res.usage)); return res.text; },);from limitry import Limitry
limitry = Limitry() # reads LIMITRY_API_KEY
with limitry.hold( subject={"kind": "user", "id": user.id}, shared=[{"kind": "product", "id": "writer"}], action="writer.ai-call", estimate=5,) as held: res = call_model(prompt) held.cost(price_cents(res.usage)) draft = res.textA check has one cost, and Limitry charges it to every limit that
applies. Give a product’s total the same unit as the limits under it,
here cents, so the numbers add up. priceCents is your own price
table, as in
Limit AI spend per user of your product.
4. Read usage per product
Section titled “4. Read usage per product”The product’s total is a limit like any other, so the Usage page shows what each product used this month. Through the API, ask for that limit’s usage:
import { createClient } from "@limitry/sdk";
const limitry = createClient();
const usage = await limitry.usage.query({ limitId: "lim_3f0c…" });from limitry import Limitry
limitry = Limitry()
usage = limitry.usage.query(limit_id="lim_3f0c…")limitry usage query --limit-id lim_3f0c…curl "https://api.limitry.com/v1/usage?limitId=$WRITER_TOTAL_ID" \ -H "Authorization: Bearer $LIMITRY_API_KEY"For one user in one product, read the user’s limit for that product’s
action, with subjectKind=user&subjectId=….
Why there are no projects
Section titled “Why there are no projects”A workspace holds your team, your bill and your two environments, test and live. Everything below that is data you choose: subject kinds, ids and action names. A product, a region or a feature fits the same pattern as a team pool, so you learn one idea instead of two. One check can then enforce a user’s cap and a product’s total together.
If two products need different people or different bills, give each its own workspace.
Related: Checks, Pools, balances and budgets.