Skip to content
Docs

AI Gateway Trace Drains

AI Gateway produces an OpenTelemetry trace for every request it handles. A trace drain forwards those traces to any OTLP/HTTP-compatible endpoint, such as your own collector or a native integration from the Marketplace, so you can inspect latency, token usage, and provider failover in the observability tool you already use.

Trace Drains are available on Enterprise and Pro plans

For the underlying drain configuration and OTLP formats, see the Drains documentation.

  1. From the Vercel dashboard, go to Team Settings > Drains and click Add Drain. You can also use a native integration that configures the endpoint for you.

  2. Configure the destination to send traces to your OTLP/HTTP collector.

  3. Set AI_GATEWAY_API_KEY to your AI Gateway API key, then run:

    Terminal
    curl -X POST "https://ai-gateway.vercel.sh/v1/responses" \
      -H "Authorization: Bearer $AI_GATEWAY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "openai/gpt-6-astra",
        "input": "Write a one-sentence bedtime story."
      }'

    Once the drain is active, AI Gateway forwards the resulting trace based on your sampling rules.

Native integrations that support trace drains include:

  • Braintrust: AI evaluation, monitoring, and observability
  • Dash0: OpenTelemetry-native logs, traces, and metrics
  • Kubiks: Logs, traces, dashboards, and alerts
  • Sentry: Error and performance monitoring
  • Statsig: Feature flags, experiments, and analytics

The Native Integrations section of the drain creation flow always shows the current list of integrations that support trace drains.

Trace drains use OTLP/HTTP exclusively and don't support OTLP/gRPC endpoints (typically port 4317). Make sure your endpoint accepts OTLP/HTTP requests (typically port 4318, path /v1/traces).

AI Gateway Traces bills on two meters: the number of trace events delivered to your drains, and the volume of trace data transferred (egress). Vercel bills the two meters separately.

ResourcePrice
AI Gateway Traces$0.05 per 1,000 traces
Trace egress$0.50 per 1 GB

Pro plans don't include an allowance for either meter. Charges begin with the first delivered trace and first byte of trace egress.

Vercel applies these billing rules:

  • Each request counts as a single trace event for each drain that delivers it, even when the request fails over across multiple providers
  • A trace event is counted only when a delivered payload contains the request's root span
  • Failed deliveries don't incur a trace-event charge

Provider attempts appear as separate spans within the trace, but they don't add trace events.

Sampling rules control the percentage of traces forwarded to each drain. A higher sampling rate can increase both trace-event and egress charges.

You can track both meters on the Usage dashboard under Drains → AI Gateway Traces.

To stop future charges, pause or delete the trace drain.

Each AI Gateway request produces a single trace with the resource attributes service.name: ai-gateway and service.namespace: vercel. Within that trace, AI Gateway emits these spans:

Span nameKindDescription
<operation> <model> (root)ServerThe full request: model, token usage, cost, latency, and response status
vercel.ai_gateway.routingInternalModel resolution and provider ordering, including any custom provider filters
vercel.ai_gateway.model_attempt <model>InternalOne per model attempt, when fallback models run
<model> (<provider>)ClientOne per upstream provider call, so a request that fails over shows every attempt in order

The root span's <operation> reflects the request type: chat, embeddings, generate_content for image and video models, or retrieval for reranking.

Span attributes use two namespaces: gen_ai.* follows the OpenTelemetry GenAI semantic conventions, and vercel.ai_gateway.* carries gateway-specific fields. Attributes are omitted when they don't apply to a request. See the Trace Drains reference for the OTLP envelope and JSON/Protobuf formats.

AI Gateway traces contain request metadata, but they don't include prompt or completion content.

Standard gen_ai.* attributes describe the model interaction:

AttributeTypeDescription
gen_ai.operation.namestringThe operation type: chat, embeddings, generate_content, or retrieval
gen_ai.provider.namestringThe provider, mapped to OTel well-known values (for example, aws.bedrock)
gen_ai.request.modelstringThe model slug the client requested
gen_ai.response.modelstringThe resolved canonical model that served the request
gen_ai.response.finish_reasonsstring[]Why generation stopped
gen_ai.request.streambooleanWhether the response streamed
gen_ai.response.time_to_first_chunkdoubleTime to first token, in seconds
gen_ai.usage.input_tokensintInput tokens
gen_ai.usage.output_tokensintOutput tokens
gen_ai.usage.reasoning.output_tokensintReasoning tokens
gen_ai.usage.cache_creation.input_tokensintInput tokens written to the provider's prompt cache
gen_ai.usage.cache_read.input_tokensintInput tokens served from the provider's prompt cache
http.response.status_codeintThe gateway's response status

Gateway-specific vercel.ai_gateway.* attributes carry routing, billing, and attribution detail:

AI Gateway records project and deployment IDs as span attributes named vercel.project.id and vercel.deployment.id. These differ from the vercel.projectId and vercel.deploymentId resource attributes on Vercel deployment traces.

AttributeTypeDescription
vercel.ai_gateway.providerstringThe exact gateway provider slug (for example, vertexAnthropic)
vercel.ai_gateway.request.idstringThe gateway request ID
vercel.ai_gateway.generation.idstringThe generation ID shown in the AI Gateway dashboard
vercel.ai_gateway.api_key.idstringThe API key that made the request
vercel.ai_gateway.api_key.namestringThe API key's display name
vercel.ai_gateway.api_formatstringThe API format the client used (for example, the Chat Completions or Anthropic formats)
vercel.ai_gateway.credential.typestringbyok or system
vercel.ai_gateway.byok.credential.idstringThe BYOK credential used, if any
vercel.ai_gateway.cost.totalstringRequest cost, as a decimal string
vercel.ai_gateway.cost.currencystringCost currency
vercel.ai_gateway.cost.marketstringThe provider's list price for the request, as a decimal string
vercel.ai_gateway.cost.market_currencystringMarket cost currency
vercel.ai_gateway.zdr.requestedbooleanWhether the request required Zero Data Retention
vercel.ai_gateway.service_tierstringThe service tier that served the request
vercel.ai_gateway.referring_site.urlstringThe referring site, when the request came from a registered app
vercel.ai_gateway.referring_site.namestringThe referring site's name
vercel.ai_gateway.tagsstringRequest tags you attached for reporting
vercel.ai_gateway.environmentstringThe Vercel environment the request came from
vercel.ai_gateway.regionstringThe region that handled the request
vercel.ai_gateway.user.idstringThe end-user ID you attached to the request
vercel.project.idstringThe Vercel project the request is attributed to
vercel.deployment.idstringThe Vercel deployment the request is attributed to

The routing span records how AI Gateway chose a provider, and each model attempt span records one model in the fallback chain:

AttributeTypeDescription
vercel.ai_gateway.vmc.idstringThe Vercel Managed Credential used, if any
vercel.ai_gateway.vmc.usedbooleanWhether a Vercel Managed Credential was used
vercel.ai_gateway.routing.provider_only_filterstringThe only provider filter, if you set one
vercel.ai_gateway.routing.custom_provider_orderstringThe order provider preference, if you set one
vercel.ai_gateway.model_attempt.indexintThis model's position in the fallback chain
vercel.ai_gateway.model_attempt.totalintTotal models attempted
vercel.ai_gateway.model_attempt.is_lastbooleanWhether this was the last model attempted
vercel.ai_gateway.model_attempt.successbooleanWhether this model attempt succeeded
vercel.ai_gateway.model_attempt.provider_attempt_countintProvider attempts made for this model

Each provider attempt span records one upstream call:

AttributeTypeDescription
gen_ai.provider.namestringThe provider, mapped to OTel well-known values
gen_ai.request.modelstringThe canonical model slug for this attempt
http.response.status_codeintThe provider's response status
error.typestringThe provider error, on failed attempts
vercel.ai_gateway.attempt.idstringThe attempt ID
vercel.ai_gateway.attempt.numberintThis attempt's position within its model attempt
vercel.ai_gateway.attempt.total_in_requestintTotal provider attempts across the request
vercel.ai_gateway.attempt.total_in_model_attemptintTotal provider attempts for this model
vercel.ai_gateway.attempt.is_finalbooleanWhether this was the last attempt in the request
vercel.ai_gateway.attempt.successbooleanWhether the provider call succeeded
vercel.ai_gateway.attempt.provider_timeoutbooleanWhether the attempt hit a provider timeout
vercel.ai_gateway.attempt.configured_timeout_msintThe configured timeout, in milliseconds
vercel.ai_gateway.attempt.provider_request_idstringThe provider's own request ID, for support escalations
vercel.ai_gateway.attempt.provider_response_idstringThe provider's own response ID
vercel.ai_gateway.credential.typestringbyok or system
vercel.ai_gateway.byok.credential.idstringThe BYOK credential used, if any
vercel.ai_gateway.regionstringThe region that made the upstream call
Last updated September 8, 2026

Was this helpful?

supported.