Skip to content

DatabricksOpenAI: forward extra kwargs to OpenAI init#429

Merged
jennsun merged 5 commits into
databricks:mainfrom
kevinyan122:fix/databricks-openai-forward-kwargs
May 13, 2026
Merged

DatabricksOpenAI: forward extra kwargs to OpenAI init#429
jennsun merged 5 commits into
databricks:mainfrom
kevinyan122:fix/databricks-openai-forward-kwargs

Conversation

@kevinyan122
Copy link
Copy Markdown
Contributor

@kevinyan122 kevinyan122 commented May 11, 2026

Summary

  • Add **kwargs to DatabricksOpenAI.__init__ and AsyncDatabricksOpenAI.__init__ so callers can pass timeout, max_retries, default_headers, etc. through to the underlying openai.OpenAI / openai.AsyncOpenAI.
  • Fixes ChatDatabricks(max_retries=...) raises TypeError because AsyncDatabricksOpenAI/DatabricksOpenAI reject kwargs #423ChatDatabricks(max_retries=...) raised TypeError on both .client and .async_client. The async path has been broken since databricks-langchain==0.15.0 (when async_client was introduced); the sync path regressed in 0.19.0 when ChatDatabricks was migrated onto DatabricksOpenAI in Update ChatDatabricks to use DatabricksOpenAI #418.
  • Conflicts with the hardcoded api_key / http_client (which carry Databricks auth) surface as Python's native TypeError: got multiple values for keyword argument 'api_key', so no custom validation is needed.

Test plan

🤖 Generated with Claude Code

Kevin Yan and others added 2 commits May 11, 2026 09:51
Both DatabricksOpenAI and AsyncDatabricksOpenAI had closed init signatures, so
ChatDatabricks(max_retries=..., timeout=...) crashed the moment .client or
.async_client was constructed. The async path was broken since 0.15.0 (when
async_client was introduced); 0.19.0 migrated the sync path onto the same
wrapper and inherited the same bug.

Add **kwargs to both wrappers and forward them through to super().__init__,
so timeout, max_retries, default_headers, and other openai.OpenAI kwargs
work as advertised in get_*_openai_client's docstring. Conflicts with the
hardcoded api_key/http_client (which carry Databricks auth) surface as
Python's native TypeError on duplicate kwargs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…st-direct

CI resolves databricks-openai from PyPI at its floor pin (>=0.14.0), which
predates the **kwargs fix in this PR. The openai-side test in
integrations/openai/tests/unit_tests/test_clients.py already covers the
regression at the layer where the bug actually lived.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@jennsun jennsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionality looks good, let's make sure we add coverage to api docs / tests with this new param we are supporting?

Comment thread integrations/openai/src/databricks_openai/utils/clients.py
Comment thread integrations/openai/tests/unit_tests/test_clients.py
Kevin Yan and others added 2 commits May 11, 2026 14:15
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Locks in the safety invariant that the new **kwargs surface cannot be used
to override Databricks-managed auth. Python's native double-pass TypeError
serves as the guardrail; this test asserts it stays that way.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
**kwargs: Additional keyword arguments forwarded to the underlying ``openai.OpenAI``
client (e.g. ``timeout``, ``max_retries``, ``default_headers``). ``api_key`` and
``http_client`` are managed internally for Databricks authentication and cannot
be overridden.
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.

nit: remove comment

``api_key`` and
            ``http_client`` are managed internally for Databricks authentication and cannot
            be overridden.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jennsun jennsun merged commit bde995a into databricks:main May 13, 2026
46 checks passed
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.

ChatDatabricks(max_retries=...) raises TypeError because AsyncDatabricksOpenAI/DatabricksOpenAI reject kwargs

2 participants