Skip to content

Commit c499e24

Browse files
committed
update docs, remove extra test annotation
1 parent d126499 commit c499e24

File tree

2 files changed

+15
-50
lines changed
  • spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat
  • spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai

2 files changed

+15
-50
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -566,24 +566,25 @@ spring.ai.openai.api-key=your-api-key-here
566566

567567
=== Custom API Key Configuration
568568

569-
You can provide your own `ApiKey` implementation by creating a bean with the `@OpenAiApiKey` qualifier:
569+
You can create a custom instance of `OpenAiApi` with your own `ApiKey` implementation using the builder pattern:
570570

571571
[source,java]
572572
----
573-
@Configuration
574-
class OpenAiConfig {
575-
@Bean
576-
@OpenAiApiKey
577-
public ApiKey customOpenAiKey() {
578-
return new ApiKey() {
579-
@Override
580-
public String getValue() {
581-
// Custom logic to retrieve API key
582-
return "your-api-key-here";
583-
}
584-
};
573+
ApiKey customApiKey = new ApiKey() {
574+
@Override
575+
public String getValue() {
576+
// Custom logic to retrieve API key
577+
return "your-api-key-here";
585578
}
586-
}
579+
};
580+
581+
OpenAiApi openAiApi = OpenAiApi.builder()
582+
.apiKey(customApiKey)
583+
.build();
584+
585+
// Create a chat client with the custom OpenAiApi instance
586+
OpenAiChatClient chatClient = new OpenAiChatClient(openAiApi);
587+
587588
----
588589

589590
This is useful when you need to:
@@ -592,4 +593,3 @@ This is useful when you need to:
592593
* Rotate API keys dynamically
593594
* Implement custom API key selection logic
594595

595-
NOTE: If you provide multiple `ApiKey` beans, make sure to use the `@OpenAiApiKey` qualifier to specify which one should be used for OpenAI operations. Without proper qualification, Spring will fail to start due to ambiguous bean definitions.

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/OtherApiKey.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)