Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public OpenAIChatModel openAIChatModel(
OpenAIProperties properties,
ObjectProvider<OpenAIChatModelBuilderCustomizer> customizerObjectProvider) {
String apiKey = trimToNull(properties.getApiKey());
if (apiKey == null) {
throw new IllegalStateException(
"agentscope.openai.api-key must be configured when OpenAI provider is"
+ " selected");
}

String modelName = trimToNull(properties.getModelName());
if (modelName == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class OpenAIProperties {

/**
* OpenAI API key.
*
* <p>Optional: some OpenAI-compatible providers (for example free model endpoints)
* do not require an API key. Leave unset for those providers.
*/
private String apiKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,30 @@ void shouldNotCreateOpenAIModelWhenDisabled() {
}

@Test
void shouldFailClearlyWhenApiKeyMissing() {
void shouldCreateOpenAIModelWhenApiKeyMissing() {
contextRunner
.withPropertyValues("agentscope.model.provider=openai")
.withPropertyValues(
"agentscope.model.provider=openai",
"agentscope.openai.model-name=gpt-4.1-mini")
.run(
context -> {
assertThat(context).hasSingleBean(Model.class);
assertThat(context).hasSingleBean(OpenAIChatModel.class);
});
}

@Test
void shouldCreateOpenAIModelForApiKeyFreeProvider() {
contextRunner
.withPropertyValues(
"agentscope.model.provider=openai",
"agentscope.openai.model-name=opencode-free-model",
"agentscope.openai.base-url=https://api.opencode.example.com/v1")
.run(
context ->
assertThat(context.getStartupFailure())
.isNotNull()
.hasMessageContaining(
"agentscope.openai.api-key must be configured"));
context -> {
assertThat(context).hasSingleBean(Model.class);
assertThat(context).hasSingleBean(OpenAIChatModel.class);
});
}

@Test
Expand Down
Loading