# Run several products in one workspace

> Run limits for more than one product from one workspace, with a budget per product and usage you can read per product.

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

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:

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();

  const writerBudget = await limitry.limits.create({
    name: "Writer AI budget",
    subject: { kind: "user" },
    action: "writer.ai-call",
    amount: 200,
    unit: "cents",
    window: "month",
  });
  console.log(writerBudget.id);

  const supportBudget = await limitry.limits.create({
    name: "Support AI budget",
    subject: { kind: "user" },
    action: "support.ai-call",
    amount: 100,
    unit: "cents",
    window: "month",
  });
  console.log(supportBudget.id);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()

  writer_budget = limitry.limits.create(
      name="Writer AI budget",
      subject={"kind": "user"},
      action="writer.ai-call",
      amount=200,
      unit="cents",
      window="month",
  )
  print(writer_budget.id)

  support_budget = limitry.limits.create(
      name="Support AI budget",
      subject={"kind": "user"},
      action="support.ai-call",
      amount=100,
      unit="cents",
      window="month",
  )
  print(support_budget.id)
  ```

* CLI

  ```bash
  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
  ```

* curl

  ```bash
  curl -X POST https://api.limitry.com/v1/limits \
    -H "Authorization: Bearer $LIMITRY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name":"Writer AI budget","subject":{"kind":"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","subject":{"kind":"user"},"action":"support.ai-call",
         "amount":100,"unit":"cents","window":"month"}'
  ```

## 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:

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();

  const limit = await limitry.limits.create({
    name: "Writer total",
    subject: { kind: "product", id: "writer" },
    action: "*",
    amount: 500000,
    unit: "cents",
    window: "month",
  });
  console.log(limit.id);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()

  limit = limitry.limits.create(
      name="Writer total",
      subject={"kind": "product", "id": "writer"},
      action="*",
      amount=500000,
      unit="cents",
      window="month",
  )
  print(limit.id)
  ```

* CLI

  ```bash
  limitry limits create --name "Writer total" \
    --subject '{"kind":"product","id":"writer"}' --action "*" \
    --amount 500000 --unit cents --window month
  ```

* curl

  ```bash
  curl -X POST https://api.limitry.com/v1/limits \
    -H "Authorization: Bearer $LIMITRY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name":"Writer total","subject":{"kind":"product","id":"writer"},
         "action":"*","amount":500000,"unit":"cents","window":"month"}'
  ```

## 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 reserved cost fits the user’s monthly budget and the product’s monthly total, and then charges what the call actually cost to both:

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();

  const draft = await limitry.reserve(
    {
      subject: { kind: "user", id: user.id },
      shared: [{ kind: "product", id: "writer" }],
      action: "writer.ai-call",
      cost: 5,
    },
    async (reservation) => {
      const res = await callModel(prompt);
      reservation.cost(priceCents(res.usage));
      return res.text;
    },
  );
  console.log(draft);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()

  with limitry.reserve(
      subject={"kind": "user", "id": user.id},
      shared=[{"kind": "product", "id": "writer"}],
      action="writer.ai-call",
      cost=5,
  ) as reservation:
      res = call_model(prompt)
      reservation.cost = price_cents(res.usage)
      draft = res.text
  print(draft)
  ```

A 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](/docs/guides/limit-ai-spend/).

## 4. Read usage per product

The product’s total is a limit like any other, so the [Usage](/docs/usage/) page shows what each product used this month. Through the API, ask for that limit’s usage:

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();

  const usage = await limitry.usage.query({ limitId: "lmt_3f0c…" });
  console.log(usage);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()

  usage = limitry.usage.query(limit_id="lmt_3f0c…")
  print(usage)
  ```

* CLI

  ```bash
  limitry usage query --limit-id lmt_3f0c…
  ```

* curl

  ```bash
  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 `subject=user:…`.

## Why there are no projects

A workspace holds your team, your bill and your two environments, [test and live](/docs/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](/docs/checks/), [Pools, balances and budgets](/docs/pools-and-budgets/).
