### Setup Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/examples/internal/temporal/README.md Install dependencies for the Temporal CLI and overmind. ```bash # Install dependencies (temporal CLI, overmind, etc.) mise install ``` -------------------------------- ### Evaluation Setup Errors Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of an evaluation setup error due to missing required options like Dataset or Task. ```go result, err := evaluator.Run(ctx, eval.Opts[string, string]{ // Missing Dataset, Task, or Scorers Experiment: "test", }) if err != nil { // Error: "eval error: Experiment is required" or similar log.Fatal(err) } ``` -------------------------------- ### Running Examples Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/examples/README.md Instructions on how to run the Go SDK examples, including setting environment variables. ```bash cd examples/openai go run main.go ``` -------------------------------- ### Development Setup Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/CONTRIBUTING.md Commands to clone the repository, install dependencies using mise, and set up environment variables. ```bash # Clone the repo. git clone git@github.com:braintrustdata/braintrust-sdk-go.git cd braintrust-sdk-go # Install our dependencies. mise trust mise install # Setup your env variables cp env.example .env ``` -------------------------------- ### WithBlockingLogin Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Blocks setup until login completes. Authentication normally happens asynchronously in the background. Enabling blocking login only enables printing links to spans. This is useful for scripts, testing, and examples but not recommended for production. ```go client, _ := braintrust.New(tp, braintrust.WithBlockingLogin(true), ) ``` -------------------------------- ### Running the Example - Option 2: Manual Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/examples/internal/temporal/README.md Manually start the Temporal server, then the worker, and then run the eval. ```bash # Terminal 1: Start Temporal server temporal server start-dev # Terminal 2: Start the worker go run cmd/worker/main.go # Terminal 3: Run eval go run cmd/client/main.go ``` -------------------------------- ### Get Project Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/projects.md Example of how to retrieve a project by its ID. ```go project, err := apiClient.Projects().Get(ctx, "proj_abc123") if err != nil { log.Fatal(err) } fmt.Println("Name:", project.Name) fmt.Println("Org ID:", project.OrgID) ``` -------------------------------- ### Tracing Setup Failed Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of catching an error during OpenTelemetry tracing initialization. ```go client, err := braintrust.New(tp) if err != nil { if strings.Contains(err.Error(), "failed to setup tracing") { // Handle tracing setup error log.Fatal("Tracing setup failed:", err) } } ``` -------------------------------- ### Running a Single Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/CLAUDE.md How to run a specific example from the examples directory. ```bash go run examples/internal//main.go ``` -------------------------------- ### Running the Example - Option 1: Using Mise (Recommended) Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/examples/internal/temporal/README.md Start the Temporal server and worker in one terminal, and run the eval in another. ```bash # Terminal 1: Start Temporal server + worker mise run server # Terminal 2: Run eval (once server is ready) mise run workflow ``` -------------------------------- ### Create Project Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/projects.md Example of how to create a new project. ```go client, _ := braintrust.New(tp, braintrust.WithAPIKey("your-key")) apiClient := client.API() project, err := apiClient.Projects().Create(ctx, projects.CreateParams{ Name: "my-project", }) if err != nil { log.Fatal(err) } fmt.Println("Project ID:", project.ID) fmt.Println("Project Name:", project.Name) ``` -------------------------------- ### Install All Integrations Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/README.md Installs all tracing integrations at once using the meta-module. ```bash go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/all ``` -------------------------------- ### Running All Examples Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/CLAUDE.md Command to run all examples in the project. ```bash make examples ``` -------------------------------- ### Complete Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md This example shows a full workflow of creating a project, a dataset, inserting events, creating an experiment, listing projects, and finally deleting the project. ```go package main import ( "context" "log" "os" "go.opentelemetry.io/otel/sdk/trace" "github.com/braintrustdata/braintrust-sdk-go" "github.com/braintrustdata/braintrust-sdk-go/api/projects" "github.com/braintrustdata/braintrust-sdk-go/api/datasets" "github.com/braintrustdata/braintrust-sdk-go/api/experiments" ) func main() { ctx := context.Background() tp := trace.NewTracerProvider() defer tp.Shutdown(ctx) // Initialize Braintrust client client, err := braintrust.New(tp, braintrust.WithAPIKey(os.Getenv("BRAINTRUST_API_KEY")), ) if err != nil { log.Fatal(err) } // Get API client api := client.API() // Create a project project, err := api.Projects().Create(ctx, projects.CreateParams{ Name: "my-project", }) if err != nil { log.Fatal(err) } log.Printf("Created project: %s (%s)\n", project.Name, project.ID) // Create a dataset dataset, err := api.Datasets().Create(ctx, datasets.CreateParams{ ProjectID: project.ID, Name: "my-dataset", Description: "Test dataset", }) if err != nil { log.Fatal(err) } log.Printf("Created dataset: %s (%s)\n", dataset.Name, dataset.ID) // Insert events into dataset err = api.Datasets().InsertEvents(ctx, dataset.ID, []datasets.Event{ { Input: "input1", Expected: "output1", }, { Input: "input2", Expected: "output2", }, }) if err != nil { log.Fatal(err) } log.Println("Inserted events into dataset") // Create an experiment experiment, err := api.Experiments().Create(ctx, experiments.CreateParams{ ProjectID: project.ID, Name: "my-experiment", }) if err != nil { log.Fatal(err) } log.Printf("Created experiment: %s (%s)\n", experiment.Name, experiment.ID) // List projects projectList, err := api.Projects().List(ctx, projects.ListParams{ Limit: 10, }) if err != nil { log.Fatal(err) } log.Printf("Found %d projects\n", len(projectList.Objects)) // Cleanup err = api.Projects().Delete(ctx, project.ID) if err != nil { log.Fatal(err) } log.Println("Deleted project") } ``` -------------------------------- ### Tracer Usage Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/client.md Example of how to get and use a Tracer from the client to start a span and set attributes. ```go tracer := client.Tracer("my-app") ctx, span := tracer.Start(ctx, "my-operation") span.SetAttributes(attribute.String("user.id", "123")) defer span.End() ``` -------------------------------- ### List Projects Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/projects.md Example of how to list projects with a limit. ```go response, err := apiClient.Projects().List(ctx, projects.ListParams{ Limit: 10, }) if err != nil { log.Fatal(err) } for _, project := range response.Objects { fmt.Printf("ID: %s, Name: %s\n", project.ID, project.Name) } ``` -------------------------------- ### Catching Evaluation Setup Errors Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Demonstrates how to catch and handle evaluation setup errors. ```go result, err := evaluator.Run(ctx, opts) if err != nil { if strings.Contains(err.Error(), "eval error") { // Handle eval setup error log.Fatal("Evaluation setup failed:", err) } } ``` -------------------------------- ### Invalid Configuration Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of creating a client with no API key provided, leading to an invalid configuration error. ```go client, err := braintrust.New(tp) // No API key provided if err != nil { // Error: "invalid configuration: API key is required" log.Fatal(err) } ``` -------------------------------- ### Configuration Loading Order Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Demonstrates how environment variables and explicit options are loaded and overridden for client configuration. ```go // Environment: BRAINTRUST_API_KEY=env-key, BRAINTRUST_DEFAULT_PROJECT=env-project client, _ := braintrust.New(tp, braintrust.WithAPIKey("option-key"), // Overrides BRAINTRUST_API_KEY // BRAINTRUST_DEFAULT_PROJECT remains "env-project" ) ``` -------------------------------- ### Create Experiment Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/experiments.md Example of how to create a new experiment. ```go client, _ := braintrust.New(tp, braintrust.WithAPIKey("your-key")) apiClient := client.API() experiment, err := apiClient.Experiments().Create(ctx, experiments.CreateParams{ ProjectID: "proj_abc123", Name: "my-experiment", Description: "Test experiment", Tags: []string{"v1", "baseline"}, }) if err != nil { log.Fatal(err) } fmt.Println("Experiment ID:", experiment.ID) ``` -------------------------------- ### Example nested tags Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/docs/PUBLISHING.md Examples of tag formats for nested modules. ```text trace/contrib/all/vX.Y.Z trace/contrib/openai/vX.Y.Z trace/contrib/adk/vX.Y.Z ``` -------------------------------- ### Get Dataset Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md Loads a dataset by ID and returns a Dataset iterator. The example shows how to load a dataset and use it in an evaluation, with automatic type conversion. ```go evaluator := braintrust.NewEvaluator[MyInput, MyOutput](client) // Load dataset by ID dataset, err := evaluator.Datasets().Get(ctx, "ds_abc123") if err != nil { log.Fatal(err) } // Use in evaluation - events are automatically converted to MyInput/MyOutput result, _ := evaluator.Run(ctx, eval.Opts[MyInput, MyOutput]{ Experiment: "test", Dataset: dataset, Task: task, Scorers: scorers, }) ``` -------------------------------- ### Register Experiment Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/experiments.md Example of how to register an experiment. ```go experiment, err := apiClient.Experiments().Register(ctx, "my-experiment", "proj_abc123", experiments.RegisterOpts{ Update: true, Tags: []string{"v1"}, }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Client Initialization Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/client.md Example of how to initialize the Braintrust client with a TracerProvider, API key, and project name. ```go package main import ( "context" "log" "os" "go.opentelemetry.io/otel/sdk/trace" "github.com/braintrustdata/braintrust-sdk-go" ) func main() { ctx := context.Background() tp := trace.NewTracerProvider() defer tp.Shutdown(ctx) client, err := braintrust.New(tp, braintrust.WithAPIKey(os.Getenv("BRAINTRUST_API_KEY")), braintrust.WithProject("my-project"), ) if err != nil { log.Fatal(err) } // Client is ready to use tracer := client.Tracer("my-app") ctx, span := tracer.Start(ctx, "my-operation") defer span.End() } ``` -------------------------------- ### Environment Variables Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Example of setting environment variables for Braintrust SDK configuration. ```bash export BRAINTRUST_API_KEY="your-api-key" export BRAINTRUST_DEFAULT_PROJECT="my-project" export BRAINTRUST_DEBUG="true" ``` -------------------------------- ### TracerProvider Usage Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/client.md Example of how to get and use the TracerProvider from the client. ```go tp := client.TracerProvider() // Use tp to create additional tracers or access provider state ``` -------------------------------- ### Custom Logger Implementation Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Provides an example of how to implement a custom logger for the Braintrust Go SDK. ```go // Custom logger type MyLogger struct {} func (l *MyLogger) Debug(msg string, args ...any) { /* ... */ } func (l *MyLogger) Info(msg string, args ...any) { /* ... */ } func (l *MyLogger) Warn(msg string, args ...any) { /* ... */ } func (l *MyLogger) Error(msg string, args ...any) { /* ... */ } client, _ := braintrust.New(tp, braintrust.WithLogger(&MyLogger{})) ``` -------------------------------- ### Projects Method Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Returns a client for project operations. ```go apiClient := api.NewClient("key") projectsAPI := apiClient.Projects() project, err := projectsAPI.Create(ctx, projects.CreateParams{ Name: "my-project", }) ``` -------------------------------- ### Invalid Parameters Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of attempting to create a project with an empty name, resulting in an invalid parameters error. ```go project, err := apiClient.Projects().Create(ctx, projects.CreateParams{ Name: "", // Empty name }) if err != nil { // Error: "project name is required" log.Fatal(err) } ``` -------------------------------- ### Delete Project Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/projects.md Example of how to delete a project. ```go err := apiClient.Projects().Delete(ctx, "proj_abc123") if err != nil { log.Fatal(err) } fmt.Println("Project deleted successfully") ``` -------------------------------- ### Client Options Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md All options are passed as variadic parameters to braintrust.New(): ```go client, err := braintrust.New(tp, braintrust.WithAPIKey("your-key"), braintrust.WithProject("my-project"), ) ``` -------------------------------- ### Installation Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/README.md Installs the Braintrust Go SDK and sets the API key environment variable. ```bash go get github.com/braintrustdata/braintrust-sdk-go export BRAINTRUST_API_KEY="your-api-key" # Get from https://www.braintrust.dev/app/settings ``` -------------------------------- ### Install Orchestrion Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/README.md Installs the Orchestrion tool for automatic instrumentation. ```bash go install github.com/DataDog/orchestrion@v1.6.1 ``` -------------------------------- ### Task Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md Example of loading and using a hosted task function in an evaluation. ```go evaluator := braintrust.NewEvaluator[string, string](client) // Load hosted task task, err := evaluator.Functions().Task(ctx, eval.FunctionOpts{ Slug: "my-llm-task", Environment: "production", }) if err != nil { log.Fatal(err) } // Use in evaluation - calls remote function result, _ := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test", Dataset: dataset, Task: task, // Remote function call Scorers: scorers, }) ``` -------------------------------- ### WithLogger Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Sets a custom logger for the SDK. If not provided, a default logger is used. ```go customLog := logger.NewDefaultLogger() client, _ := braintrust.New(tp, braintrust.WithLogger(customLog)) ``` -------------------------------- ### Create Dataset Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/datasets.md Example of how to create a new dataset using the Datasets API client. ```go client, _ := braintrust.New(tp, braintrust.WithAPIKey("your-key")) apiClient := client.API() dataset, err := apiClient.Datasets().Create(ctx, datasets.CreateParams{ ProjectID: "proj_abc123", Name: "test-dataset", Description: "My test dataset", Metadata: map[string]interface{}{ "version": "1.0", }, }) if err != nil { log.Fatal(err) } fmt.Println("Dataset ID:", dataset.ID) ``` -------------------------------- ### Result Permalink Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluator.md Shows how to get a permalink to view the experiment results in the Braintrust UI. ```go result, _ := evaluator.Run(ctx, opts) link, err := result.Permalink() if err == nil { fmt.Println("View results:", link) } ``` -------------------------------- ### Not Found Errors Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of attempting to retrieve a project with an invalid ID, resulting in a 404 error. ```go project, err := apiClient.Projects().Get(ctx, "invalid_id") if err != nil { // HTTP 404 error from API log.Fatal(err) } ``` -------------------------------- ### Query Dataset Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md Loads a dataset with advanced query options. The example demonstrates querying by name and version, and also by ID. ```go evaluator := braintrust.NewEvaluator[string, string](client) // Query by name and version dataset, err := evaluator.Datasets().Query(ctx, eval.DatasetQueryOpts{ Name: "test-dataset", Version: "v1.0", Limit: 100, }) if err != nil { log.Fatal(err) } // Query by ID (direct lookup) dataset, err = evaluator.Datasets().Query(ctx, eval.DatasetQueryOpts{ ID: "ds_abc123", }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Experiments Method Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Returns a client for experiment operations. ```go apiClient := api.NewClient("key") experimentsAPI := apiClient.Experiments() experiment, err := experimentsAPI.Create(ctx, experiments.CreateParams{ ProjectID: "proj_123", Name: "my-experiment", }) ``` -------------------------------- ### Install Tracing Integrations Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/README.md Installs specific tracing integrations for various LLM providers. ```bash go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/openai # OpenAI (openai-go) go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/anthropic # Anthropic go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/genai # Google GenAI go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/genkit # Firebase Genkit go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/adk # Google ADK go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/cloudwego/eino # CloudWeGo Eino go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/langchaingo # LangChainGo go get github.com/braintrustdata/braintrust-sdk-go/trace/contrib/github.com/sashabaranov/go-openai # sashabaranov/go-openai ``` -------------------------------- ### TaskOutput Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/eval-types.md Example of how to use TaskOutput in a task function. ```go task := func(ctx context.Context, input string, hooks *eval.TaskHooks) (eval.TaskOutput[string], error) { result := callLLM(input) // Return output and optional app context return eval.TaskOutput[string]{ Value: result, UserData: dbConnection, // Not logged }, nil } ``` -------------------------------- ### Conflict Errors Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example demonstrating a conflict error when trying to create an experiment that already exists with EnsureNew=true. ```go // First call succeeds experiment1, _ := apiClient.Experiments().Create(ctx, params) // Second call with EnsureNew=true fails experiment2, err := apiClient.Experiments().Create(ctx, experiments.CreateParams{ ProjectID: params.ProjectID, Name: params.Name, EnsureNew: true, }) if err != nil { // Error: conflict - experiment already exists } ``` -------------------------------- ### Datasets Method Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Returns a client for dataset operations. ```go apiClient := api.NewClient("key") datasetsAPI := apiClient.Datasets() dataset, err := datasetsAPI.Create(ctx, datasets.CreateParams{ ProjectID: "proj_123", Name: "my-dataset", }) ``` -------------------------------- ### Complete Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md A full Go program demonstrating how to set up and run an evaluation using Braintrust's SDK, including loading hosted datasets, tasks, and scorers. ```go package main import ( "context" "log" "os" "go.opentelemetry.io/otel/sdk/trace" "github.com/braintrustdata/braintrust-sdk-go" "github.com/braintrustdata/braintrust-sdk-go/eval" ) type QAInput struct { Question string `json:"question"` } type QAOutput struct { Answer string `json:"answer"` } func main() { ctx := context.Background() tp := trace.NewTracerProvider() defer tp.Shutdown(ctx) // Initialize client client, err := braintrust.New(tp, braintrust.WithAPIKey(os.Getenv("BRAINTRUST_API_API_KEY")), ) if err != nil { log.Fatal(err) } // Create evaluator with typed input/output evaluator := braintrust.NewEvaluator[QAInput, QAOutput](client) // Load hosted dataset dataset, err := evaluator.Datasets().Query(ctx, eval.DatasetQueryOpts{ Name: "qa-dataset", Limit: 100, }) if err != nil { log.Fatal(err) } // Load hosted task (LLM prompt) task, err := evaluator.Functions().Task(ctx, eval.FunctionOpts{ Slug: "qa-task", Environment: "production", }) if err != nil { log.Fatal(err) } // Load hosted scorer scorer, err := evaluator.Functions().Scorer(ctx, eval.FunctionOpts{ Slug: "qa-scorer", }) if err != nil { log.Fatal(err) } // Run evaluation with hosted resources result, err := evaluator.Run(ctx, eval.Opts[QAInput, QAOutput]{ Experiment: "qa-eval", Dataset: dataset, // From Braintrust Task: task, // Hosted LLM task Scorers: []eval.Scorer[QAInput, QAOutput]{scorer}, // Hosted scorer Parallelism: 4, }) if err != nil { log.Fatal(err) } log.Printf("Evaluation complete: %s", result.Name()) if link, err := result.Permalink(); err == nil { log.Printf("View results: %s", link) } } ``` -------------------------------- ### NewScorer Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/eval-types.md Example of creating a new scorer for exact match. ```go scorer := eval.NewScorer("exact_match", func(ctx context.Context, r eval.TaskResult[string, string]) (eval.Scores, error) { score := 0.0 if r.Expected == r.Output { score = 1.0 } return eval.S(score), nil }) ``` -------------------------------- ### Span Filtering Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md An example demonstrating how to use custom span filter functions to control which spans are sent to Braintrust. ```go client, _ := braintrust.New(tp, braintrust.WithSpanFilterFuncs( func(span trace.ReadOnlySpan) int { // Keep only LLM spans if strings.HasPrefix(span.Name(), "llm.") { return 1 } return 0 // Don't influence other decisions }, ), ) ``` -------------------------------- ### In-memory cases example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/eval-types.md Example of creating an in-memory dataset from a slice of cases. ```go // In-memory cases cases := []eval.Case[string, string]{ { Input: "What is 2+2?", Expected: "4", Tags: []string{"math", "basic"}, Metadata: map[string]interface{}{ "difficulty": "easy", }, }, { Input: "What is 10+20?", Expected: "30", Tags: []string{"math"}, }, } dataset := eval.NewDataset(cases) ``` -------------------------------- ### WithAPIURL Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Sets the API URL for the client. ```go apiClient := api.NewClient("key", api.WithAPIURL("https://api.custom.braintrust.dev"), ) ``` -------------------------------- ### WithAPIURL Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Sets the API URL (overrides BRAINTRUST_API_URL). ```go client, _ := braintrust.New(tp, braintrust.WithAPIURL("https://api.custom.braintrust.dev"), ) ``` -------------------------------- ### Insert Events Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/datasets.md Example of how to insert events into a dataset using the Insert method. ```go events := []datasets.Event{ { Input: "What is 2+2?", Expected: "4", Metadata: map[string]interface{}{ "category": "math", }, }, { Input: "What is 3+3?", Expected: "6", Tags: []string{"arithmetic"}, }, } err := apiClient.Datasets().Insert(ctx, "ds_xyz789", datasets.InsertParams{ Events: events, }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Testing Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/examples/internal/temporal/README.md Run all tests or a specific test. ```bash # Run all tests go test -v # Run specific test go test -v -run TestLoggerWorkflow ``` -------------------------------- ### Authentication Errors Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of a login failure due to an invalid API key and blocking login enabled. ```go client, err := braintrust.New(tp, braintrust.WithAPIKey("invalid-key"), braintrust.WithBlockingLogin(true), ) if err != nil { // Error: "login failed: ..." log.Fatal(err) } ``` -------------------------------- ### NewDataset Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/eval-types.md Example of using NewDataset to create an iterator. ```go dataset := eval.NewDataset([]eval.Case[string, string]{ {Input: "hello", Expected: "hello"}, {Input: "world", Expected: "world"}, }) ``` -------------------------------- ### WithProject Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Sets the default project name (overrides BRAINTRUST_DEFAULT_PROJECT). ```go client, _ := braintrust.New(tp, braintrust.WithProject("my-project")) ``` -------------------------------- ### WithAppURL Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Sets the application URL (overrides BRAINTRUST_APP_URL). ```go client, _ := braintrust.New(tp, braintrust.WithAppURL("https://app.custom.braintrust.dev"), ) ``` -------------------------------- ### Scorer Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md Example of loading and using a hosted scorer function in an evaluation. ```go evaluator := braintrust.NewEvaluator[string, string](client) // Load hosted scorer scorer, err := evaluator.Functions().Scorer(ctx, eval.FunctionOpts{ Slug: "my-scorer", }) if err != nil { log.Fatal(err) } // Use in evaluation - calls remote scorer result, _ := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test", Dataset: dataset, Task: task, Scorers: []eval.Scorer[string, string]{scorer}, // Remote scorer call }) ``` -------------------------------- ### WithAPIKey Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Sets the API key for authentication (overrides BRAINTRUST_API_KEY). ```go client, _ := braintrust.New(tp, braintrust.WithAPIKey("your-key")) ``` -------------------------------- ### Scorer Error Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Shows an example of a scorer function returning an error and how to catch it. ```go scorer := eval.NewScorer("bad_scorer", func(ctx context.Context, r eval.TaskResult[string, string]) (eval.Scores, error) { return nil, fmt.Errorf("scorer error") }) result, err := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test", Dataset: dataset, Task: task, Scorers: []eval.Scorer[string, string]{scorer}, }) if err != nil { // Error: "scorer error: scorer \"bad_scorer\" failed: ..." } ``` ```go result, err := evaluator.Run(ctx, opts) if err != nil { if strings.Contains(err.Error(), "scorer error") { // Handle scorer failure log.Fatal("Scoring failed:", err) } } ``` -------------------------------- ### Function Not Found Error Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of handling a 'function not found' error when requesting a non-existent function. ```go task, err := evaluator.Functions().Task(ctx, eval.FunctionOpts{ Slug: "nonexistent-task", }) if err != nil { // Error: "function not found: project=... slug=nonexistent-task" } ``` ```go task, err := evaluator.Functions().Task(ctx, opts) if err != nil { if strings.Contains(err.Error(), "function not found") { // Handle missing function log.Fatal("Function not found:", err) } } ``` -------------------------------- ### Main Package Import Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/README.md Example of how to import the main Braintrust SDK package and initialize the client. ```go import "github.com/braintrustdata/braintrust-sdk-go" client, _ := braintrust.New(tp) ``` -------------------------------- ### WithLogger Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Sets a custom logger for the client. ```go import "github.com/braintrustdata/braintrust-sdk-go/logger" customLog := logger.NewDefaultLogger() apiClient := api.NewClient("key", api.WithLogger(customLog), ) ``` -------------------------------- ### Functions Method Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Returns a client for function operations (prompts, tools, scorers). ```go apiClient := api.NewClient("key") functionsAPI := apiClient.Functions() funcs, err := functionsAPI.Query(ctx, functions.QueryParams{ ProjectName: "my-project", Slug: "my-prompt", }) ``` -------------------------------- ### Orchestrion Tool Configuration (All Integrations) Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/README.md Example `orchestrion.tool.go` file to include all Braintrust LLM integrations. ```go //go:build tools package main import ( _ "github.com/DataDog/orchestrion" _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/all" // Dedicated meta-module for all Braintrust LLM integrations ) ``` -------------------------------- ### TaskHooks Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/eval-types.md Example demonstrating how to use TaskHooks within a task function to access context and modify spans. ```go task := func(ctx context.Context, input string, hooks *eval.TaskHooks) (eval.TaskOutput[string], error) { // Add custom metrics or attributes to spans hooks.TaskSpan.SetAttributes( attribute.String("user.id", "123"), attribute.Int("attempt", 1), ) // Access case context if len(hooks.Tags) > 0 { fmt.Println("Case tags:", hooks.Tags) } // Perform task return eval.TaskOutput[string]{Value: "result"}, nil } ``` -------------------------------- ### Get Project Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/projects.md Retrieves a project by ID. ```go func (a *API) Get(ctx context.Context, id string) (*Project, error) ``` -------------------------------- ### Run Method Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluator.md Executes an evaluation using the evaluator's configured session, tracer provider, and API client. ```go evaluator := braintrust.NewEvaluator[string, string](client) result, err := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "my-experiment", Dataset: eval.NewDataset([]eval.Case[string, string]{ {Input: "hello", Expected: "hello"}, {Input: "world", Expected: "world"}, }), Task: eval.T(func(ctx context.Context, input string) (string, error) { return input, nil }), Scorers: []eval.Scorer[string, string]{ eval.NewScorer("exact_match", func(ctx context.Context, r eval.TaskResult[string, string]) (eval.Scores, error) { score := 0.0 if r.Expected == r.Output { score = 1.0 } return eval.S(score), nil }), }, Parallelism: 4, }) if err != nil { log.Fatal(err) } fmt.Println("Result:", result.Name()) fmt.Println("Link:", result.Permalink()) ``` -------------------------------- ### Task Type Conversion Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md Demonstrates automatic type conversion for task inputs and outputs using JSON. ```go // Define your types type MyInput struct { Prompt string `json:"prompt"` } type MyOutput struct { Response string `json:"response"` } // Load function task, _ := evaluator.Functions().Task(ctx, eval.FunctionOpts{ Slug: "my-task", }) // When task is called: // 1. MyInput is converted to JSON // 2. Sent to remote function // 3. Response parsed back to MyOutput ``` -------------------------------- ### Experiment Already Exists Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Example of creating an experiment, allowing reuse of an existing experiment by setting EnsureNew to false. ```go // Create with EnsureNew=false (default) to reuse existing exp, err := apiClient.Experiments().Create(ctx, experiments.CreateParams{ ProjectID: projectID, Name: "my-experiment", EnsureNew: false, // Allow reusing existing }) ``` -------------------------------- ### Function Invocation Failed Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Demonstrates handling an error when a hosted function invocation fails on the server. ```go result, err := apiClient.Functions().Invoke(ctx, "fn_abc123", input) if err != nil { // Error from server execution failure log.Fatal(err) } ``` -------------------------------- ### Task Execution Error Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Demonstrates how a task function returning an error or panicking is handled and how to catch it. ```go task := func(ctx context.Context, input string, hooks *eval.TaskHooks) (eval.TaskOutput[string], error) { return eval.TaskOutput[string]{}, fmt.Errorf("task failed") } result, err := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test", Dataset: dataset, Task: task, Scorers: scorers, }) if err != nil { // Error wrapped with task execution details // Error type: "task run error" } ``` ```go result, err := evaluator.Run(ctx, opts) if err != nil { if strings.Contains(err.Error(), "task run error") { // Handle task failure log.Fatal("Task execution failed:", err) } } ``` -------------------------------- ### NewClient Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Creates a new Braintrust API client with the given API key and options. ```go apiClient := api.NewClient("your-api-key") // With options apiClient := api.NewClient("your-api-key", api.WithAPIURL("https://api.custom.braintrust.dev"), api.WithLogger(customLogger), ) ``` -------------------------------- ### WithOrgName Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Sets the organization name (overrides BRAINTRUST_ORG_NAME). ```go client, _ := braintrust.New(tp, braintrust.WithOrgName("my-org")) ``` -------------------------------- ### WithProjectID Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/configuration.md Sets the default project ID (overrides BRAINTRUST_DEFAULT_PROJECT_ID). ```go client, _ := braintrust.New(tp, braintrust.WithProjectID("proj_abc123")) ``` -------------------------------- ### Orchestrion Tool Configuration (Specific Integrations) Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/README.md Example `orchestrion.tool.go` file to include specific Braintrust LLM integrations. ```go import ( _ "github.com/DataDog/orchestrion" _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/openai" // OpenAI (openai-go) _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/anthropic" // Anthropic _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/genai" // Google GenAI _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/genkit" // Firebase Genkit _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/adk" // Google ADK _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/cloudwego/eino" // CloudWeGo Eino _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/langchaingo" // LangChainGo _ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/github.com/sashabaranov/go-openai" // sashabaranov/go-openai ) ``` -------------------------------- ### Error Handling Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md Demonstrates how to handle errors related to missing functions or invocation failures during evaluation. ```go // Function not found task, err := evaluator.Functions().Task(ctx, eval.FunctionOpts{ Slug: "nonexistent", }) if err != nil { if strings.Contains(err.Error(), "function not found") { // Handle missing function } } // Invocation fails during eval result, err := evaluator.Run(ctx, opts) if err != nil { // Error contains details about failed invocation log.Fatal(err) } ``` -------------------------------- ### Sub-packages Import Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/README.md Examples of importing various sub-packages within the Braintrust Go SDK. ```go import "github.com/braintrustdata/braintrust-sdk-go/api" import "github.com/braintrustdata/braintrust-sdk-go/api/projects" import "github.com/braintrustdata/braintrust-sdk-go/api/datasets" import "github.com/braintrustdata/braintrust-sdk-go/api/experiments" import "github.com/braintrustdata/braintrust-sdk-go/api/functions" import "github.com/braintrustdata/braintrust-sdk-go/eval" import "github.com/braintrustdata/braintrust-sdk-go/config" import "github.com/braintrustdata/braintrust-sdk-go/logger" ``` -------------------------------- ### Type Conversion Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluation-apis.md Demonstrates how dataset events are automatically converted from JSON to the evaluator's input/output types. ```go type MyInput struct { Question string `json:"question"` } type MyOutput struct { Answer string `json:"answer"` } // Dataset loaded as DatasetAPI[MyInput, MyOutput] // JSON events are parsed into MyInput/MyOutput structs dataset, _ := evaluator.Datasets().Get(ctx, "ds_123") // Events are automatically converted case, _ := dataset.Next() // case.Input is MyInput{Question: "..."} // case.Expected is MyOutput{Answer: "..."} ``` -------------------------------- ### Error Handling Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/README.md Demonstrates how to check for specific error conditions when running an evaluation. ```go // Check for specific error conditions result, err := evaluator.Run(ctx, opts) if err != nil { switch { case strings.Contains(err.Error(), "eval error"): // Evaluation setup issue case strings.Contains(err.Error(), "task run error"): // Task execution issue case strings.Contains(err.Error(), "scorer error"): // Scorer failure default: // Other error } } ``` -------------------------------- ### Dataset Iterator Error Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Illustrates an error occurring during dataset iteration and how to catch it. ```go // Custom dataset that returns error type BadDataset struct{} func (d *BadDataset) Next() (eval.Case[string, string], error) { return eval.Case[string, string]{}, fmt.Errorf("iterator error") } func (d *BadDataset) ID() string { return "" } func (d *BadDataset) Version() string { return "" } result, err := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test", Dataset: &BadDataset{}, Task: task, Scorers: scorers, }) if err != nil { // Error: "case iterator error: iterator error" } ``` ```go result, err := evaluator.Run(ctx, opts) if err != nil { if strings.Contains(err.Error(), "case iterator error") { // Handle dataset error log.Fatal("Dataset iteration failed:", err) } } ``` -------------------------------- ### Evaluations Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/README.md Example of running evaluations with custom test cases and scoring functions using the Braintrust Go SDK. ```go package main import ( "context" "log" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/sdk/trace" "github.com/braintrustdata/braintrust-sdk-go" "github.com/braintrustdata/braintrust-sdk-go/eval" ) func main() { ctx := context.Background() // Set up OpenTelemetry tracer tp := trace.NewTracerProvider() defer tp.Shutdown(ctx) otel.SetTracerProvider(tp) // Initialize Braintrust client, err := braintrust.New(tp) if err != nil { log.Fatal(err) } // Create an evaluator with your task's input and output types evaluator := braintrust.NewEvaluator[string, string](client) // Run an evaluation _, err = evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "greeting-experiment", Dataset: eval.NewDataset([]eval.Case[string, string]{ {Input: "World", Expected: "Hello World"}, {Input: "Alice", Expected: "Hello Alice"}, }), Task: eval.T(func(ctx context.Context, input string) (string, error) { return "Hello " + input, nil }), Scorers: []eval.Scorer[string, string]{ eval.NewScorer("exact_match", func(ctx context.Context, r eval.TaskResult[string, string]) (eval.Scores, error) { score := 0.0 if r.Expected == r.Output { score = 1.0 } return eval.S(score), nil }), }, }) if err != nil { log.Fatal(err) } } ``` -------------------------------- ### Error Handling Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Shows the standard pattern for handling errors returned by Braintrust API methods. ```go project, err := api.Projects().Get(ctx, projectID) if err != nil { log.Fatal(err) // Handle network/validation errors } ``` -------------------------------- ### Datasets Method Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/evaluator.md Returns a dataset API for loading datasets with this evaluator's type parameters. Datasets are automatically converted to the evaluator's input/output types. ```go evaluator := braintrust.NewEvaluator[MyInput, MyOutput](client) // Load dataset from Braintrust API dataset, err := evaluator.Datasets().Get(ctx, "ds_abc123") if err != nil { log.Fatal(err) } // Use in evaluation result, _ := evaluator.Run(ctx, eval.Opts[MyInput, MyOutput]{ Experiment: "test", Dataset: dataset, Task: task, Scorers: scorers, }) ``` -------------------------------- ### Create Spans for Tracing Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/README.md Example of how to create spans for tracing operations using the Braintrust SDK. ```go tracer := client.Tracer("my-app") ctx, span := tracer.Start(ctx, "my-operation") span.SetAttributes(attribute.String("key", "value")) defer span.End() // Get link to span in UI link := client.Permalink(span) ``` -------------------------------- ### Query and Reuse Pattern Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/api-client.md Demonstrates how to query for existing projects and implement a 'find or create' pattern to avoid duplicate resources. ```go // Query for existing existing, _ := api.Projects().List(ctx, projects.ListParams{ Limit: 100, }) // Find or create pattern var projectID string found := false for _, p := range existing.Objects { if p.Name == "my-project" { projectID = p.ID found = true break } } if !found { p, _ := api.Projects().Create(ctx, projects.CreateParams{ Name: "my-project", }) projectID = p.ID } ``` -------------------------------- ### T Function Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/eval-types.md Example of using the T function for a simple task and then using it in an evaluation. ```go // Simple task that just echoes input task := eval.T(func(ctx context.Context, input string) (string, error) { return "echo: " + input, nil }) // Use in evaluation result, _ := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test", Dataset: dataset, Task: task, Scorers: scorers, }) ``` -------------------------------- ### Build, Test and Run Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/CONTRIBUTING.md Command to view available development tasks defined in the Makefile. ```bash make help ``` -------------------------------- ### Catching Invalid Configuration Errors Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/errors.md Demonstrates how to catch and handle invalid configuration errors. ```go client, err := braintrust.New(tp) if err != nil { if strings.Contains(err.Error(), "invalid configuration") { // Handle config error log.Fatal("Configuration invalid:", err) } } ``` -------------------------------- ### InsertEvents Convenience Function Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/datasets.md Example of using the InsertEvents convenience function to insert events into a dataset. ```go events := []datasets.Event{ { Input: "input1", Expected: "output1", }, { Input: "input2", Expected: "output2", }, } err := apiClient.Datasets().InsertEvents(ctx, "ds_xyz789", events) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Prerequisites: Set up OpenTelemetry and initialize Braintrust Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/trace/contrib/README.md Initializes OpenTelemetry and the Braintrust SDK, preparing for manual tracing instrumentation. ```go import ( "context" "log" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/sdk/trace" "github.com/braintrustdata/braintrust-sdk-go" ) func main() { tp := trace.NewTracerProvider() defer tp.Shutdown(context.Background()) otel.SetTracerProvider(tp) _, err := braintrust.New(tp, braintrust.WithProject("my-project")) if err != nil { log.Fatal(err) } // Now add tracing middleware to your LLM clients below } ``` -------------------------------- ### NewEvaluator Usage Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/client.md Example of creating and using an evaluator for string to string evaluations, running multiple evaluations with different experiments and datasets. ```go client, _ := braintrust.New(tp) // Create evaluator for string → string evaluations evaluator := braintrust.NewEvaluator[string, string](client) // Run multiple evaluations with the same evaluator result1, _ := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test-1", Dataset: dataset1, Task: task1, Scorers: scorers, }) result2, _ := evaluator.Run(ctx, eval.Opts[string, string]{ Experiment: "test-2", Dataset: dataset2, Task: task2, Scorers: scorers, }) ``` -------------------------------- ### TaskFunc Example Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/eval-types.md Example of a task function that processes input and returns a result, demonstrating the use of hooks for advanced features and span attributes. ```go task := func(ctx context.Context, input string, hooks *eval.TaskHooks) (eval.TaskOutput[string], error) { // Can access hooks for advanced features if hooks.Metadata != nil { fmt.Println("Case metadata:", hooks.Metadata) } // Add custom span attributes hooks.TaskSpan.SetAttributes(attribute.String("custom.field", "value")) // Return output return eval.TaskOutput[string]{ Value: "result: " + input, }, nil } ``` -------------------------------- ### Get Experiment Source: https://github.com/braintrustdata/braintrust-sdk-go/blob/main/_autodocs/api-reference/experiments.md Retrieves an experiment by its ID. ```go func (a *API) Get(ctx context.Context, experimentID string) (*Experiment, error) ``` ```go experiment, err := apiClient.Experiments().Get(ctx, "exp_xyz789") if err != nil { log.Fatal(err) } fmt.Println("Experiment:", experiment.Name) fmt.Println("Project:", experiment.ProjectID) ```