> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript

`@stigg/agent-sdk-js` adds gating, metering and budgets to the LLM calls your agents make. See [AI agents](https://docs.stigg.io/documentation/ai-agents/overview.md) for setup, and the [source on GitHub](https://github.com/stiggio/stigg-agent-sdk-ts).

> [!NOTE]
>
> 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.

**0.7.14**

2026-11-08

**Perplexity**

See [Perplexity](https://docs.stigg.io/documentation/ai-agents/providers/perplexity.md).

* Added: `perplexityRecipe()`, matched on `api.perplexity.ai`, for Perplexity's own client and an OpenAI client pointed at its Agent API. It covers `responses.create` and `chat.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 as `web_search`, which token counts don't cover. Set `unitsPerDollar` to change the scale.
  * Note: OpenRouter and LiteLLM report their price as `cost`. A meter that prices all three needs both names.
* Added: the Agent API's cache counts, `cache_read_input_tokens` and `cache_creation_input_tokens`, and on chat completions `reasoning_tokens`, `citation_tokens` and `num_search_queries`.
* Changed: a detected Perplexity client keeps its `openai.responses.create` and `openai.chat.completions.create` event names and adds a `provider: perplexity` dimension, unless the run already sets `provider`. Pass `wrap(client, { recipe: perplexityRecipe() })` to report under `perplexity.*` instead.
* Note: `search.create`, embeddings, `async.chat.completions`, batches and browser sessions aren't gated. A `responses.create` with `background: true` is gated but not metered.

**0.7.13**

2026-11-08

* Updated `@stigg/node-server-sdk` to 6.4.1, which fixes checks that stayed denied after usage went back under a hard limit. See the [Node.js SDK changelog](https://docs.stigg.io/api-and-sdks/changelog/backend-graphql/node.md#6-4-1).

**0.7.9**

2026-11-04

**TrueFoundry AI Gateway**

* Added: `truefoundryRecipe()`, for TrueFoundry's AI Gateway, hosted or self-hosted. OpenAI and Anthropic clients pointed at the gateway report under `truefoundry.*` event names, with token counts and the model that served. That model comes from TrueFoundry's `x-tfy-resolved-model` header, so a call the gateway sent to a fallback model reports the one that answered. For a self-hosted gateway, pass its base URL with `wrap(client, { recipe: truefoundryRecipe({ baseUrl }) })`. `stigg.wrapFetch` takes the recipe too.
* Changed: OpenAI and Anthropic clients whose base URL is on `truefoundry.ai`, `truefoundry.cloud` or `truefoundry.com` now report as `truefoundry.*`, where they previously reported as `openai.*` or `anthropic.*`.
* Note: TrueFoundry's Gemini, Bedrock and Azure OpenAI passthroughs aren't covered.

**0.7.8**

2026-11-04

**Vercel AI SDK**

See [Tools](https://docs.stigg.io/documentation/ai-agents/orchestrators/vercel-ai-sdk.md#tools).

* Added: paid tools. `stiggVercelMiddleware()` takes the same `tools` option as the LangChain handler, and `middleware.tools()` wraps each listed tool's `execute`. 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 `needsApproval` names its customer in its own context, `toolsContext` in `ai` 7 or `experimental_context` in `ai` 6.

**0.7.7**

2026-11-04

**AI gateways**

See [agentgateway](https://docs.stigg.io/documentation/ai-agents/providers/agentgateway.md) and [A gateway you call over HTTP](https://docs.stigg.io/documentation/ai-agents/usage-metering.md#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 under `agentgateway.*` event names, with token counts and the model that served. Pass the gateway's `baseUrl`, which Solo.io and Gloo builds require.
* Added: `stigg.wrapFetch({ baseUrl, recipe })`, which returns a `fetch` that 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.

**Usage governance**

* Added: `register()` with a `budget` that sets no `limit` gives an agent with no budget yet one with no limit, resetting monthly unless you pass a `cadence`. 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](https://docs.stigg.io/documentation/ai-agents/usage-governance.md#observe-only-rollout).

**0.7.4**

2026-11-03

**Vercel AI SDK**

See [Vercel AI SDK](https://docs.stigg.io/documentation/ai-agents/orchestrators/vercel-ai-sdk.md).

* Added: `stiggVercelMiddleware()`, a language model middleware for the AI SDK's `wrapLanguageModel`. Each model call of `generateText`, `streamText` or an agent's loop is checked before it runs, and its usage is reported after, as the agent in the middleware's `stiggContext`. Works with `ai` 6 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.

**0.7.0**

2026-10-29

**Google ADK**

See [Google ADK](https://docs.stigg.io/documentation/ai-agents/orchestrators/google-adk.md).

* Added: `StiggAdkPlugin`, from the new `@stigg/agent-sdk-js/adk` entry point. Add it to a Runner's `plugins` to 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/adk` 2.x is an optional peer dependency.
* Added: `stepContext`, a function that returns each step's `stiggContext`, 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-supplied `userId` or 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 with `errorCode: '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.

**0.6.0**

2026-10-29

**LangChain and LangGraph**

See [LangChain and LangGraph](https://docs.stigg.io/documentation/ai-agents/orchestrators/langchain.md).

* ⚠️ Changed: a run names its customer with `metadata: { stiggContext: { customerId } }`. `metadata.stiggCustomerId` still 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's `stiggContext` can set `customerId` and `correlationId`. Any other field throws, because a client can write that metadata. A node can set other fields in its own config's `metadata.stiggContext`, and they apply to that node's steps.
* ⚠️ Changed: `stigg.middleware()` takes a step's contexts as `stiggContexts: [{ customerId }]`, outermost first. `StepAttribution.customerId` was removed, and a step that still passes it throws.

**Agent budgets**

* Added: `budget.scope` on `stigg.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: `defaultPlanId` on `stigg.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.

**Other changes**

* ⚠️ Changed: a `stiggContext` field of the wrong type throws. For example, a non-string `agentId`, `defaultPlanId` or dimension value, or a `usageMapper` that isn't a function. These were previously passed through.

**0.5.1**

2026-10-26

**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_name` metadata. 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: `rootAgent` on `StiggLangChainCallbackHandler`, the agent the top-level run always counts as. Without it, the caller's `runName` decides.
* 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 to `onError` rather than being reported as zero.

**Customer provisioning**

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

**0.5.0**

2026-10-26

**LangChain and LangGraph**

See [LangChain and LangGraph](https://docs.stigg.io/documentation/ai-agents/orchestrators/langchain.md).

* Added: `StiggLangChainCallbackHandler`, from the new `@stigg/agent-sdk-js/langchain` entry point. Pass it in a run's `callbacks` to govern a LangChain `createAgent` graph or a hand-built LangGraph `StateGraph`. 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/core` 1.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 default `customerId` in `stiggContext`. A run with neither is refused before its first step. Set `stiggCustomerId` on 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 own `stiggContext` and tools, laid over the shared ones. Point an agent's `agentId` at an entity registered with `stigg.register()`, and its steps are checked and reported against that entity's budget.

**Other changes**

* Added: OpenTelemetry spans (`stigg.check` and `stigg.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/api` is an optional peer dependency, and without it no spans are emitted. Wrapped clients emit no spans.
* Changed: `isAccessDenied` finds an `AccessDeniedError` anywhere in an error's cause chain or inside an `AggregateError`.
* Added: `HookContext` carries the agent and tool a hook fired for.

**0.4.0**

2026-10-21

* Added: `defaultPlanId` in `stiggContext`. 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 `onError` and provisioning is retried on the next call. A check for a customer that couldn't be provisioned follows `checkErrorAction`.
  * If Stigg refuses, for example because the plan doesn't exist, the refusal is reported once and not retried.

**0.3.2**

2026-10-19

* Fixed: the npm package links to the public [stigg-agent-sdk-ts](https://github.com/stiggio/stigg-agent-sdk-ts) repository. It previously linked to a private one.
* Fixed: the examples and `.env.template` use `STIGG_SERVER_API_KEY`, the variable the SDK reads. They previously used `STIGG_API_KEY`, which the SDK ignores. The examples still accept the old name.

**0.3.1**

2026-10-19

* Fixed: a stream split with `tee()` is metered. Previously only `for await` was metered, so a teed Anthropic or OpenAI-compatible stream moved no budget.
* ⚠️ Changed: `wrap` throws when `stiggContext` sets an `idempotencyKey`. One key shared by every call deduplicated them all down to the first, so later calls moved no budget. Set `idempotencyKey` per call instead.
* ⚠️ Changed: a call throws when its `customerId` is empty or blank. It previously fell back to the client's default customer. A call with no `customerId` still uses the default.
* Fixed: `apiKey` is no longer enumerable on `stigg.config`, so logging or serializing the client no longer prints the key.

**0.3.0**

2026-10-19

* Updated `@stigg/node-server-sdk` to 6.2.0. No change to the Agent SDK API.

**0.2.0**

2026-10-14

**Databricks**

* Added: `databricksRecipe`, matched automatically on a Databricks workspace's `/serving-endpoints` or `/ai-gateway/mlflow/v1` URL. It covers both an `OpenAI` client pointed at the workspace and Databricks' own `@databricks/sdk-modelservingquery` client, and emits `databricks.chat.completions.create`, `databricks.responses.create` and `databricks.query`.
* Added: the model that answered is recorded as a dimension. On Databricks the `model` you send is a serving endpoint name, so the response is the only place the real model appears.
* Added: `databricksExternalRecipe` for serving endpoints configured as external models, where the upstream provider charges you instead of Databricks. It emits `databricks-external.*` events. It's opt-in, because the two routes look identical from the client: `stigg.wrap(client, { recipe: databricksExternalRecipe() })`.
* Neither recipe reports a `cost` metric, because Databricks doesn't state a price on any response. A workspace on a custom domain needs its base URL passed in: `databricksRecipe({ baseUrl })`.

**Cloudflare**

* 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 an `OpenAI` client and the `cloudflare` package's own `ai.run`, and emits `cloudflare.chat.completions.create`, `cloudflare.responses.create`, `cloudflare.messages.create` and `cloudflare.ai.run`.
* Reports token counts only. Cloudflare doesn't state a price or Neuron count on any response, so there's no `cost` metric.
* On AI Gateway, the model that served and the `cf_aig_log_id` are recorded as dimensions, and a cache hit isn't metered because no one was charged for it.
* Known limitation: a streamed `ai.run` call is gated but not metered, because Cloudflare returns raw SSE bytes for it.

**0.1.0**

2026-10-13

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 optional `entitlement`. 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()` and `stigg.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 to `stigg.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 the `onError` hook and never break the call.
* Added: `unitsPerTokens` and `weightedMetrics` for pricing token counts in code. Stigg recommends reporting raw token counts and converting them in Stigg instead.

**Providers**

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

**Gateways**

* Added: OpenRouter, through an `OpenAI` client or OpenRouter's own `@openrouter/sdk`. Reports `cost` and the model that served.
* Added: LiteLLM. Reports `cost` from 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 with `stigg.ingestFromHeaders(...)`. This path meters but can't refuse calls.


## Related topics

- [JavaScript](https://docs.stigg.io/api-and-sdks/integration/frontend/javascript.md)
- [JavaScript SDK](https://docs.stigg.io/api-and-sdks/references/sdk/frontend/javascript-rest.md)
- [Get started with the SDKs](https://docs.stigg.io/documentation/getting-started/get-started-with-sdks.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.