Skip to main content
Braintrust integrates with Cloudflare in two ways: tracing LLM requests routed through Cloudflare AI Gateway, and exporting traces from Cloudflare Agents over OpenTelemetry. This page covers both.

Cloudflare AI Gateway

Cloudflare AI Gateway provides a unified interface to access multiple AI providers with observability, caching, and rate limiting. Braintrust automatically traces requests through Cloudflare AI Gateway across all supported providers.

Setup

Install the Braintrust SDK and OpenAI client:
Configure your environment variables:
.env

Trace with Cloudflare AI Gateway

Use wrapOpenAI to automatically trace requests through Cloudflare’s unified API endpoint:

Switching providers

Cloudflare AI Gateway’s unified API allows you to easily switch between different AI providers by changing the model parameter and corresponding API key. All requests are automatically traced by Braintrust regardless of which provider you use.
Cloudflare AI Gateway supports OpenAI, Anthropic, Google AI Studio, Groq, Mistral, Cohere, Perplexity, DeepSeek, Cerebras, xAI, and Workers AI. See the Cloudflare documentation for the complete list.

AI Gateway resources

Cloudflare Agents

Cloudflare Agents instrument each agent run with OpenTelemetry spans that follow the GenAI semantic conventions. Because Braintrust ingests OpenTelemetry data, you can export these spans to Braintrust from Cloudflare’s Workers Observability without adding the Braintrust SDK to your Worker. Braintrust maps the incoming spans to LLM and tool spans automatically.
1

Get your Braintrust credentials

Create an API key in Settings > API keys. Find your project ID using the Copy project ID button at the bottom of the project’s configuration page.
2

Add a tracing destination in Cloudflare

In the Cloudflare dashboard, go to your account’s Workers Observability section and add a destination pointing at Braintrust’s OpenTelemetry endpoint. Name it braintrust so you can reference it in the next step:
  • Name: braintrust.
  • OTLP endpoint: https://api.braintrust.dev/otel/v1/traces.
  • Custom headers:
    • Authorization: Bearer <BRAINTRUST_API_KEY>.
    • x-bt-parent: project_id:<BRAINTRUST_PROJECT_ID>.
The x-bt-parent header sets the project or experiment that receives the traces. For other parent formats and the full attribute mapping, see the OpenTelemetry integration.
If your organization is on the EU data plane, use https://api-eu.braintrust.dev/otel/v1/traces instead. Self-hosted deployments should use their stack’s API URL followed by /otel/v1/traces. See Data plane region.
3

Enable trace export in wrangler

In your Worker’s wrangler.jsonc, enable trace export and reference the braintrust destination you created by name:
wrangler.jsonc
Deploy your Worker. Agent runs now appear as traces in Braintrust.

Cloudflare Agents resources