Skip to content

fix(openai): make api-key optional for OpenAI#2175

Open
ningmeng0503 wants to merge 1 commit into
agentscope-ai:mainfrom
ningmeng0503:fix/openai-api-key-optional-free-providers
Open

fix(openai): make api-key optional for OpenAI#2175
ningmeng0503 wants to merge 1 commit into
agentscope-ai:mainfrom
ningmeng0503:fix/openai-api-key-optional-free-providers

Conversation

@ningmeng0503

Copy link
Copy Markdown
Contributor

Some OpenAI-compatible providers (e.g., free model endpoints such as opencode) do not require an API key. The current OpenAIAutoConfiguration throws an IllegalStateException at startup when
agentscope.openai.api-key is missing, which prevents these providers from being used.

This change removes the mandatory API key check from the auto-configuration. The underlying OpenAIClient already handles a missing key gracefully by omitting the Authorization header, so runtime
behavior remains correct for providers that do require authentication.

Changes:

  • OpenAIAutoConfiguration: removed the apiKey == null startup validation.
  • OpenAIProperties: updated Javadoc to clarify that api-key is optional for API-key-free providers.
  • OpenAIAutoConfigurationTest: replaced the "must fail when API key missing" test with tests that verify the model is created successfully without an API key, including a free-provider scenario with
    a custom base-url.

…patible providers

Some free OpenAI-compatible providers (e.g., opencode free models) do not require an API key. Remove the mandatory startup check so the auto-configuration can create the OpenAIChatModel without an api-key property.
@ningmeng0503 ningmeng0503 requested a review from a team July 13, 2026 10:45
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/ext/spring-boot Spring Boot starters labels Jul 14, 2026

@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

This PR makes the OpenAI API key optional in the Spring Boot auto-configuration, enabling use with free/no-auth OpenAI-compatible providers (e.g., opencode). The change is minimal (+25/-12, 3 files) and well-scoped: it removes the IllegalStateException thrown when agentscope.openai.api-key is missing, updates the Javadoc, and adjusts tests to reflect the new behavior.

The PR description is accurate — the downstream OpenAIClient.buildHeaders() (line 541) already handles null apiKey gracefully by omitting the Authorization header.

The change is backwards-compatible: existing configurations with API keys work identically.


@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

This PR makes the OpenAI API key optional in the Spring Boot auto-configuration, enabling use with free/no-auth OpenAI-compatible providers (e.g., opencode). The change is minimal (+25/-12, 3 files) and well-scoped: it removes the IllegalStateException thrown when agentscope.openai.api-key is missing, updates the Javadoc, and adjusts tests to reflect the new behavior.

The PR description is accurate — the downstream OpenAIClient.buildHeaders() (line 541) already handles null apiKey gracefully by omitting the Authorization header.

The change is backwards-compatible: existing configurations with API keys work identically.


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

Labels

area/ext/spring-boot Spring Boot starters bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants