Follow 303 redirects when the API returns them#106
Merged
Conversation
realark
approved these changes
Feb 18, 2026
Collaborator
Author
|
This was released in v0.1.4. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix HTTP 303 redirect handling for large dataset responses
Fixes #101
Problem
The Braintrust API returns HTTP 303 redirects to S3 presigned URLs when responses are large (e.g., dataset fetches via
POST /btql). The SDK treated all non-2xx responses as errors, so these redirects raised exceptions like:Solution
Extracted a new
Braintrust::Internal::Httpmodule with two composable utilities:Http.with_redirects(uri, request)— drop-in replacement for rawNet::HTTPrequest execution that follows HTTP redirects. Handles 301/302/303 (follow with GET), 307/308 (preserve method and body), stripsAuthorizationheaders on cross-host redirects (e.g., API → S3), and enforces a configurable max redirect limit.Http.decompress_response!(response)— decompresses response bodies based onContent-Encoding(gzip, x-gzip). No-op if uncompressed.The following HTTP call sites now use
with_redirects:API::Datasets— list, get, create, insert, fetch (fetch also callsdecompress_response!)API::Functions— list, create, invoke, get, deleteAPI::Internal::Projects— createAPI::Internal::Experiments— createAPI::Internal::Auth— loginTrace::Attachment— from_urlRedirect handling
Braintrust::ErrorBraintrust::ErrorBraintrust::ErrorBraintrust::ErrorBraintrust::ErrorContent-Encoding