feat(anthropic,fireworks,openai): support langsmith gateway through env var#38742
feat(anthropic,fireworks,openai): support langsmith gateway through env var#38742ccurme (ccurme) wants to merge 4 commits into
Conversation
| alias="api_key", | ||
| default_factory=secret_from_env("ANTHROPIC_API_KEY", default=""), | ||
| default_factory=lambda: SecretStr( | ||
| os.getenv("LANGSMITH_GATEWAY_API_KEY") |
There was a problem hiding this comment.
🟠 Gateway key overrides provider credentials
This reads LANGSMITH_GATEWAY_API_KEY whenever it is present, even when LANGSMITH_GATEWAY is unset or explicitly false. In that configuration the model still targets the normal Anthropic endpoint, but the Anthropic API key from ANTHROPIC_API_KEY is replaced with the gateway key, so requests fail authentication. The same unconditional override was added for Fireworks and OpenAI as well; the gateway key should only take precedence when the gateway base URL is actually selected (or the docs/tests should cover and justify the global override).
(Refers to line 978)
Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.
| sync_api_key_value: str | Callable[[], str] | None = None | ||
| async_api_key_value: str | Callable[[], Awaitable[str]] | None = None | ||
|
|
||
| if self.openai_api_key is None and _base_url_from_gateway: |
There was a problem hiding this comment.
🟠 Provider env key bypasses gateway key
openai_api_key has already been populated from OPENAI_API_KEY by its field default factory before this validator runs, so this condition is false whenever both provider and gateway credentials are present. With LANGSMITH_GATEWAY=true, LANGSMITH_GATEWAY_API_KEY=gateway-key, and OPENAI_API_KEY=provider-key, the base URL is switched to the LangSmith gateway but the OpenAI provider key is sent to it, causing authentication to fail. The new positive test hides this by deleting OPENAI_API_KEY; gateway-key precedence needs to happen before the provider env fallback while still preserving an explicitly passed api_key.
(Refers to line 1215)
Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.
Enables LLM Gateway for supported chat models:
or, using a custom URL: