Skip to content

Add authenticated user's orgName to BraintrustConfig#1

Merged
philhetzel merged 7 commits into
mainfrom
phil/fix-trivia-hardcode
Jul 13, 2025
Merged

Add authenticated user's orgName to BraintrustConfig#1
philhetzel merged 7 commits into
mainfrom
phil/fix-trivia-hardcode

Conversation

@philhetzel

Copy link
Copy Markdown
Contributor

Summary

  • Implements automatic organization name retrieval in BraintrustConfig similar to the Python SDK
  • Fixes experiment URLs that previously showed hardcoded or incorrect organization identifiers
  • Adds login API functionality to fetch user's organization information

Changes Made

  • BraintrustApiClient: Added /api/apikey/login endpoint with proper response models
  • BraintrustConfig: Enhanced to automatically retrieve org name during initialization
  • TriviaEvaluation: Fixed URL generation to use proper org name with URL encoding

Implementation Details

  • Follows Python SDK pattern: calls login endpoint and uses first organization by default
  • Gracefully handles API failures with warnings rather than breaking builds
  • No breaking changes - all existing BraintrustConfig usage automatically gets org name functionality
  • Proper URL encoding ensures special characters in org names work correctly

Test Results

Before:
https://www.braintrust.dev/app/Optional.empty/p/Trivia%20Bot%20Evaluation/experiments/...

After:
https://www.braintrust.dev/app/Braintrust%20Demos/p/Trivia%20Bot%20Evaluation/experiments/...

Test plan

  • Verified organization name is correctly retrieved from API
  • Confirmed experiment URLs now display proper organization names
  • Tested with URL encoding for organization names containing spaces
  • Ensured existing code continues to work without modification
  • Verified graceful failure handling when API is unavailable

philhetzel and others added 3 commits July 10, 2025 20:53
Replace hardcoded 'braintrustdata.com' with project.orgId() to ensure
the experiment URL is constructed correctly for all environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fix URL construction to use project.name() for the organization
identifier in the experiment URL path.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements organization name gathering similar to the Python SDK by calling
the /api/apikey/login endpoint during configuration initialization.

Key changes:
- Add login API method to BraintrustApiClient with proper response models
- Enhance BraintrustConfig to automatically retrieve org name during build()
- Fix experiment URL generation to use proper org name instead of hardcoded values
- Add proper URL encoding for organization names in experiment URLs

The implementation follows the Python SDK pattern:
- Calls /api/apikey/login endpoint to get user's organization info
- Uses the first organization by default if multiple exist
- Gracefully handles API failures with warnings rather than breaking builds
- No breaking changes to existing code - all BraintrustConfig instances
  automatically get org name functionality

Fixes experiment URLs that previously showed "Optional.empty" to now display
the correct organization name (e.g., "Braintrust%20Demos").

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

@ankrgyl Ankur Goyal (ankrgyl) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@ankrgyl

Copy link
Copy Markdown
Contributor

Looks like code formatting failed. I think you can install the pre-commit hooks with

./gradlew installGitHooks

and then try committing again

philhetzel and others added 3 commits July 12, 2025 14:04
Replace instanceof pattern matching with traditional cast syntax to ensure
compatibility with CI environment's Java version and formatter.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The project requires Java 17+ (configured in build.gradle) but CI was
testing against Java 11 which doesn't support record types. Records
were introduced in Java 14 preview and stabilized in Java 16.

This fixes the spotless formatting errors in CI that were caused by
Java 11 not understanding record syntax.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@philhetzel

Copy link
Copy Markdown
Contributor Author

Looks like the formatter was breaking when using Java 11 but not in 17+ so removed v11. Build is failing but looks like expected values in tests don't include v1 in paths.

@ankrgyl

Copy link
Copy Markdown
Contributor

Let me fix the tests in another branch and then will merge it in ehre

@philhetzel philhetzel merged commit 13c78ff into main Jul 13, 2025
3 checks passed
@philhetzel philhetzel deleted the phil/fix-trivia-hardcode branch July 13, 2025 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants