Skip to content

feat: support custom Anthropic API baseUrl and apiKey#32

Open
sunyuhan1998 wants to merge 1 commit into
spring-ai-community:mainfrom
sunyuhan1998:feat/support-apikey-baseurl
Open

feat: support custom Anthropic API baseUrl and apiKey#32
sunyuhan1998 wants to merge 1 commit into
spring-ai-community:mainfrom
sunyuhan1998:feat/support-apikey-baseurl

Conversation

@sunyuhan1998
Copy link
Copy Markdown

@sunyuhan1998 sunyuhan1998 commented Apr 30, 2026

Summary

  • Add agent-client.claude.api-key and agent-client.claude.base-url configuration properties for enterprise users to route requests through internal API gateways
  • These properties translate to ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL environment variables in the CLI process, with explicit properties taking precedence over the env map
  • Fix ClaudeAgentOptions.environmentVariables not being propagated to the CLI process (dead code)

Closes #25

Changes

File Change
ClaudeAgentProperties.java Add apiKey/baseUrl fields, update buildCLIOptions() to merge into env map
ClaudeAgentOptions.java Add apiKey/baseUrl fields and builder methods
ClaudeAgentModel.java Translate environmentVariables/apiKey/baseUrl into CLIOptions.env
ClaudeAgentAutoConfiguration.java Pass apiKey/baseUrl/env from properties to options builder
Tests 13 new tests covering defaults, setting, precedence, and coexistence

Configuration Example

agent-client:
  claude:
    api-key: "${ANTHROPIC_API_KEY}"
    base-url: "https://proxy.example.com"

Precedence

Explicit apiKey/baseUrl properties > env map entries > system ANTHROPIC_API_KEY

Test Plan

  • Unit tests: ClaudeAgentPropertiesTest (7 new tests), ClaudeAgentModelTest (6 new tests)
  • Integration test verified against third-party Anthropic-compatible endpoint
  • Formatting clean: spring-javaformat:validate passes
  • All 65 existing tests pass

Support custom Anthropic API endpoint and authentication via
agent-client.claude.api-key and agent-client.claude.base-url
properties for enterprise gateway use cases. Also fix environmentVariables
not being propagated to CLI process.
@sunyuhan1998
Copy link
Copy Markdown
Author

Hi @markpollack, would you mind taking a look at this PR when you get a chance? This addresses issue #25 which was previously attempted in #26 but became stale after the SDK rewrite. Thanks!

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.

Support for customizing Anthropic API baseUrl and apiKey

1 participant