Skip to content

Add project_id support and Prompt#version accessor#131

Merged
David Elner (delner) merged 2 commits intobraintrustdata:mainfrom
patbenatar:add-project-id-and-version-support
Apr 1, 2026
Merged

Add project_id support and Prompt#version accessor#131
David Elner (delner) merged 2 commits intobraintrustdata:mainfrom
patbenatar:add-project-id-and-version-support

Conversation

@patbenatar
Copy link
Copy Markdown
Contributor

Summary

Adds project_id: parameter to Functions#list and Prompt.load, and exposes Prompt#version (backed by _xact_id from the API response).

Motivation

When integrating Braintrust prompts into applications, it's common to reference projects by UUID rather than name (e.g., from configuration or environment variables). The API already supports project_id as a query parameter on GET /v1/function, but the SDK only exposed project_name.

Similarly, _xact_id is returned by the API and represents the prompt version, but wasn't accessible on the Prompt object. This is useful for observability (e.g., attaching prompt version to OpenTelemetry spans).

Changes

  • Functions#list: Added optional project_id: keyword argument, passed as query param when present
  • Prompt.load: Added optional project_id: keyword argument as alternative to project:. Raises ArgumentError if neither is provided. project: is no longer required (but one of the two must be given).
  • Prompt#version: New reader that returns @data["_xact_id"]

Tests

  • Unit tests for Prompt#version (present and nil cases)
  • Unit test for Prompt.load argument validation (requires project or project_id)
  • VCR integration test for Prompt.load(project_id:)
  • VCR integration test for Functions#list(project_id:)
  • Added version assertion to existing load_with_version integration test

Backward Compatibility

Fully backward compatible. Prompt.load(project: "name", slug: "slug") continues to work. The only signature change is that project: is now optional (but an ArgumentError is raised if neither project: nor project_id: is provided).

…version accessor

The Braintrust API supports filtering functions by project_id (UUID),
but the SDK only exposed project_name. This adds project_id as an
optional parameter to Functions#list and Prompt.load, allowing callers
who have a project UUID to load prompts without needing to resolve
the project name first.

Also adds a Prompt#version reader that exposes the _xact_id from the
API response, which is useful for pinning prompts to specific versions
and for observability metadata.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@delner David Elner (delner) left a comment

Choose a reason for hiding this comment

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

Tweaked some tests to shore up coverage but otherwise looks good!

@patbenatar
Copy link
Copy Markdown
Contributor Author

Awesome, thanks David Elner (@delner) ! Can we get this merged + released?

@delner David Elner (delner) merged commit f5078bc into braintrustdata:main Apr 1, 2026
10 checks passed
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