examples

module
v0.0.0-...-7aeed6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0

README

Braintrust Go SDK Examples

This directory contains examples demonstrating how to use the Braintrust Go SDK. Examples are organized by complexity and use case.

Getting Started (5 minutes)

Start here to learn basic tracing with popular AI providers:

  • openai/ - Trace OpenAI chat completions
  • anthropic/ - Trace Anthropic Claude messages
  • genai/ - Trace Google Gemini requests
  • genkit/ - Trace Genkit model generation with middleware

Evaluations (15 minutes)

Learn how to evaluate and improve your AI applications:

  • evals/ - Simple eval with inline dataset and scorers
  • datasets/ - Run evals against downloaded datasets
  • dataset-api/ - Complete workflow: create datasets, use prompts, run evals
  • scorers/ - Custom scoring with online and code-based scorers

HTTP API Client

  • api-client/ - Use the public generated openapi client to browse an existing project's experiments, prompts, and datasets without modifying state. Includes commented-out calls to full dataset-row and paused project-automation CRUD lifecycles with cleanup.
  • HTTP API client guide - Generated methods/models, authentication, HTTP status handling, and opt-in write lifecycles.

Alternative Providers & Libraries

Examples for other AI providers and client libraries:

Remote Evals

Run evaluations triggered from the Braintrust UI against your own infrastructure:

  • eval-runner - Run evals from a playground under bt eval --dev, including a prompt parameter

Advanced Features (30 minutes)

More specialized use cases and integrations:

  • manual-llm-logging/ - Manually log LLM calls (for custom AI proxies)
  • attachments/ - Include images and files in traces
  • prompts/ - Render a prompt locally and call the model yourself, or invoke it server-side
  • distributed-tracing/ - W3C baggage propagation across services
  • otel/ - Add Braintrust to existing OpenTelemetry setup

Internal Examples

The internal/ directory contains comprehensive examples that test all SDK features. These are primarily used for SDK development and validation, not for learning. See internal/README.md for details.

Running Examples

Each example is a standalone Go program. To run an example:

cd examples/openai
go run main.go

Make sure you have the required API keys set as environment variables (e.g., OPENAI_API_KEY, ANTHROPIC_API_KEY, BRAINTRUST_API_KEY).

Directories

Path Synopsis
This example demonstrates basic Anthropic tracing with Braintrust.
This example demonstrates basic Anthropic tracing with Braintrust.
This example only reads existing resources unless you uncomment a lifecycle call.
This example only reads existing resources unless you uncomment a lifecycle call.
Package main demonstrates manual attachment usage in Braintrust traces.
Package main demonstrates manual attachment usage in Braintrust traces.
This example demonstrates basic AWS Bedrock Runtime tracing with Braintrust.
This example demonstrates basic AWS Bedrock Runtime tracing with Braintrust.
cloudwego
eino command
Example demonstrating CloudWeGo Eino tracing with Braintrust.
Example demonstrating CloudWeGo Eino tracing with Braintrust.
Package main demonstrates distributed tracing using W3C baggage propagation.
Package main demonstrates distributed tracing using W3C baggage propagation.
This example demonstrates basic Google Gemini tracing with Braintrust.
This example demonstrates basic Google Gemini tracing with Braintrust.
This example demonstrates basic Genkit tracing with Braintrust.
This example demonstrates basic Genkit tracing with Braintrust.
internal
anthropic command
Anthropic kitchen sink - tests all the Anthropic features with minimal code
Anthropic kitchen sink - tests all the Anthropic features with minimal code
bedrockruntime command
AWS Bedrock Runtime kitchen sink - exercises the full Converse feature surface.
AWS Bedrock Runtime kitchen sink - exercises the full Converse feature surface.
braintrust-json command
classifiers command
cloudwego/eino command
Internal golden-test example for CloudWeGo Eino tracing.
Internal golden-test example for CloudWeGo Eino tracing.
email-evals command
This is a realistic eval example.
This is a realistic eval example.
eval-runner command
This example demonstrates running Braintrust evals under the bt CLI, so the Braintrust playground can trigger them against code on your own machine.
This example demonstrates running Braintrust evals under the bt CLI, so the Braintrust playground can trigger them against code on your own machine.
eval-trial-count command
This example demonstrates running each eval case multiple times with TrialCount.
This example demonstrates running each eval case multiple times with TrialCount.
eval-updates command
This example demonstrates using the Update option to append results to an existing experiment.
This example demonstrates using the Update option to append results to an existing experiment.
functions command
kitchensink command
Package main demonstrates a comprehensive "kitchen sink" example that combines as much Braintrust SDK functionality as possible into a single executable.
Package main demonstrates a comprehensive "kitchen sink" example that combines as much Braintrust SDK functionality as possible into a single executable.
load-test command
Package main runs a heavy synthetic load test that exercises the Braintrust SDK's span pipeline (including the attachment processor / uploader) without requiring any real LLM API calls.
Package main runs a heavy synthetic load test that exercises the Braintrust SDK's span pipeline (including the attachment processor / uploader) without requiring any real LLM API calls.
openapi command
This example builds a generated request offline, or reads through the public generated client with -live.
This example builds a generated request offline, or reads through the public generated client with -live.
rewrite command
span-origin command
workflow-eval command
Workflow evaluation with OpenAI batches, polling or externally verified webhooks, and optional Redis persistence across process restarts.
Workflow evaluation with OpenAI batches, polling or externally verified webhooks, and optional Redis persistence across process restarts.
This example demonstrates basic OpenAI tracing with Braintrust.
This example demonstrates basic OpenAI tracing with Braintrust.
This example shows the two ways to use a Braintrust prompt from Go, against the same prompt:
This example shows the two ways to use a Braintrust prompt from Go, against the same prompt:
This example demonstrates OpenAI tracing with Braintrust using the sashabaranov/go-openai library.
This example demonstrates OpenAI tracing with Braintrust using the sashabaranov/go-openai library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL