- OpenAI
- Anthropic
- Gemini
Prerequisites
Before you begin, make sure you have:- A Braintrust account: Sign up free at braintrust.dev
- A Braintrust API key: Get one from Settings > API keys
- An OpenAI API key: Get one at platform.openai.com
1. Install SDKs
Install the Braintrust SDK and OpenAI SDK for your programming language.API keys are encrypted using 256-bit AES-GCM encryption and are not stored or logged by Braintrust.
2. Define your application
Create a customer support email classifier that categorizes emails into billing, technical, or feature_request.classifier.ts
3. Trace LLM calls
To enable tracing, make two changes to your code: initialize Braintrust and wrap your OpenAI client. This captures every LLM call automatically.- TypeScript & Python: Use
wrapOpenAI/wrap_openaiwrapper functions - Go: Use the tracing middleware with the OpenAI client
- Ruby: Use
Braintrust::Trace::OpenAI.wrapto wrap the OpenAI client - Java: Use the tracing interceptor with the OpenAI client
- C#: Use
BraintrustOpenAI.WrapOpenAI()to wrap the OpenAI client
classifier.ts
4. View traces
In the Braintrust UI, go to the “Email Classifier” project and select Logs. You’ll see a trace for each email classification request.Click into any trace to see:- Complete input prompt and model output
- Token counts, latency, and cost
- Model configuration (temperature, max tokens, etc.)
- Request and response metadata
Next steps
- Observe - View, filter, and analyze your logs
- Annotate - Create datasets from your logs and add human feedback
- Evaluate - Run experiments to test and validate improvements
- Deploy - Ship changes and monitor production
Troubleshooting
Not seeing traces in the dashboard?
Not seeing traces in the dashboard?
Check your API key:Make sure it’s set and starts with
sk-.Verify the project name:
The project is created automatically when you call initLogger({ projectName: "Email Classifier" }). Check that you’re looking at the correct project in the dashboard.Look for errors:
Check your console output for any error messages from Braintrust. Common issues:- Invalid API key
- Network connectivity issues
- Firewall blocking requests to
api.braintrust.dev
Traces look incomplete or missing data?
Traces look incomplete or missing data?
Check wrapper coverage:
Make sure you’re wrapping the client before making API calls. Calls made with an unwrapped client won’t be traced.Verify async/await:
If using async functions, ensure you’re awaiting API calls properly. Unawaited promises may not be fully traced.Check for errors:
If your LLM call throws an error, the trace may be incomplete. Check logs for error messages.
High latency when logging?
High latency when logging?
Logging is async:
Braintrust logs data asynchronously to avoid blocking your application. Traces should appear in the dashboard within seconds.Check network:
If you’re experiencing delays, verify network connectivity to
api.braintrust.dev.Batch size:
Braintrust batches logs for efficiency. You can adjust batch settings if needed - see the SDK reference.Need help?
Need help?
- Join our Slack community for live support
- Check the GitHub discussions for common questions
- Email us at [email protected]