openrouter SDK with wrap_openrouter() or through OpenRouter’s OpenAI-compatible endpoint with wrap_openai().
This guide covers manual instrumentation. For quicker setup, use auto-instrumentation.
Setup
Install Braintrust and the native OpenRouter SDK:.env
Trace with OpenRouter
Usewrap_openrouter() when you want to trace the native OpenRouter SDK directly.
trace-openrouter.py
Use the OpenAI-compatible endpoint
If your app already uses the OpenAI Python SDK against OpenRouter’s OpenAI-compatible endpoint, keep that setup and usewrap_openai().
trace-openrouter-openai-compatible.py
What Braintrust traces
For the nativeopenrouter SDK, Braintrust traces:
- Chat completions, including
chat.send()andsend_async() - Streaming chat responses
- Embeddings via
embeddings.generate() - Responses API calls via
beta.responses.send()andsend_async()