# Track Vercel AI Gateway costs by user and project

An AI Gateway request already has a model, token usage and cost. A trace drain can deliver those fields to Veqen without wrapping each call in application code. Use one recording path per request so gateway exports and SDK instrumentation do not double count the same work.

## Set up a drain

Create an **ingest** key in [Veqen API keys](https://veqen-app.com/app/settings/keys). In Vercel, configure an AI Gateway trace drain with this HTTPS destination and authentication header:

```text
Endpoint: https://veqen-app.com/v1/otlp/v1/traces
Authorization: Bearer <your-veqen-ingest-key>
Encoding: OTLP/HTTP JSON
```

Vercel's drain feature is available on Pro and Enterprise, and drain usage can carry charges. Review your existing plan and Vercel's pricing before enabling it. Veqen does not require a paid plan to receive calls within its Free allowance. See [Vercel's trace-drain reference](https://vercel.com/docs/ai-gateway/observability-and-spend/trace-drains) for current dashboard setup and pricing.

## Accounting and attribution

Veqen records the root span's token usage and preserves a USD `vercel.ai_gateway.cost.total` as **reported** cost. It maps `vercel.ai_gateway.user.id` to user, `vercel.project.id` to project, and `vercel.ai_gateway.environment` to environment. Explicit `veqen.*` allocation fields take priority. Provider-attempt spans without token usage are ignored.

The reported amount is deliberately kept separate from a price-book estimate. Gateway discounts, credits, routing and other billing terms can make list-price multiplication differ from a reported charge. Only a reconciliation against billing evidence can establish agreement with an invoice. A non-USD charge is not silently converted into dollars; without a supported USD charge, Veqen prices the usage from its price book or your custom rates.

## Verify delivery

Start with a test project and one short model request. Check the drain's delivery status, then filter Veqen by that project's identifier. Verify the model, input/output usage, user and reported amount. A repeated export of the identical span is recorded once. Different spans for the same underlying call are different records, so avoid a second usage-bearing wrapper span.

The receiver returns OTLP partial-success errors for invalid counts, unsupported timestamps or plan-limit drops. A successful connection test alone does not prove that a real request was recorded; verify the ledger row too.

## Keep content private

Veqen retains allowlisted usage and allocation fields and discards arbitrary attributes. Vercel documents its gateway traces as excluding prompt and completion content. Keep additional exporter instrumentation under the same policy, and use pseudonymous user identifiers. A user identifier is sufficient for cost attribution; a customer's email address or message text is unnecessary.

For direct AI SDK instrumentation, see [OpenTelemetry](/docs/opentelemetry). To attach a customer identifier at your application boundary, see [cost per customer](/guides/cost-per-customer). Telemetry records completed usage; it is not a pre-call spending limit.
