Skip to content

fix(anthropic): send customHeaders from the model builder - #2920

Merged
geoand merged 1 commit into
quarkiverse:mainfrom
CryoThrust:fix/anthropic-custom-headers
Oct 13, 2026
Merged

geoand merged 1 commit into
quarkiverse:mainfrom
CryoThrust:fix/anthropic-custom-headers

Conversation

@CryoThrust

@CryoThrust CryoThrust commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

QuarkusAnthropicClient replaced langchain4j's Anthropic client but never read builder.customHeadersSupplier, so headers passed through the model builder were dropped on the floor. QuarkusOpenAiClient has applied them through a ClientHeadersFactory since #1927; the Anthropic client is the one that got missed.

A gateway in front of Anthropic that authenticates on its own header therefore received unauthenticated calls, with no warning: the builder accepts the option and the call succeeds against anything that does not check the header.

AnthropicChatModel.builder()
        .apiKey(key)
        .baseUrl(url)
        .customHeaders(Map.of("X-API-Gateway-Key", "gateway-secret"))  // was dropped
        .build();

How it was fixed

Same shape as the OpenAI client: when customHeadersSupplier is set, register a ClientHeadersFactory that returns those headers for the outgoing request, before the REST API is built. Placing it next to the existing ModelAuthProvider filter keeps the ordering unchanged — the filter still adds the credential header afterwards, so x-api-key / Authorization behaviour is untouched.

@quarkus-bot

This comment has been minimized.

@geoand geoand left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I added another comment

@quarkus-bot

This comment has been minimized.

@geoand

geoand commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks.

Can you please squash the commits?

Apply the model builder's customHeadersSupplier through a ClientHeadersFactory
so the Quarkus Anthropic client forwards custom gateway authentication headers.
Cover both blocking and streaming requests with HTTP-level assertions.

Fixes quarkiverse#2918
@CryoThrust
CryoThrust force-pushed the fix/anthropic-custom-headers branch from ab04c14 to 73b461b Compare October 13, 2026 06:00
@CryoThrust

Copy link
Copy Markdown
Contributor Author

Squashed into 73b461be4. The file tree is identical to ab04c1471; this only combines the two commits. The earlier 99 successful checks apply to that unchanged tree, and the new head is waiting for its own CI results.

@geoand geoand left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@quarkus-bot

quarkus-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

Status for workflow Build (on pull request)

This is the status report for running Build (on pull request) on commit 73b461b.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@geoand
geoand merged commit 2873779 into quarkiverse:main Oct 13, 2026
99 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.

QuarkusAnthropicClient ignores customHeaders from the AnthropicChatModel / AnthropicStreamingChatModel builder

2 participants