Skip to content

Commit b2d5ff0

Browse files
sobychackoilayaperumalg
authored andcommitted
GH-3187: Replace Spring environment variables with custom alternatives
Fixes: #3187 This commit addresses the issue with Spring environment variables that directly mirror Spring AI application properties, which can confuse users into thinking they should always set environment variables that match Spring property names. Instead, we've replaced all instances of SPRING_* prefixed environment variables in the documentation with custom-named alternatives that are referenced using Spring Expression Language (SpEL) or retrieved programmatically. Each documentation section now shows multiple configuration approaches: - Direct property setting in application.properties/yml - Using custom environment variables with SpEL - Accessing environment variables programmatically This gives users more flexibility while making it clear that using SPRING_* prefixed environment variables is not required or recommended. Signed-off-by: Soby Chacko <[email protected]>
1 parent c2a6949 commit b2d5ff0

25 files changed

+813
-129
lines changed

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

+33-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,42 @@ Spring AI provides dedicated xref:api/chat/bedrock-converse.adoc[Amazon Bedrock
1010

1111
== Prerequisites
1212

13-
You will need to create an API key on Anthropic portal.
14-
Create an account at https://console.anthropic.com/dashboard[Anthropic API dashboard] and generate the api key on the https://console.anthropic.com/settings/keys[Get API Keys] page.
13+
You will need to create an API key on the Anthropic portal.
14+
15+
Create an account at https://console.anthropic.com/dashboard[Anthropic API dashboard] and generate the API key on the https://console.anthropic.com/settings/keys[Get API Keys] page.
16+
1517
The Spring AI project defines a configuration property named `spring.ai.anthropic.api-key` that you should set to the value of the `API Key` obtained from anthropic.com.
16-
Exporting an environment variable is one way to set that configuration property:
1718

18-
[source,shell]
19+
You can set this configuration property in your `application.properties` file:
20+
21+
[source,properties]
22+
----
23+
spring.ai.anthropic.api-key=<your-anthropic-api-key>
24+
----
25+
26+
For enhanced security when handling sensitive information like API keys, you can use Spring Expression Language (SpEL) to reference a custom environment variable:
27+
28+
[source,yaml]
29+
----
30+
# In application.yml
31+
spring:
32+
ai:
33+
anthropic:
34+
api-key: ${ANTHROPIC_API_KEY}
35+
----
36+
37+
[source,bash]
38+
----
39+
# In your environment or .env file
40+
export ANTHROPIC_API_KEY=<your-anthropic-api-key>
41+
----
42+
43+
You can also set this configuration programmatically in your application code:
44+
45+
[source,java]
1946
----
20-
export SPRING_AI_ANTHROPIC_API_KEY=<INSERT KEY HERE>
47+
// Retrieve API key from a secure source or environment variable
48+
String apiKey = System.getenv("ANTHROPIC_API_KEY");
2149
----
2250

2351
=== Add Repositories and BOM

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

+52-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,35 @@ To access models using an API key, obtain your Azure OpenAI `endpoint` and `api-
1414

1515
Spring AI defines two configuration properties:
1616

17-
1. `spring.ai.azure.openai.api-key`: Set this to the value the `API Key` obtained from Azure.
17+
1. `spring.ai.azure.openai.api-key`: Set this to the value of the `API Key` obtained from Azure.
1818
2. `spring.ai.azure.openai.endpoint`: Set this to the endpoint URL obtained when provisioning your model in Azure.
1919

20-
You can set these configuration properties by exporting environment variables:
20+
You can set these configuration properties in your `application.properties` or `application.yml` file:
2121

22-
[source,shell]
22+
[source,properties]
2323
----
24-
export SPRING_AI_AZURE_OPENAI_API_KEY=<INSERT AZURE KEY HERE>
25-
export SPRING_AI_AZURE_OPENAI_ENDPOINT=<INSERT ENDPOINT URL HERE>
24+
spring.ai.azure.openai.api-key=<your-azure-api-key>
25+
spring.ai.azure.openai.endpoint=<your-azure-endpoint-url>
26+
----
27+
28+
For enhanced security when handling sensitive information like API keys, you can use Spring Expression Language (SpEL) to reference custom environment variables:
29+
30+
[source,yaml]
31+
----
32+
# In application.yml
33+
spring:
34+
ai:
35+
azure:
36+
openai:
37+
api-key: ${AZURE_OPENAI_API_KEY}
38+
endpoint: ${AZURE_OPENAI_ENDPOINT}
39+
----
40+
41+
[source,bash]
42+
----
43+
# In your environment or .env file
44+
export AZURE_OPENAI_API_KEY=<your-azure-openai-api-key>
45+
export AZURE_OPENAI_ENDPOINT=<your-azure-openai-endpoint-url>
2646
----
2747

2848
=== OpenAI Key
@@ -31,9 +51,34 @@ To authenticate with the OpenAI service (not Azure), provide an OpenAI API key.
3151

3252
When using this approach, set the `spring.ai.azure.openai.chat.options.deployment-name` property to the name of the https://platform.openai.com/docs/models[OpenAI model] you wish to use.
3353

34-
[source,shell]
54+
In your application configuration:
55+
56+
[source,properties]
57+
----
58+
spring.ai.azure.openai.openai-api-key=<your-azure-openai-key>
59+
spring.ai.azure.openai.chat.options.deployment-name=<openai-model-name>
60+
----
61+
62+
Using environment variables with SpEL:
63+
64+
[source,yaml]
65+
----
66+
# In application.yml
67+
spring:
68+
ai:
69+
azure:
70+
openai:
71+
openai-api-key: ${AZURE_OPENAI_API_KEY}
72+
chat:
73+
options:
74+
deployment-name: ${AZURE_OPENAI_MODEL_NAME}
75+
----
76+
77+
[source,bash]
3578
----
36-
export SPRING_AI_AZURE_OPENAI_OPENAI_API_KEY=<INSERT OPENAI KEY HERE>
79+
# In your environment or .env file
80+
export AZURE_OPENAI_API_KEY=<your-openai-key>
81+
export AZURE_OPENAI_MODEL_NAME=<openai-model-name>
3782
----
3883

3984
=== Microsoft Entra ID

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

+32-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,41 @@ Spring AI supports the various AI language models from DeepSeek. You can interac
55
== Prerequisites
66

77
You will need to create an API key with DeepSeek to access DeepSeek language models.
8+
89
Create an account at https://platform.deepseek.com/sign_up[DeepSeek registration page] and generate a token on the https://platform.deepseek.com/api_keys[API Keys page].
9-
The Spring AI project defines a configuration property named `spring.ai.deepseek.api-key` that you should set to the value of the `API Key` obtained from the https://platform.deepseek.com/api_keys[API Keys page].
10-
Exporting an environment variable is one way to set this configuration property:
1110

12-
[source,shell]
11+
The Spring AI project defines a configuration property named `spring.ai.deepseek.api-key` that you should set to the value of the `API Key` obtained from the API Keys page.
12+
13+
You can set this configuration property in your `application.properties` file:
14+
15+
[source,properties]
16+
----
17+
spring.ai.deepseek.api-key=<your-deepseek-api-key>
18+
----
19+
20+
For enhanced security when handling sensitive information like API keys, you can use Spring Expression Language (SpEL) to reference a custom environment variable:
21+
22+
[source,yaml]
23+
----
24+
# In application.yml
25+
spring:
26+
ai:
27+
deepseek:
28+
api-key: ${DEEPSEEK_API_KEY}
29+
----
30+
31+
[source,bash]
32+
----
33+
# In your environment or .env file
34+
export DEEPSEEK_API_KEY=<your-deepseek-api-key>
35+
----
36+
37+
You can also set this configuration programmatically in your application code:
38+
39+
[source,java]
1340
----
14-
export SPRING_AI_DEEPSEEK_API_KEY=<INSERT KEY HERE>
41+
// Retrieve API key from a secure source or environment variable
42+
String apiKey = System.getenv("DEEPSEEK_API_KEY");
1543
----
1644

1745
=== Add Repositories and BOM

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

+44-10
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,55 @@ for examples of using Groq with Spring AI.
1818

1919
== Prerequisites
2020

21-
* Create an API Key.
22-
Please visit https://console.groq.com/keys[here] to create an API Key.
21+
* **Create an API Key**:
22+
Visit https://console.groq.com/keys[here] to create an API Key.
2323
The Spring AI project defines a configuration property named `spring.ai.openai.api-key` that you should set to the value of the `API Key` obtained from groq.com.
24-
* Set the Groq URL.
24+
25+
* **Set the Groq URL**:
2526
You have to set the `spring.ai.openai.base-url` property to `https://api.groq.com/openai`.
26-
* Select a https://console.groq.com/docs/models[Groq Model].
27-
Use the `spring.ai.openai.chat.options.model=<model name>` property to set the Model.
2827

29-
Exporting an environment variable is one way to set that configuration property:
28+
* **Select a Groq Model**:
29+
Use the `spring.ai.openai.chat.model=<model name>` property to select from the available https://console.groq.com/docs/models[Groq Models].
30+
31+
You can set these configuration properties in your `application.properties` file:
32+
33+
[source,properties]
34+
----
35+
spring.ai.openai.api-key=<your-groq-api-key>
36+
spring.ai.openai.base-url=https://api.groq.com/openai
37+
spring.ai.openai.chat.model=llama3-70b-8192
38+
----
39+
40+
For enhanced security when handling sensitive information like API keys, you can use Spring Expression Language (SpEL) to reference custom environment variables:
3041

31-
[source,shell]
42+
[source,yaml]
43+
----
44+
# In application.yml
45+
spring:
46+
ai:
47+
openai:
48+
api-key: ${GROQ_API_KEY}
49+
base-url: ${GROQ_BASE_URL}
50+
chat:
51+
model: ${GROQ_MODEL}
52+
----
53+
54+
[source,bash]
55+
----
56+
# In your environment or .env file
57+
export GROQ_API_KEY=<your-groq-api-key>
58+
export GROQ_BASE_URL=https://api.groq.com/openai
59+
export GROQ_MODEL=llama3-70b-8192
60+
----
61+
62+
You can also set these configurations programmatically in your application code:
63+
64+
[source,java]
3265
----
33-
export SPRING_AI_OPENAI_API_KEY=<INSERT GROQ API KEY HERE>
34-
export SPRING_AI_OPENAI_BASE_URL=https://api.groq.com/openai
35-
export SPRING_AI_OPENAI_CHAT_MODEL=llama3-70b-8192
66+
// Retrieve configuration from secure sources or environment variables
67+
String apiKey = System.getenv("GROQ_API_KEY");
68+
String baseUrl = System.getenv("GROQ_BASE_URL");
69+
String model = System.getenv("GROQ_MODEL");
3670
----
3771

3872
=== Add Repositories and BOM

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

+41-7
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,49 @@ TIP: For a complete and up-to-date list of supported models and architectures, s
1010

1111
You will need to create an Inference Endpoint on Hugging Face and create an API token to access the endpoint.
1212
Further details can be found link:https://huggingface.co/docs/inference-endpoints/index[here].
13-
The Spring AI project defines a configuration property named `spring.ai.huggingface.chat.api-key` that you should set to the value of the API token obtained from Hugging Face.
14-
There is also a configuration property named `spring.ai.huggingface.chat.url` that you should set to the inference endpoint URL obtained when provisioning your model in Hugging Face.
15-
You can find this on the Inference Endpoint's UI link:https://ui.endpoints.huggingface.co/[here].
16-
Exporting environment variables is one way to set these configuration properties:
1713

18-
[source,shell]
14+
The Spring AI project defines two configuration properties:
15+
16+
1. `spring.ai.huggingface.chat.api-key`: Set this to the value of the API token obtained from Hugging Face.
17+
2. `spring.ai.huggingface.chat.url`: Set this to the inference endpoint URL obtained when provisioning your model in Hugging Face.
18+
19+
You can find your inference endpoint URL on the Inference Endpoint's UI link:https://ui.endpoints.huggingface.co/[here].
20+
21+
You can set these configuration properties in your `application.properties` file:
22+
23+
[source,properties]
24+
----
25+
spring.ai.huggingface.chat.api-key=<your-huggingface-api-key>
26+
spring.ai.huggingface.chat.url=<your-inference-endpoint-url>
27+
----
28+
29+
For enhanced security when handling sensitive information like API keys, you can use Spring Expression Language (SpEL) to reference custom environment variables:
30+
31+
[source,yaml]
32+
----
33+
# In application.yml
34+
spring:
35+
ai:
36+
huggingface:
37+
chat:
38+
api-key: ${HUGGINGFACE_API_KEY}
39+
url: ${HUGGINGFACE_ENDPOINT_URL}
40+
----
41+
42+
[source,bash]
43+
----
44+
# In your environment or .env file
45+
export HUGGINGFACE_API_KEY=<your-huggingface-api-key>
46+
export HUGGINGFACE_ENDPOINT_URL=<your-inference-endpoint-url>
47+
----
48+
49+
You can also set these configurations programmatically in your application code:
50+
51+
[source,java]
1952
----
20-
export SPRING_AI_HUGGINGFACE_CHAT_API_KEY=<INSERT KEY HERE>
21-
export SPRING_AI_HUGGINGFACE_CHAT_URL=<INSERT INFERENCE ENDPOINT URL HERE>
53+
// Retrieve API key and endpoint URL from secure sources or environment variables
54+
String apiKey = System.getenv("HUGGINGFACE_API_KEY");
55+
String endpointUrl = System.getenv("HUGGINGFACE_ENDPOINT_URL");
2256
----
2357

2458
=== Add Repositories and BOM

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

+32-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,39 @@ Spring AI supports the various AI language models from MiniMax. You can interact
77
You will need to create an API with MiniMax to access MiniMax language models.
88

99
Create an account at https://www.minimaxi.com/login[MiniMax registration page] and generate the token on the https://www.minimaxi.com/user-center/basic-information/interface-key[API Keys page].
10-
The Spring AI project defines a configuration property named `spring.ai.minimax.api-key` that you should set to the value of the `API Key` obtained from https://www.minimaxi.com/user-center/basic-information/interface-key[API Keys page].
11-
Exporting an environment variable is one way to set that configuration property:
1210

13-
[source,shell]
11+
The Spring AI project defines a configuration property named `spring.ai.minimax.api-key` that you should set to the value of the `API Key` obtained from the API Keys page.
12+
13+
You can set this configuration property in your `application.properties` file:
14+
15+
[source,properties]
16+
----
17+
spring.ai.minimax.api-key=<your-minimax-api-key>
18+
----
19+
20+
For enhanced security when handling sensitive information like API keys, you can use Spring Expression Language (SpEL) to reference an environment variable:
21+
22+
[source,yaml]
23+
----
24+
# In application.yml
25+
spring:
26+
ai:
27+
minimax:
28+
api-key: ${MINIMAX_API_KEY}
29+
----
30+
31+
[source,bash]
32+
----
33+
# In your environment or .env file
34+
export MINIMAX_API_KEY=<your-minimax-api-key>
35+
----
36+
37+
You can also set this configuration programmatically in your application code:
38+
39+
[source,java]
1440
----
15-
export SPRING_AI_MINIMAX_API_KEY=<INSERT KEY HERE>
41+
// Retrieve API key from a secure source or environment variable
42+
String apiKey = System.getenv("MINIMAX_API_KEY");
1643
----
1744

1845
=== Add Repositories and BOM
@@ -298,4 +325,4 @@ Flux<ChatResponse> streamResponse = chatModel.stream(new Prompt(this.messages, t
298325
==== MiniMaxApi Samples
299326
* The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiIT.java[MiniMaxApiIT.java] test provides some general examples how to use the lightweight library.
300327

301-
* The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiToolFunctionCallIT.java[MiniMaxApiToolFunctionCallIT.java] test shows how to use the low-level API to call tool functions.>
328+
* The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiToolFunctionCallIT.java[MiniMaxApiToolFunctionCallIT.java] test shows how to use the low-level API to call tool functions.>

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

+31-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,41 @@ Check the xref:_openai_api_compatibility[OpenAI API compatibility] section to le
88
== Prerequisites
99

1010
You will need to create an API with Mistral AI to access Mistral AI language models.
11+
1112
Create an account at https://auth.mistral.ai/ui/registration[Mistral AI registration page] and generate the token on the https://console.mistral.ai/api-keys/[API Keys page].
13+
1214
The Spring AI project defines a configuration property named `spring.ai.mistralai.api-key` that you should set to the value of the `API Key` obtained from console.mistral.ai.
13-
Exporting an environment variable is one way to set that configuration property:
1415

15-
[source,shell]
16+
You can set this configuration property in your `application.properties` file:
17+
18+
[source,properties]
19+
----
20+
spring.ai.mistralai.api-key=<your-mistralai-api-key>
21+
----
22+
23+
For enhanced security when handling sensitive information like API keys, you can use Spring Expression Language (SpEL) to reference a custom environment variable:
24+
25+
[source,yaml]
26+
----
27+
# In application.yml
28+
spring:
29+
ai:
30+
mistralai:
31+
api-key: ${MISTRALAI_API_KEY}
32+
----
33+
34+
[source,bash]
35+
----
36+
# In your environment or .env file
37+
export MISTRALAI_API_KEY=<your-mistralai-api-key>
38+
----
39+
40+
You can also set this configuration programmatically in your application code:
41+
42+
[source,java]
1643
----
17-
export SPRING_AI_MISTRALAI_API_KEY=<INSERT KEY HERE>
44+
// Retrieve API key from a secure source or environment variable
45+
String apiKey = System.getenv("MISTRALAI_API_KEY");
1846
----
1947

2048
=== Add Repositories and BOM

0 commit comments

Comments
 (0)