Skip to content

OLS-3755: Add Anthropic Provider - #3036

Open
raptorsun wants to merge 2 commits into
openshift:mainfrom
raptorsun:ols-3755
Open

OLS-3755: Add Anthropic Provider#3036
raptorsun wants to merge 2 commits into
openshift:mainfrom
raptorsun:ols-3755

Conversation

@raptorsun

@raptorsun raptorsun commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Add a new anthropic provider type to lightspeed-service that uses ChatAnthropic from langchain-anthropic with a direct API key, enabling Claude models without requiring Google Vertex AI or AWS Bedrock as intermediaries.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • New Features

    • Added direct Anthropic support as an LLM provider.
    • Added Anthropic configuration with API-key credentials, custom endpoints, certificates, HTTP clients, and extended-thinking options.
    • Added parameter mapping for Anthropic models, including maximum response tokens.
  • Documentation

    • Updated provider references, configuration guidance, architecture documentation, and supported-provider lists to include Anthropic.
  • Tests

    • Added comprehensive coverage for Anthropic configuration, client setup, parameter handling, and provider registration.

Signed-off-by: Haoyu Sun <hasun@redhat.com>
Signed-off-by: Haoyu Sun <hasun@redhat.com>
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 31, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 31, 2026

Copy link
Copy Markdown

@raptorsun: This pull request references OLS-3755 which is a valid jira issue.

Details

In response to this:

Description

Add a new anthropic provider type to lightspeed-service that uses ChatAnthropic from langchain-anthropic with a direct API key, enabling Claude models without requiring Google Vertex AI or AWS Bedrock as intermediaries.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@raptorsun

Copy link
Copy Markdown
Contributor Author

/hold
need test with an Anthropic account

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 31, 2026
@openshift-ci
openshift-ci Bot requested review from sriroopar and tisnik July 31, 2026 14:49
@openshift-ci

openshift-ci Bot commented Jul 31, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sriroopar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The change adds direct Anthropic provider support. It introduces configuration, API-key loading, HTTP clients, reasoning parameters, provider registration, dependency metadata, documentation, and unit tests.

Changes

Anthropic provider support

Layer / File(s) Summary
Provider contracts and configuration
ols/constants.py, ols/src/llms/providers/provider.py, ols/app/models/config.py
Adds the Anthropic provider constant, parameter validation, max_tokens mapping, certificate handling, API-key loading, and AnthropicConfig.
Anthropic runtime provider
ols/src/llms/providers/anthropic.py, pyproject.toml
Adds the Anthropic provider and its ChatAnthropic integration. The provider supports endpoint and credential overrides, HTTP clients, response limits, sampling defaults, and extended thinking.
Provider registration and validation
tests/unit/llms/providers/test_providers.py, tests/unit/llms/providers/test_anthropic.py
Registers Anthropic and tests configuration, credentials, certificates, HTTP clients, parameter filtering, model loading, and thinking behavior.
Provider specifications and references
.ai/spec/*, docs/ai/providers.md, .konflux/requirements-build.txt, .konflux/requirements.hashes.source.txt
Documents Anthropic support and updates dependency attribution and pinned package metadata.

Build metadata updates

Layer / File(s) Summary
Build dependency metadata
.konflux/requirements-build.txt, .konflux/requirements.hashes.source.txt
Updates vcs-versioning and replaces the pinned langchain-mcp-adapters package and hashes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProviderConfig
  participant SecretStore
  participant Anthropic
  participant ChatAnthropic
  ProviderConfig->>SecretStore: Read Anthropic API key
  ProviderConfig->>Anthropic: Create AnthropicConfig
  Anthropic->>Anthropic: Build endpoint, clients, and model parameters
  Anthropic->>ChatAnthropic: Load configured chat model
  ChatAnthropic-->>Anthropic: Return BaseChatModel
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding direct Anthropic provider support.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/unit/llms/providers/test_anthropic.py (1)

48-69: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for anthropic_config without url.

None of the fixtures set anthropic_config with only credentials_path (omitting url). This is the exact configuration shape that triggers the str(anthropic_config.url) bug flagged in ols/src/llms/providers/anthropic.py (lines 26-33). Add a fixture/test for this case once that fix lands, to prevent regression.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/llms/providers/test_anthropic.py` around lines 48 - 69, Add a
fixture or test alongside provider_config_with_specific_parameters that defines
anthropic_config with credentials_path only and omits url, then exercise
Anthropic provider configuration to verify it initializes successfully without
attempting to stringify a missing anthropic_config.url value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.ai/spec/what/llm-providers.md:
- Line 209: Align Rule 17 with the certificate-store provider list: update the
rule and the startup certificate-store description together so Anthropic and
Bedrock are consistently included only if they use certificates_store; otherwise
remove them from the list. Ensure both documentation references define the same
provider scope.

In `@ols/src/llms/providers/anthropic.py`:
- Around line 26-33: Update the provider-specific URL assignment in the
Anthropic provider initialization to fall back to the existing self.url when
anthropic_config.url is unset, matching the earlier provider_config.url
behavior; avoid converting None into the literal string "None" while preserving
the configured Anthropic URL when present.
- Around line 35-44: Update the `default_parameters` construction used by
`load()` so `ChatAnthropic` receives only supported constructor arguments:
replace `http_client` and `http_async_client` with pre-built clients via
`anthropic_client` and `anthropic_client_async`, or remove them after validating
the installed `langchain-anthropic` signature. Preserve the existing client
configuration and all other parameters.

---

Nitpick comments:
In `@tests/unit/llms/providers/test_anthropic.py`:
- Around line 48-69: Add a fixture or test alongside
provider_config_with_specific_parameters that defines anthropic_config with
credentials_path only and omits url, then exercise Anthropic provider
configuration to verify it initializes successfully without attempting to
stringify a missing anthropic_config.url value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 77104973-e943-4648-b8f7-6e1496fcb540

📥 Commits

Reviewing files that changed from the base of the PR and between d3f0286 and 1337504.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock, !uv.lock
📒 Files selected for processing (15)
  • .ai/spec/README.md
  • .ai/spec/how/llm-providers.md
  • .ai/spec/what/config.md
  • .ai/spec/what/llm-providers.md
  • .ai/spec/what/system-overview.md
  • .konflux/requirements-build.txt
  • .konflux/requirements.hashes.source.txt
  • docs/ai/providers.md
  • ols/app/models/config.py
  • ols/constants.py
  • ols/src/llms/providers/anthropic.py
  • ols/src/llms/providers/provider.py
  • pyproject.toml
  • tests/unit/llms/providers/test_anthropic.py
  • tests/unit/llms/providers/test_providers.py

6. Credentials are never logged. Parameters containing keys, tokens, or HTTP client objects must be redacted from log output.

7. The certificate store path is computed at startup and points to a PEM bundle file in the certificate directory. It is only used by OpenAI-family providers (OpenAI, Azure OpenAI, RHOAI vLLM, RHELAI vLLM, Bedrock).
7. The certificate store path is computed at startup and points to a PEM bundle file in the certificate directory. It is only used by OpenAI-family providers and direct Anthropic (OpenAI, Azure OpenAI, RHOAI vLLM, RHELAI vLLM, Anthropic, Bedrock).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Align the certificate-store contract.

Line 209 includes Anthropic and Bedrock, but Rule 17 at Line 58 omits both providers. Update Rule 17 and this list together, or remove providers that do not use certificates_store. Inconsistent TLS documentation can cause incorrect provider configuration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.ai/spec/what/llm-providers.md at line 209, Align Rule 17 with the
certificate-store provider list: update the rule and the startup
certificate-store description together so Anthropic and Bedrock are consistently
included only if they use certificates_store; otherwise remove them from the
list. Ensure both documentation references define the same provider scope.

Comment on lines +26 to +33
self.url = str(self.provider_config.url or self.url)
self.credentials = self.provider_config.credentials
# provider-specific configuration has precedence over regular configuration
if self.provider_config.anthropic_config is not None:
anthropic_config = self.provider_config.anthropic_config
self.url = str(anthropic_config.url)
if anthropic_config.api_key is not None:
self.credentials = anthropic_config.api_key

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Fix missing None fallback for anthropic_config.url.

AnthropicConfig only requires credentials_path; url is optional. If anthropic_config is set but url is omitted, anthropic_config.url is None, and str(anthropic_config.url) produces the literal string "None". Line 26 correctly falls back with or self.url when the general provider_config.url is unset. Apply the same fallback here.

🐛 Proposed fix
         if self.provider_config.anthropic_config is not None:
             anthropic_config = self.provider_config.anthropic_config
-            self.url = str(anthropic_config.url)
+            self.url = str(anthropic_config.url or self.url)
             if anthropic_config.api_key is not None:
                 self.credentials = anthropic_config.api_key
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.url = str(self.provider_config.url or self.url)
self.credentials = self.provider_config.credentials
# provider-specific configuration has precedence over regular configuration
if self.provider_config.anthropic_config is not None:
anthropic_config = self.provider_config.anthropic_config
self.url = str(anthropic_config.url)
if anthropic_config.api_key is not None:
self.credentials = anthropic_config.api_key
if self.provider_config.anthropic_config is not None:
anthropic_config = self.provider_config.anthropic_config
self.url = str(anthropic_config.url or self.url)
if anthropic_config.api_key is not None:
self.credentials = anthropic_config.api_key
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ols/src/llms/providers/anthropic.py` around lines 26 - 33, Update the
provider-specific URL assignment in the Anthropic provider initialization to
fall back to the existing self.url when anthropic_config.url is unset, matching
the earlier provider_config.url behavior; avoid converting None into the literal
string "None" while preserving the configured Anthropic URL when present.

Comment on lines +35 to +44
default_parameters: dict[str, Any] = {
"model": self.model,
"anthropic_api_key": self.credentials,
"base_url": self.url,
"max_tokens": constants.DEFAULT_MAX_TOKENS_FOR_RESPONSE,
"temperature": 0.01,
"top_p": 0.95,
"http_client": self._construct_httpx_client(True, False),
"http_async_client": self._construct_httpx_client(True, True),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🌐 Web query:

Does langchain-anthropic ChatAnthropic 0.3.x support http_client or http_async_client constructor parameters, or is custom httpx client injection unsupported?

💡 Result:

In langchain-anthropic 0.3.x, ChatAnthropic does not natively support http_client or http_async_client as direct constructor parameters [1][2]. Providing these parameters directly to the ChatAnthropic constructor will raise a TypeError (unexpected keyword argument) [1][2]. While there has been ongoing development to add these fields to match other integrations (such as ChatOpenAI) [3][4], versions within the 0.3.x range typically manage the httpx client internally, creating it automatically using default settings [3][2][5]. To inject a custom httpx client, the standard workaround in 0.3.x is to initialize the underlying Anthropic SDK client yourself and inject it into ChatAnthropic using the anthropic_client (or anthropic_client_async) constructor parameter [2]: import httpx from anthropic import Anthropic from langchain_anthropic import ChatAnthropic # 1. Create your custom client custom_http = httpx.Client(proxy="http://proxy.corp:8080",...) anth_client = Anthropic(http_client=custom_http,...) # 2. Inject it into ChatAnthropic llm = ChatAnthropic( model="claude-3-5-sonnet-20240620", anthropic_client=anth_client,) If you require fine-tuned control over the default httpx client (e.g., custom timeouts or proxy settings) without building the entire client manually, newer updates have introduced a client_args parameter in some branches to pass arguments directly to the internally created httpx client [6]. Always verify your specific version, as the integration logic is subject to frequent updates [2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)anthropic\.py$|pyproject\.toml|poetry\.lock|requirements.*|uv\.lock|pdm\.lock|constraints|requirements\.txt' || true

echo "== target slice =="
if [ -f ols/src/llms/providers/anthropic.py ]; then
  nl -ba ols/src/llms/providers/anthropic.py | sed -n '1,120p'
fi

echo "== dependency mentions =="
rg -n 'langchain-anthropic|langchain_anthropic|langchain' -S pyproject.toml poetry.lock uv.lock pdm.lock requirements*.txt constraints* 2>/dev/null || true

echo "== ChatAnthropic usages/tests =="
rg -n 'ChatAnthropic|anthropic_client|anthropic_client_async|http_client|http_async_client' -S . --glob '!*.lock' --glob '!**/.venv/**' --glob '!**/dist/**' --glob '!**/build/**' || true

Repository: openshift/lightspeed-service

Length of output: 713


🌐 Web query:

langchain-anthropic ChatAnthropic constructor anthropic_client anthropic_client_async source

💡 Result:

In the langchain-anthropic package, ChatAnthropic manages Anthropic API clients internally through cached properties rather than exposing them as constructor arguments. The ChatAnthropic class utilizes the following mechanisms for client management: 1. Internal Client Access: The synchronous anthropic.Client and asynchronous anthropic.AsyncClient instances are accessed via private cached properties named _client and _async_client, respectively [1][2][3]. 2. Configuration and Initialization: These clients are constructed on-demand based on configuration parameters provided to the ChatAnthropic constructor, such as base_url, timeout, and anthropic_proxy [1][2]. These parameters are stored in an internal _client_params dictionary, which is used to initialize the underlying Anthropic SDK clients during the first property access [1][4]. 3. Implementation Details: - The sync client is returned by the @cached_property def _client(self) -> anthropic.Client method [1][4]. - The async client is returned by the @cached_property def _async_client(self) -> anthropic.AsyncClient method [1][4]. Because these are implemented as cached properties, they are intended for internal use by the ChatAnthropic integration logic rather than for external configuration via the constructor [1][3]. Users should configure the client's behavior by passing relevant parameters (e.g., timeout, base_url, anthropic_proxy) directly to the ChatAnthropic constructor, which the class then propagates to the underlying SDK clients [1][5][4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target slice =="
if [ -f ols/src/llms/providers/anthropic.py ]; then
  python3 - <<'PY'
with open("ols/src/llms/providers/anthropic.py", encoding="utf-8") as f:
    for i, line in enumerate(f, 1):
        if 1 <= i <= 130:
            print(f"{i:4d}\t{line.rstrip()}")
PY
fi

echo "== dependency mentions =="
rg -n 'langchain-anthropic|langchain_anthropic|langchain|anthropic>=|anthropic<|anthropic==' pyproject.toml uv.lock requirements.txt .konflux || true

echo "== ChatAnthropic usages/tests =="
rg -n 'ChatAnthropic|anthropic_client|anthropic_client_async|http_client|http_async_client|_construct_httpx_client' sos ols . --glob '!*.lock' --glob '!**/.venv/**' --glob '!**/dist/**' --glob '!**/build/**' 2>/dev/null || true

echo "== uv lock langchain-anthropic package entries =="
python3 - <<'PY'
path='uv.lock'
try:
    with open(path, encoding='utf-8') as f:
        txt=f.read()
except FileNotFoundError:
    print("uv.lock not found")
    raise SystemExit
for i,line in enumerate(txt.splitlines(),1):
    if 'langchain-anthropic' in line or 'name = "langchain-anthropic"' in line:
        print(f"{i}: {line}")
PY

Repository: openshift/lightspeed-service

Length of output: 35013


🌐 Web query:

langchain_anthropic ChatAnthropic source http_client http_async_client anthropic_client_async

💡 Result:

In the langchain-anthropic library, the ChatAnthropic class manages its underlying HTTP connections using internal helper functions—_get_default_httpx_client and _get_default_async_httpx_client—located in the _client_utils.py module [1][2][3][4]. These helpers return configured httpx.Client and httpx.AsyncClient instances, respectively, which are then passed to the official Anthropic SDK's client constructors [1][2][3][4]. For a significant period, ChatAnthropic did not allow users to inject custom httpx clients, which limited support for scenarios requiring custom proxy configurations, mutual TLS (mTLS), or specific certificate paths [5][6][7][8]. To address these limitations, community efforts and development prioritized adding explicit http_client and http_async_client fields to the ChatAnthropic class, bringing it to parity with other integrations like ChatOpenAI [5][6][9]. As of May 2026, work has been merged (via pull requests such as #37526) to introduce these optional http_client and http_async_client fields [7][9]. When these are provided, the ChatAnthropic class uses the user-supplied client instead of generating a default one, allowing for advanced transport-layer customization [5][6]. Before this addition, users frequently had to resort to manual workarounds, such as monkey-patching the internal client attributes or attempting to pass unsupported parameters [7].

Citations:


🌐 Web query:

langchain-anthropic 1.5.3 ChatAnthropic source default_async_client custom_client _client_utils

💡 Result:

In langchain-anthropic version 1.5.3, the ChatAnthropic class manages its interaction with the Anthropic API using cached client instances [1][2]. The terms you mentioned relate to the internal mechanism for managing these clients: _client and _async_client: These are @cached_property methods defined within ChatAnthropic that handle the initialization and retrieval of the underlying Anthropic SDK clients (anthropic.Client and anthropic.AsyncClient, respectively) [1]. By caching these, the model avoids re-initializing the client on every invocation [2]. _client_utils.py: This module was introduced (e.g., via PR #31659) to centralize utility logic for client management, including the caching mechanism [2]. Custom Client Usage: While ChatAnthropic is designed to automatically manage the Anthropic SDK client based on provided configuration (such as api_key, base_url, and timeout), it does not natively expose a parameter to inject a pre-constructed custom client instance directly into its constructor [3][4][5]. Developers requiring specific custom client behavior—such as using an azure_ad_token_provider—typically achieve this by subclassing ChatAnthropic and overriding the _client and _async_client cached properties to return the desired client instance [1]. The version 1.5.3 of langchain-anthropic was released on July 28, 2026, and included fixes related to streaming and message content handling [6][7].

Citations:


🌐 Web query:

langchain-anthropic 1.5.3 ChatAnthropic source __init__ http_client anthropic_client_async

💡 Result:

In recent versions of the langchain-anthropic package, including 1.5.3, the ChatAnthropic class has been updated to support custom HTTP clients, bringing it into parity with other integrations like ChatOpenAI [1]. Users can now pass custom httpx.Client and httpx.AsyncClient instances directly to ChatAnthropic via the http_client and http_async_client initialization parameters, respectively [1]. These parameters allow for advanced network customization, such as configuring custom SSL settings, proxies, or corporate network environments [1]. In the internal implementation of ChatAnthropic, these parameters are utilized within the _client and _async_client cached properties [1]. If a user provides an http_client or http_async_client, the class uses the provided client; otherwise, it falls back to the default internal client creation logic (using utility functions _get_default_httpx_client or _get_default_async_httpx_client) [1]. Previously, ChatAnthropic relied exclusively on its internal mechanisms for creating and managing HTTP clients, making it difficult to inject pre-configured clients [1]. This addition ensures that the Anthropic SDK, which natively supports http_client as a constructor argument, can be fully leveraged through the LangChain wrapper [1].

Citations:


🌐 Web query:

langchain-anthropic 1.5.3 ChatAnthropic http_async_client anthropic_client_async constructor

💡 Result:

In langchain-anthropic version 1.5.3, the ChatAnthropic class does not accept http_client or http_async_client as direct constructor parameters [1][2][3]. While there have been community requests and discussions to add these fields to provide parity with other integration classes like ChatOpenAI—specifically to support custom httpx clients for use cases such as mTLS, proxy configuration, or certificate-based authentication [1][2]—the official implementation in the langchain-anthropic package historically relies on internal mechanisms to manage clients [2][4]. To inject a custom client into ChatAnthropic, the recommended and supported approach is to instantiate the underlying Anthropic SDK client yourself and pass it to the constructor using the anthropic_client or anthropic_client_async parameters [3]: from anthropic import AsyncAnthropic import httpx from langchain_anthropic import ChatAnthropic # 1. Create your custom httpx client async_http = httpx.AsyncClient(...) # 2. Instantiate the Anthropic client with your custom httpx client anth_async = AsyncAnthropic(http_client=async_http) # 3. Inject it into ChatAnthropic llm = ChatAnthropic( model="claude-3-5-sonnet-20241022", anthropic_client_async=anth_async,) Passing http_client directly to the ChatAnthropic constructor will typically raise a TypeError in recent versions of the library, as the wrapper class strictly validates its arguments [3]. If you need to use both synchronous and asynchronous invocation methods (invoke and ainvoke), you should provide both anthropic_client and anthropic_client_async respectively [3].

Citations:


Remove unsupported Anthropic HTTP-client kwargs.

load() passes self.params to ChatAnthropic, and default_params currently includes http_client/http_async_client. ChatAnthropic does not expose these constructor kwargs, so every Anthropic load fails with an unrecognized argument error. Use anthropic_client/anthropic_client_async with pre-built Anthropic clients, or remove these kwargs after checking the installed langchain-anthropic signature.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ols/src/llms/providers/anthropic.py` around lines 35 - 44, Update the
`default_parameters` construction used by `load()` so `ChatAnthropic` receives
only supported constructor arguments: replace `http_client` and
`http_async_client` with pre-built clients via `anthropic_client` and
`anthropic_client_async`, or remove them after validating the installed
`langchain-anthropic` signature. Preserve the existing client configuration and
all other parameters.

@openshift-ci

openshift-ci Bot commented Jul 31, 2026

Copy link
Copy Markdown

@raptorsun: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-ols-cluster 1337504 link true /test e2e-ols-cluster

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants