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

# agentgateway

> Wrap a client for your agentgateway, or Solo.io's enterprise build, to meter and gate calls, with the model that actually served each one.

## Set up

[agentgateway](https://agentgateway.dev) is an open-source AI gateway that runs in your own cluster. Solo.io's enterprise edition and Gloo AI Gateway are builds of the same project, so the same recipe covers all three. The gateway has no public address for the SDK to recognize, so pass the agentgateway recipe with your gateway's base URL:

```typescript theme={null}
import OpenAI from 'openai';
import { agentgatewayRecipe } from '@stigg/agent-sdk-js';

const gateway = stigg.wrap(
  new OpenAI({ baseURL: 'http://agentgateway.internal:8080/v1', apiKey: process.env.AGENTGATEWAY_KEY }),
  { recipe: agentgatewayRecipe({ baseUrl: 'http://agentgateway.internal:8080/v1' }) },
);

await gateway.chat.completions.create({
  model: 'gpt-5-mini',   // a model name your gateway exposes
  messages,
  stiggContext: { customerId: 'customer-acme', entitlement: { currencyId: 'credits' } },
});
```

The gateway also answers on Anthropic's Messages API. Wrap an `Anthropic` client pointed at the gateway's root, with the same recipe, and its calls are governed the same way:

```typescript theme={null}
import Anthropic from '@anthropic-ai/sdk';

const gateway = stigg.wrap(
  new Anthropic({ baseURL: 'http://agentgateway.internal:8080', apiKey: process.env.AGENTGATEWAY_KEY }),
  { recipe: agentgatewayRecipe({ baseUrl: 'http://agentgateway.internal:8080' }) },
);
```

To call the gateway with plain HTTP instead of a client, see [A gateway you call over HTTP](https://docs.stigg.io/documentation/ai-agents/usage-metering.md#a-gateway-you-call-over-http).

* **Always pass `baseUrl` for Solo.io and Gloo builds.** Without it, the SDK recognizes the gateway only when a part of its hostname is `agentgateway` or starts with `agentgateway-`, as in a default install's `agentgateway-proxy.agentgateway-system.svc`.
* **Tell deployments apart with a dimension.** Every build reports under the same `agentgateway.*` event names. To separate Solo.io traffic from another agentgateway deployment, add a dimension such as `gateway: 'solo-enterprise'` to the `stiggContext`.

### `agentgatewayRecipe` options

| Option | Default | Description |
| - | - | - |
| `baseUrl` | | Your gateway's URL, used to recognize the client. Required for Solo.io and Gloo builds. |
| `modelDimension` | `model` | The dimension the model that served the call is reported under. |
| `estimate` | `() => 1` | The requested usage of the check before the call. See [Requested usage](https://docs.stigg.io/documentation/ai-agents/access-enforcement.md#requested-usage). |

## What is reported

agentgateway is a gateway you host: one endpoint in front of many model providers, answering in OpenAI's format and in Anthropic's. Each route reports the token counts of the format it answered in. The gateway puts no price on its responses, so there is no `cost` metric. Each provider charges you directly for what its models served.

| Method | Event name |
| - | - |
| `chat.completions.create` | `agentgateway.chat.completions.create` |
| `responses.create` | `agentgateway.responses.create` |
| `messages.create`, `messages.stream` | `agentgateway.messages.create` |

* **Chat Completions and Responses** report the same metrics as [OpenAI](https://docs.stigg.io/documentation/ai-agents/providers/openai.md#what-is-reported).
* **Messages** reports the same metrics as [Anthropic](https://docs.stigg.io/documentation/ai-agents/providers/anthropic.md#what-is-reported).

Each event also carries:

| Reported | What it is |
| - | - |
| `model` dimension | The model that served the call. The gateway can resolve the model you asked for to another, through an alias, a provider prefix or a failover group. See [Routing drift](https://docs.stigg.io/documentation/ai-agents/usage-metering.md#routing-drift). |

> [!TIP]
>
> A streamed Chat Completions call carries usage only when the request sets `stream_options: { include_usage: true }`. Without it, a streamed call reports nothing.

Every usage field the gateway returns is also included, with a `raw.` prefix. See [How usage is reported](https://docs.stigg.io/documentation/ai-agents/usage-metering.md#how-usage-is-reported).


## Related topics

- [JavaScript](https://docs.stigg.io/api-and-sdks/changelog/agent-sdk/javascript.md)
- [Providers and frameworks](https://docs.stigg.io/documentation/ai-agents/providers/overview.md)
- [Agent SDK](https://docs.stigg.io/api-and-sdks/references/sdk/backend/graphql/agent-sdk.md)
- [Usage metering](https://docs.stigg.io/documentation/ai-agents/usage-metering.md)


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