Skip to content

feat(anthropic,fireworks,openai): support langsmith gateway through env var#38742

Open
ccurme (ccurme) wants to merge 4 commits into
masterfrom
cc/gateway-base-url
Open

feat(anthropic,fireworks,openai): support langsmith gateway through env var#38742
ccurme (ccurme) wants to merge 4 commits into
masterfrom
cc/gateway-base-url

Conversation

@ccurme

@ccurme ccurme (ccurme) commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Enables LLM Gateway for supported chat models:

LANGSMITH_GATEWAY=true
LANGSMITH_GATEWAY_API_KEY=...

or, using a custom URL:

LANGSMITH_GATEWAY=https://...
LANGSMITH_GATEWAY_API_KEY=...

@github-actions github-actions Bot added anthropic `langchain-anthropic` package issues & PRs feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs integration PR made that is related to a provider partner package integration internal openai `langchain-openai` package issues & PRs size: S 50-199 LOC labels Jul 9, 2026

@open-swe open-swe Bot 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.

✅ Open SWE Review: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in WebView Open SWE trace

@github-actions github-actions Bot added size: M 200-499 LOC and removed size: S 50-199 LOC labels Jul 9, 2026

@open-swe open-swe Bot 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.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

alias="api_key",
default_factory=secret_from_env("ANTHROPIC_API_KEY", default=""),
default_factory=lambda: SecretStr(
os.getenv("LANGSMITH_GATEWAY_API_KEY")

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.

🟠 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.

@open-swe open-swe Bot 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.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

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:

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.

🟠 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anthropic `langchain-anthropic` package issues & PRs feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs integration PR made that is related to a provider partner package integration internal openai `langchain-openai` package issues & PRs size: M 200-499 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant