Skip to content

docs(openai): document ChatOpenAI endpoint resolution precedence - #11638

Open
Mohan Ram (mohanram-dev) wants to merge 1 commit into
langchain-ai:mainfrom
mohanram-dev:docs/chatopenai-endpoint-resolution-precedence
Open

Mohan Ram (mohanram-dev) wants to merge 1 commit into
langchain-ai:mainfrom
mohanram-dev:docs/chatopenai-endpoint-resolution-precedence

Conversation

@mohanram-dev

Copy link
Copy Markdown

Description

Fixes #11635

This PR documents the base URL endpoint resolution order in @langchain/openai and adds unit test coverage to ensure parity with the Python counterpart (langchain-openai).

In @langchain/openai, ChatOpenAI resolves its endpoint according to the following precedence:

  1. configuration.baseURL (explicit client option)
  2. baseUrl (serialized/loaded compatibility field)
  3. OPENAI_API_BASE environment variable (read by LangChain — takes precedence over OPENAI_BASE_URL)
  4. OPENAI_BASE_URL environment variable (read by the underlying OpenAI SDK)
  5. Default OpenAI API base URL (https://api.openai.com/v1)

Because the underlying openai SDK reads only OPENAI_BASE_URL and ignores OPENAI_API_BASE, a leftover OPENAI_API_BASE in the environment can silently override a newly configured OPENAI_BASE_URL. This PR adds explicit JSDoc documentation and regression test assertions to make this priority explicit and clear for developers.

Changes Made

  • Documented resolution order on BaseChatOpenAIFields.configuration in libs/providers/langchain-openai/src/chat_models/base.ts.
  • Updated ChatOpenAI class JSDoc in libs/providers/langchain-openai/src/chat_models/index.ts.
  • Added unit tests in libs/providers/langchain-openai/src/chat_models/tests/index.test.ts verifying OPENAI_API_BASE takes precedence over OPENAI_BASE_URL, and configuration.baseURL takes precedence over environment variables.

Validation

  • pnpm --filter @langchain/core build passed.
  • pnpm --filter @langchain/openai build passed.
  • pnpm --filter @langchain/openai test src/chat_models/tests/index.test.ts passed (54/54 tests).
  • pnpm format:check and pnpm lint passed with 0 errors.

@changeset-bot

changeset-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b412961

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC: ChatOpenAI endpoint resolution — OPENAI_API_BASE takes precedence over OPENAI_BASE_URL, documented in Python but not in JS

2 participants