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:.env
Trace with Cloudflare AI Gateway
UsewrapOpenAI 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 themodel parameter and corresponding API key. All requests are automatically traced by Braintrust regardless of which provider you use.
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 toLLM 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>.
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 Deploy your Worker. Agent runs now appear as traces in Braintrust.
wrangler.jsonc, enable trace export and reference the braintrust destination you created by name:wrangler.jsonc