Skip to content

fix: Ignore empty BRAINTRUST_API_URL and BRAINTRUST_PROXY_URL environment variables - #2600

Open
Raphael Fakhri (RaphaelFakhri) wants to merge 1 commit into
braintrustdata:mainfrom
RaphaelFakhri:fix/empty-api-url-env
Open

Raphael Fakhri (RaphaelFakhri) wants to merge 1 commit into
braintrustdata:mainfrom
RaphaelFakhri:fix/empty-api-url-env

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Summary

Empty BRAINTRUST_API_URL and BRAINTRUST_PROXY_URL environment variables are now ignored, and the SDK uses the API and proxy URLs from the organization's login response.

The logger reads both variables with iso.getEnv(name) ?? org.api_url. ?? only falls back for undefined, so an empty value is used as the URL. Empty values are common: Docker Compose sets BRAINTRUST_API_URL: ${BRAINTRUST_API_URL} to "" when the host variable is unset, and GitHub Actions does the same for an undefined ${{ vars.* }}. The effects:

  • BRAINTRUST_API_URL= makes login(), initLogger() and init() fail with Unable to log into any organization with the provided credential., even though the credential is valid.
  • BRAINTRUST_API_URL= makes loadPrompt() and loadParameters() with an explicit apiKey fail with the same error.
  • BRAINTRUST_PROXY_URL= sets state.proxyUrl to "", so proxy requests go to the API URL instead of the organization's proxy URL, and BraintrustState.serialize() throws Cannot serialize BraintrustState without all login attributes.

This change uses || for these lookups, which matches how the same file already reads BRAINTRUST_APP_URL and BRAINTRUST_APP_PUBLIC_URL. The Python SDK already treats empty values of these variables as unset.

Test plan

  • Added tests in js/src/logger.test.ts:
    • loginToState with empty BRAINTRUST_API_URL and BRAINTRUST_PROXY_URL uses the organization's api_url and proxy_url.
    • loadPrompt with an explicit API key and an empty BRAINTRUST_API_URL sends the prompt request to the organization's api_url.
  • Before the change, both new tests fail with Unable to log into any organization with the provided credential. After the change, both pass, and all 133 tests in the file pass.
cd js && npx vitest run src/logger.test.ts -t "login with empty URL environment variables"

This branch has not been deployed

No deployments
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.

1 participant