Skip to main content
The LLM Gateway is in beta.
The LLM Gateway records every request it routes, so you can monitor what your agents spend and how the gateway’s traffic behaves over time. In the LLM Gateway, two tabs cover this:
  • Usage: See how much LLM cost a workspace has accrued through the gateway, and drill down into the users, keys, models, and other dimensions behind it.
  • Monitoring: View and edit a dashboard of charts on gateway metrics like request volume, latency, error rate, cost, and tokens.
Both tabs require the runs:read-stats and projects:read permissions in the workspace, and a Plus or Enterprise plan. The Monitoring tab also requires charts:read.

Track LLM spend

The Usage tab shows how much LLM cost a workspace has accrued through the gateway. Use it to:
  • Compare spend over time.
  • Identify the user groups, users, API keys, models, providers, and request header values that account for that spend.
  • Attribute that spend for chargebacks.

Group and filter LLM spend

Within the Usage tab, select Breakdown by to group spend by one of the following dimensions:
  • User Group: Attributes spend to the user groups of the user associated with the personal access token that invoked the gateway. A user in several groups counts toward each of them, so user group totals can add up to more than total spend.
  • User: Attributes spend to the user associated with the personal access token that invoked the gateway. Requests made with a workspace or organization-scoped service key appear as Unaffiliated with any user.
  • API key: Attributes spend to the LangSmith API key that invoked the gateway.
  • Model: Attributes spend to the model used for the request.
  • Model Provider: Attributes spend to the provider that served the request, such as OpenAI or Anthropic.
  • Custom Dimension: Attributes spend to the value of an X-Gateway-* request header that your application sends.
When you select Custom Dimension, enter the header name in the field that appears. The field defaults to X-Gateway-Service, and the X-Gateway- prefix is optional. Requests without the header appear under No value. For how to send these headers, see Header-based policies. After you select a dimension, use the adjacent filter to show only the entities you select.

Set the time range and granularity

Use the controls to the chart’s top right to define the period covered by every summary, chart, and table on the page:
  • Time range: Select a preset range from one day to one year, or choose custom dates. Dates and time buckets use UTC.
  • Aggregation granularity: Group spend into hourly, daily, or weekly buckets. The available options depend on the length of the selected time range.

Interpret the spend summary

The cards above the chart summarize spend and tokens for the selected workspace, time range, dimension, and filters:
  • Total Spend: The sum of gateway spend over the selected time range.
  • Hourly, Daily, or Weekly Avg: Total spend divided by the number of time buckets in the selected range.
  • Hourly, Daily, or Weekly Avg / dimension: Average spend per selected entity for each time bucket. When you have not applied an entity filter, this metric uses the top 10 entities by spend.
  • Total Tokens: The number of tokens in requests routed through the gateway over the selected time range.

Analyze the chart and table

The stacked bar chart shows how each entity contributed to spend in every time bucket. Hover over a bar to view the bucket total and the contribution from each visible entity. The table summarizes the same selection with one row per visible entity. Use it to compare:
  • Hourly, Daily, or Weekly Avg: The entity’s total spend divided by the number of time buckets.
  • Spend Share: The percentage of spend attributed to the entity.
  • Total Spend: The entity’s total spend over the selected time range.
To download the table, click the Export CSV icon next to the time range. The file covers every entity for the current breakdown, filters, and time range, including rows the table has not loaded yet, up to 100 entities. Spend from any further entities appears in an Other row, so the file’s totals match the summary cards. To drill down, select a row to open a detailed view of that entity. Select a dimension from Group by to break its spend down further, for example an API key’s spend by user or by custom header. The detailed view has its own filter, time range, and granularity controls, which do not change the controls on the main view.
In the detailed view for a user, an API key, or a custom header value, click View traces to open the Traces tab filtered to that entity’s requests over the detailed view’s time range. For what each trace records, see View LLM Gateway traces.

Attribute spend for chargebacks

A chargeback bills LLM costs back to the customer, tenant, or cost center that incurred them. Because every request routes through the gateway, the Usage tab can split spend along the same lines you bill against. Choose the dimension that matches who you charge:
  • Cost Centers, such as departments, internal groups, or products: Give each group its own service key, then break down by API key. Alternatively, have each group’s applications send a header such as X-Gateway-Cost-Center, then break down by Custom Dimension. If your cost centers match your user groups and each user belongs to only one group, break down by User Group.
  • End customers of your application: Have your backend send a header such as X-Gateway-Customer-Id on each request it makes for a customer, then break down by Custom Dimension. To also cap each customer’s spend, see Cap spend per end customer.
  • Individual users: Have each user call the gateway with their own personal access token, then break down by User.
  • Custom dimensions: To bill against any other attribute, such as environment, have your applications send its value in an X-Gateway-* header, then break down by Custom Dimension.

Visualize gateway metrics

The Monitoring tab in the LLM Gateway is a custom dashboard built on the workspace’s gateway tracing project, where the gateway traces every request. Use it to watch request volume, latency, errors, cost, and token usage across all gateway traffic, and to add charts for the metrics your team tracks. The workspace has one gateway dashboard, which LangSmith creates the first time a user with the charts:create permission opens the tab. Until then, other users see Gateway monitoring isn’t set up yet. The dashboard starts with charts from the same sections as a prebuilt dashboard:
  • Traces: Trace count, latency, and error rate.
  • LLM Calls: LLM call count and latency.
  • Cost & Tokens: Total cost, cost per trace, and input and output tokens.
To add a chart, which requires the charts:create permission:
  1. In the LLM Gateway, select the Monitoring tab.
  2. Click + Chart to open the chart creation pane, or drag Chart to the position you want on the dashboard.
  3. Configure the chart’s metric, filters, grouping, and visualization. Charts on this dashboard read from the gateway project. For each option, see Chart configuration.
  4. Click Create.
To add notes between charts, click or drag + Text instead. To reorder charts or set the dashboard’s time range, see Arrange your dashboard.

See also