@stigg/agent-sdk-js adds gating, metering and budgets to the LLM calls your agents make. See AI agents for setup, and the source on GitHub.
npm also lists versions 1.0.0, 1.0.1, 1.1.0 and 2.0.0. Those are pre-release builds published before the package was re-versioned, and they aren’t supported. Install 0.1.0 or later.
- Updated
@stigg/node-server-sdkto 6.4.3, which stops memory growing with every usage and event report. See the Node.js SDK changelog.
xAI, Together AI, Fireworks AI and DeepSeekSee xAI, Together AI, Fireworks AI and DeepSeek.
- Added:
xaiRecipe,togetherRecipe,fireworksRecipeanddeepseekRecipe, matched on each provider’s API host. They cover chat completions on all four, the Responses API on xAI, Together AI and Fireworks AI, andmessages.createthrough anAnthropicclient on Fireworks AI and DeepSeek. - Changed: a detected client keeps its
openai.*oranthropic.messages.createevent names and adds aproviderdimension ofxai,together,fireworksordeepseek. Pass the recipe atwrap, for examplewrap(client, { recipe: xaiRecipe }), to report underxai.*,together.*,fireworks.*ordeepseek.*instead. - Added: xAI calls report
cost_in_usd_ticks, xAI’s exact price, as an integer at 10,000,000,000 ticks to the dollar. A meter that sums it should divide by that scale, or one of your choosing, rather than price each tick. They also reportreasoning_tokensandnum_sources_used, and on the Responses APInum_server_side_tools_usedand a count per server-side tool, such asweb_search_callsandx_search_calls. - Changed: xAI’s normalized output tokens include reasoning tokens. xAI counts them outside
completion_tokensbut insidetotal_tokens, so output is the total minus the input.completion_tokensis reported as xAI stated it. - Added: Together AI chat calls report
cached_tokenswhen a model states its cache reads flat, asusage.cached_tokens. - Added: DeepSeek chat calls report
reasoning_tokens, and theprompt_cache_hit_tokensandprompt_cache_miss_tokensDeepSeek prices on, whether the response nests them or not. The hit and miss counts add up toprompt_tokens, so price the split or the total, not both. - Note: a streamed
messages.createon Fireworks AI or DeepSeek states its counts on the finalmessage_delta. A stream that ends before then reports what it has and is flaggedincomplete. - Note: Together AI, Fireworks AI and DeepSeek state no price, so their calls report tokens only.
- Added:
vllmRecipe({ baseUrl }), for a self-hosted vLLM server reached through anOpenAIclient. It’s opt-in, because a vLLM server has no hostname to recognize it by. Named atwrap, it reports chat completions and the Responses API asvllm.*, andwraprefuses a client pointed at any other server, so a mistyped URL fails at setup. A vLLM client that doesn’t name the recipe still reports asopenai.*.- Note:
cached_tokensis reported only when the server runs with--enable-prompt-tokens-details.
- Note:
- Changed:
AnthropicBedrockandAnthropicBedrockMantleclients from@anthropic-ai/bedrock-sdkare matched bybedrockRecipe(), on Bedrock runtime and Mantle hosts, including FIPS, China and PrivateLinkvpce-endpoints. They keep theanthropic.messages.createevent name and Anthropic’s counters,total_tokensincluded, and addprovider: bedrock. Passwrap(client, { recipe: bedrockRecipe() })to reportbedrock.messages.createinstead.- Note: a PrivateLink endpoint on a private DNS name of your own isn’t recognized. Name the recipe for it.
- Note:
beta.messageson these clients isn’t governed.
PerplexitySee Perplexity.
- Added:
perplexityRecipe(), matched onapi.perplexity.ai, for Perplexity’s own client and an OpenAI client pointed at its Agent API. It coversresponses.createandchat.completions.create, buffered and streamed. - Added: Perplexity calls report
total_cost, the price Perplexity stated for the call, in micro-dollars by default. It includes per-call tool fees such asweb_search, which token counts don’t cover. SetunitsPerDollarto change the scale.- Note: OpenRouter and LiteLLM report their price as
cost. A meter that prices all three needs both names.
- Note: OpenRouter and LiteLLM report their price as
- Added: the Agent API’s cache counts,
cache_read_input_tokensandcache_creation_input_tokens, and on chat completionsreasoning_tokens,citation_tokensandnum_search_queries. - Changed: a detected Perplexity client keeps its
openai.responses.createandopenai.chat.completions.createevent names and adds aprovider: perplexitydimension, unless the run already setsprovider. Passwrap(client, { recipe: perplexityRecipe() })to report underperplexity.*instead. - Note:
search.create, embeddings,async.chat.completions, batches and browser sessions aren’t gated. Aresponses.createwithbackground: trueis gated but not metered.
- Updated
@stigg/node-server-sdkto 6.4.1, which fixes checks that stayed denied after usage went back under a hard limit. See the Node.js SDK changelog.
TrueFoundry AI Gateway
- Added:
truefoundryRecipe(), for TrueFoundry’s AI Gateway, hosted or self-hosted. OpenAI and Anthropic clients pointed at the gateway report undertruefoundry.*event names, with token counts and the model that served. That model comes from TrueFoundry’sx-tfy-resolved-modelheader, so a call the gateway sent to a fallback model reports the one that answered. For a self-hosted gateway, pass its base URL withwrap(client, { recipe: truefoundryRecipe({ baseUrl }) }).stigg.wrapFetchtakes the recipe too. - Changed: OpenAI and Anthropic clients whose base URL is on
truefoundry.ai,truefoundry.cloudortruefoundry.comnow report astruefoundry.*, where they previously reported asopenai.*oranthropic.*. - Note: TrueFoundry’s Gemini, Bedrock and Azure OpenAI passthroughs aren’t covered.
Vercel AI SDKSee Tools.
- Added: paid tools.
stiggVercelMiddleware()takes the sametoolsoption as the LangChain handler, andmiddleware.tools()wraps each listed tool’sexecute. A tool is checked before it runs and reported after it succeeds, as the model step that asked for it. A denied tool doesn’t run, and the model gets a short error as its result. - Added: a tool with
needsApprovalnames its customer in its own context,toolsContextinai7 orexperimental_contextinai6.
AI gatewaysSee agentgateway and A gateway you call over HTTP.
- Added:
agentgatewayRecipe(), for the open-source agentgateway and the builds on it, Solo.io’s enterprise edition and Gloo AI Gateway. Calls report underagentgateway.*event names, with token counts and the model that served. Pass the gateway’sbaseUrl, which Solo.io and Gloo builds require. - Added:
stigg.wrapFetch({ baseUrl, recipe }), which returns afetchthat checks and meters plain HTTP calls to a gateway, the same way a wrapped client does. Any recipe for OpenAI’s or Anthropic’s format works.
- Added:
register()with abudgetthat sets nolimitgives an agent with no budget yet one with no limit, resetting monthly unless you pass acadence. Its usage is tracked without a cap, and an existing budget, including a limit set in the Stigg app, is left as it is. See Observe-only rollout.
- Added: the
audroption. Passaudr: { client, environment }to the constructor and the SDK also writes an AUDR record (Agent Usage Detail Record) for every model call it meters, to your own@openaudr/audrclient. Off by default.@openaudr/audris an optional peer dependency, at>=0.2.0 <0.3.
Vercel AI SDKSee Vercel AI SDK.
- Added:
stiggVercelMiddleware(), a language model middleware for the AI SDK’swrapLanguageModel. Each model call ofgenerateText,streamTextor an agent’s loop is checked before it runs, and its usage is reported after, as the agent in the middleware’sstiggContext. Works withai6 and 7. - Added: a call names its customer in
providerOptions.stigg, which is removed before the provider sees the call. - Added: a streamed call is reported once, when the stream ends. A stream the user stops is reported from an estimate of its output and isn’t counted as a metering failure. A timeout, a failed stream, or a model that reports no usage, streamed or not, is estimated and counted as one.
Google ADKSee Google ADK.
- Added:
StiggAdkPlugin, from the new@stigg/agent-sdk-js/adkentry point. Add it to a Runner’spluginsto govern every agent the Runner runs. Each model call and tool call is checked before it runs, and its usage is reported after it succeeds, as the agent ADK runs it under.@google/adk2.x is an optional peer dependency. - Added:
stepContext, a function that returns each step’sstiggContext, usually the customer. ADK has no per-run metadata, so this is where the customer comes from. Resolve it from your server’s login, never from a client-supplieduserIdor state. - Added:
onRefusal. ADK doesn’t let a plugin throw, so a refused model call returns an answer instead. Return{ transferTo: 'agent-name' }to hand the turn to another agent, or nothing for an error response witherrorCode: 'STIGG_ACCESS_DENIED'. A refused tool returns a short error as its result, and the model carries on without it. - Added:
plugin.denialOf(event), which returns the decision behind a refused step’s event. - Put the plugin first in
plugins. ADK stops at the first plugin that answers a step, so a plugin before it can hide that step from Stigg.
LangChain and LangGraphSee LangChain and LangGraph.
- ⚠️ Changed: a run names its customer with
metadata: { stiggContext: { customerId } }.metadata.stiggCustomerIdstill works, but it’s deprecated and logs a warning. A run that names two different customers, one in each field, throws. - Added: on
invoke, the run’sstiggContextcan setcustomerIdandcorrelationId. Any other field throws, because a client can write that metadata. A node can set other fields in its own config’smetadata.stiggContext, and they apply to that node’s steps. - ⚠️ Changed:
stigg.middleware()takes a step’s contexts asstiggContexts: [{ customerId }], outermost first.StepAttribution.customerIdwas removed, and a step that still passes it throws.
- Added:
budget.scopeonstigg.register(), a list of entity IDs that narrows a budget to the calls attributed to all of them. Use it for a budget per value of a dimension, such as one per model. Each scope is a separate budget, so register once per scope, and register the agent’s whole budget too. - Added:
defaultPlanIdonstigg.register(). A customer Stigg doesn’t know yet is created on that plan before the agent is registered. Without it, registering an agent for an unknown customer fails.
- ⚠️ Changed: a
stiggContextfield of the wrong type throws. For example, a non-stringagentId,defaultPlanIdor dimension value, or ausageMapperthat isn’t a function. These were previously passed through.
LangChain and LangGraph
- Fixed: each step’s usage is reported as the nearest agent above it in LangChain’s run tree, not to the agent named in the run’s
lc_agent_namemetadata. Unnamed sub-agents inherit that metadata, and a caller can set it, so a step could count against the wrong agent or an agent the caller chose. - Added:
rootAgentonStiggLangChainCallbackHandler, the agent the top-level run always counts as. Without it, the caller’srunNamedecides. - Fixed: a class-based tool such as
TavilySearch, which starts without a name, is named from the model’s tool call or from its result. A priced tool’s usage is now reported even when its name arrives only with its result, and the SDK logs once that it ran unchecked. - Fixed: completion models, which aren’t chat models, are metered from LangChain’s
llmOutput.tokenUsage. A streamed completion reports no usage, and that goes toonErrorrather than being reported as zero.
- Fixed: a rate-limited or timed-out provisioning call no longer locks the customer out until the process restarts. Only unreachable, rate-limited and timed-out calls are retried, after 30 seconds. Every other refusal is final.
LangChain and LangGraphSee LangChain and LangGraph.
- Added:
StiggLangChainCallbackHandler, from the new@stigg/agent-sdk-js/langchainentry point. Pass it in a run’scallbacksto govern a LangChaincreateAgentgraph or a hand-built LangGraphStateGraph. Each model call and governed tool call is checked before it runs, and its usage is reported after it succeeds, as the agent that made it.@langchain/core1.x is an optional peer dependency. - Added:
stigg.middleware({ stiggContext, tools, hooks, agents }), the framework-neutral logic behind the handler, for wiring other orchestrators. - Added: the run’s customer comes from
metadata.stiggCustomerId, or from a defaultcustomerIdinstiggContext. A run with neither is refused before its first step. SetstiggCustomerIdon your server, because it wins over the default. - Added: per-tool governance in
tools, keyed by tool name, with'*'for every tool not named:- An entitlement: checked, then reported as one unit per call.
{ entitlement, usage }: checked, then reported through a usage mapper over the call’s input and output.{ usage }: reported, never checked.false: left ungoverned.
- Added:
agents, which gives each agent in the graph its ownstiggContextand tools, laid over the shared ones. Point an agent’sagentIdat an entity registered withstigg.register(), and its steps are checked and reported against that entity’s budget.
- Added: OpenTelemetry spans (
stigg.checkandstigg.ingest, with GenAI attribute names) from the middleware and the LangChain handler, so tracing tools such as Langfuse and LangSmith see Stigg’s decisions, including refusals.@opentelemetry/apiis an optional peer dependency, and without it no spans are emitted. Wrapped clients emit no spans. - Changed:
isAccessDeniedfinds anAccessDeniedErroranywhere in an error’s cause chain or inside anAggregateError. - Added:
HookContextcarries the agent and tool a hook fired for.
- Added:
defaultPlanIdinstiggContext. A customer Stigg doesn’t know yet is created on that plan before their first check or report. An existing customer is left untouched.- Provisioning runs once per customer per process.
- If Stigg is unreachable, the failure goes to
onErrorand provisioning is retried on the next call. A check for a customer that couldn’t be provisioned followscheckErrorAction. - If Stigg refuses, for example because the plan doesn’t exist, the refusal is reported once and not retried.
- Fixed: the npm package links to the public stigg-agent-sdk-ts repository. It previously linked to a private one.
- Fixed: the examples and
.env.templateuseSTIGG_SERVER_API_KEY, the variable the SDK reads. They previously usedSTIGG_API_KEY, which the SDK ignores. The examples still accept the old name.
- Fixed: a stream split with
tee()is metered. Previously onlyfor awaitwas metered, so a teed Anthropic or OpenAI-compatible stream moved no budget. - ⚠️ Changed:
wrapthrows whenstiggContextsets anidempotencyKey. One key shared by every call deduplicated them all down to the first, so later calls moved no budget. SetidempotencyKeyper call instead. - ⚠️ Changed: a call throws when its
customerIdis empty or blank. It previously fell back to the client’s default customer. A call with nocustomerIdstill uses the default. - Fixed:
apiKeyis no longer enumerable onstigg.config, so logging or serializing the client no longer prints the key.
Databricks
- Added:
databricksRecipe, matched automatically on a Databricks workspace’s/serving-endpointsor/ai-gateway/mlflow/v1URL. It covers both anOpenAIclient pointed at the workspace and Databricks’ own@databricks/sdk-modelservingqueryclient, and emitsdatabricks.chat.completions.create,databricks.responses.createanddatabricks.query. - Added: the model that answered is recorded as a dimension. On Databricks the
modelyou send is a serving endpoint name, so the response is the only place the real model appears. - Added:
databricksExternalRecipefor serving endpoints configured as external models, where the upstream provider charges you instead of Databricks. It emitsdatabricks-external.*events. It’s opt-in, because the two routes look identical from the client:stigg.wrap(client, { recipe: databricksExternalRecipe() }). - Neither recipe reports a
costmetric, because Databricks doesn’t state a price on any response. A workspace on a custom domain needs its base URL passed in:databricksRecipe({ baseUrl }).
- Added:
cloudflareRecipe, matched automatically for both Workers AI (api.cloudflare.com/client/v4/accounts/<id>/ai/v1) and AI Gateway (gateway.ai.cloudflare.com). It covers anOpenAIclient and thecloudflarepackage’s ownai.run, and emitscloudflare.chat.completions.create,cloudflare.responses.create,cloudflare.messages.createandcloudflare.ai.run. - Reports token counts only. Cloudflare doesn’t state a price or Neuron count on any response, so there’s no
costmetric. - On AI Gateway, the model that served and the
cf_aig_log_idare recorded as dimensions, and a cache hit isn’t metered because no one was charged for it. - Known limitation: a streamed
ai.runcall is gated but not metered, because Cloudflare returns raw SSE bytes for it.
Initial release.Core
- Added:
StiggAgentSDK. Pass an API key, or one options object for the base URL, ingest mode and hooks. - Added:
stigg.wrap(client, { stiggContext }), which returns a copy of a vendor client whose calls are checked and metered. The context names the customer, the agent the call is attributed to, and an optionalentitlement. Naming an entitlement turns on gating. Without one, calls are metered but never refused. Any call can override the context in its own parameters, so one wrapped client can serve every customer. - Added:
stigg.register()andstigg.deregister()to create an agent entity with a budget and a parent. Both are optional. Without them, checks and usage apply to the customer. - Added: a refused call throws
AccessDeniedError. Pass it tostigg.denial(err)to get the decision, including which entity blocked the call and how to fix it. - Added:
ingest: 'async' | 'sync'. Usage is reported as raw events by default. A metric named after a credit currency draws the credit balance directly. Metering failures go to theonErrorhook and never break the call. - Added:
unitsPerTokensandweightedMetricsfor pricing token counts in code. Stigg recommends reporting raw token counts and converting them in Stigg instead.
- Added: Anthropic, OpenAI (Chat Completions and Responses), Google Gemini (models and chats), Groq, Mistral, Ollama and TypeSafe.
- Added: any other OpenAI-compatible endpoint, metered under
openai.*events.
- Added: OpenRouter, through an
OpenAIclient or OpenRouter’s own@openrouter/sdk. Reportscostand the model that served. - Added: LiteLLM. Reports
costfrom the response header and the model that served. - Added: Amazon Bedrock. Reports tokens only, because Bedrock doesn’t state a price.
- Added: a gateway you operate yourself. The wrapped client sends attribution as
x-stigg-*headers, and your gateway reports usage withstigg.ingestFromHeaders(...). This path meters but can’t refuse calls.