Skip to main content
The Stigg Agent SDK is in public beta.

What it is

A wrapper adds Stigg metering and budget checks to the LLM or gateway client you already use. You call stigg.wrap(client) once and use the client it returns. From then on, every model call through that client is:
  1. Checked to make sure the agent has enough credits or metered capacity to perform its task.
  2. Measured when the response arrives, by reading the usage block the provider returned.
  3. Reported to Stigg in the background, attributed to the customer (and optionally the agent) that made it.
The wrapped client takes the same arguments, returns the same types, and raises the same errors as the original. The only addition is a stiggContext field in each call’s parameters, which says which customer the call is for and what to check it against. The SDK removes it before the request is sent, so the provider never sees it. The client you passed to wrap() is left as it was, so calls through it are not metered or checked.
Passing the context on each call lets one wrapped client serve every customer, which is what a server handling many tenants needs. In a process that only ever serves one customer, you can set the context once instead, as the default for every call: stigg.wrap(new Anthropic(), { stiggContext: { customerId, entitlement } }). A call can still override any field. You can wrap any code that calls a model, from a single chat feature or background summarizer to a full agent loop. Each one is metered and checked the same way.

Why use it

Bill for AI usage from the client you already use

Token counts and gateway costs flow into Stigg as usage events. Price them in a plan, draw them down from a credit balance, or pass them through with a margin.

Stop spend before it happens

Most metering tools tell you a budget was exceeded after the fact. Tell the wrapper which credits or metered feature to enforce, and it checks them before each request leaves, so an agent that has run out never reaches the provider.

Bill what each call actually cost

If you route calls through an LLM gateway, the wrapper reports what the gateway actually charged for each call, not an estimate from token counts and a price list. When the gateway falls back to a different model, you see which model served the call and what it cost.

Your AI calls keep working

Usage is reported in the background, so it adds no delay to the call. If a report fails, your user still gets their response, and the error goes to your onError hook.

How it works

  • Recognizes your provider. wrap() detects which provider or gateway the client talks to. If it does not recognize the client, it throws an error instead of returning a client that meters nothing. See Supported providers.
  • Knows who each call is for. Each call says which customer, and optionally which agent, it belongs to, so one wrapped client can serve them all. You can also set a default on wrap(). See StiggContext.
  • Checks only when you ask. Tell the wrapper which credits or metered feature to enforce, and calls without enough left are denied before they reach the provider. Otherwise every call goes through and is only metered. See Gating calls.
  • Handles streaming. Streamed responses are metered when the stream ends, even if your code stops reading early. See Metering usage.

Example use cases

A developer platform charges per million input and output tokens. Each wrapped call reports input_tokens and output_tokens as one event, and two metered features in Stigg sum them for the invoice. Adding a new model changes nothing in your code.
A writing assistant sells monthly credit packs. The wrapper converts tokens into credits with a weights table, checks the balance before each call, and shows the user a top-up prompt when the balance runs out instead of an error page.
A company routes all traffic through OpenRouter. The OpenRouter recipe reports the credits OpenRouter actually charged for each call, so the customer is billed real cost plus margin, even when OpenRouter falls back to a different model.
A product offers free AI usage up to a cap. With the cap modeled as a metered feature that the wrapper enforces, calls past the cap are denied before they cost anything.