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

What it is

The Stigg Agent SDK adds Stigg 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 goes through three steps:
  1. Meter usage. The tokens, and the cost where a gateway reports one, are read from each response and reported to Stigg, straight from the LLM provider or gateway you call.
  2. Enforce access. Before a call leaves your process, the SDK checks that the agent has enough credits or metered capacity to perform its task, so an agent that has run out never reaches the provider.
  3. Govern usage. Each agent gets its own identity and budget, under teams and orgs, so you know which agent spent what and can stop one without stopping the rest.
The wrapped client takes the same arguments, returns the same types, and raises the same errors as the original. The client you passed to wrap() is left as it was, so calls through it are not metered or checked.

stigg-agent-sdk-ts on GitHub

The Agent SDK is open source under the MIT license. Browse the source, run the examples, or contribute a recipe for a new vendor.
The stiggContext tells Stigg who the call is for. The SDK removes it before the request is sent, so the provider never sees it. You can pass the context in two places:
  • On each call, as above. One wrapped client then serves every customer, which is what a server handling many customers needs.
  • Once, on wrap(), as the default for every call through that client: stigg.wrap(new Anthropic(), { stiggContext: { customerId, entitlement } }). Use this in a process that only serves one customer. A stiggContext on a call still takes precedence over the default for the fields it sets.
Either way, every call must end up with a customerId.

Why use it

Meter 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.

Charge for 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 Usage metering.
  • 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 Access enforcement.
  • Handles streaming. Streamed responses are metered when the stream ends, even if your code stops reading early. See Usage metering.

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 charged 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.
A customer runs a support agent, a research agent and a coding agent from one credit balance. Each agent gets its own monthly budget, so when the research agent loops on a bad prompt, it is stopped at its own budget and the other two keep serving users.