@@ -73,7 +73,8 @@ import com.openai.models.ChatModel;
73
73
import com.openai.models.chat.completions.ChatCompletion ;
74
74
import com.openai.models.chat.completions.ChatCompletionCreateParams ;
75
75
76
- // Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
76
+ // Configures using the `openai.apiKey`, `openai.orgId`, `openai.projectId`, `openai.webhookSecret` and `openai.baseUrl` system properties
77
+ // Or configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
77
78
OpenAIClient client = OpenAIOkHttpClient . fromEnv();
78
79
79
80
ChatCompletionCreateParams params = ChatCompletionCreateParams . builder()
@@ -85,13 +86,14 @@ ChatCompletion chatCompletion = client.chat().completions().create(params);
85
86
86
87
## Client configuration
87
88
88
- Configure the client using environment variables:
89
+ Configure the client using system properties or environment variables:
89
90
90
91
``` java
91
92
import com.openai.client.OpenAIClient ;
92
93
import com.openai.client.okhttp.OpenAIOkHttpClient ;
93
94
94
- // Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
95
+ // Configures using the `openai.apiKey`, `openai.orgId`, `openai.projectId`, `openai.webhookSecret` and `openai.baseUrl` system properties
96
+ // Or configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
95
97
OpenAIClient client = OpenAIOkHttpClient . fromEnv();
96
98
```
97
99
@@ -113,21 +115,24 @@ import com.openai.client.OpenAIClient;
113
115
import com.openai.client.okhttp.OpenAIOkHttpClient ;
114
116
115
117
OpenAIClient client = OpenAIOkHttpClient . builder()
116
- // Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
118
+ // Configures using the `openai.apiKey`, `openai.orgId`, `openai.projectId`, `openai.webhookSecret` and `openai.baseUrl` system properties
119
+ Or configures using the `OPENAI_API_KEY `, `OPENAI_ORG_ID `, `OPENAI_PROJECT_ID `, `OPENAI_WEBHOOK_SECRET ` and `OPENAI_BASE_URL ` environment variables
117
120
.fromEnv()
118
121
.apiKey(" My API Key" )
119
122
.build();
120
123
```
121
124
122
125
See this table for the available options:
123
126
124
- | Setter | Environment variable | Required | Default value |
125
- | --------------- | ----------------------- | -------- | ----------------------------- |
126
- | ` apiKey ` | ` OPENAI_API_KEY ` | true | - |
127
- | ` organization ` | ` OPENAI_ORG_ID ` | false | - |
128
- | ` project ` | ` OPENAI_PROJECT_ID ` | false | - |
129
- | ` webhookSecret ` | ` OPENAI_WEBHOOK_SECRET ` | false | - |
130
- | ` baseUrl ` | ` OPENAI_BASE_URL ` | true | ` "https://api.openai.com/v1" ` |
127
+ | Setter | System property | Environment variable | Required | Default value |
128
+ | --------------- | ---------------------- | ----------------------- | -------- | ----------------------------- |
129
+ | ` apiKey ` | ` openai.apiKey ` | ` OPENAI_API_KEY ` | true | - |
130
+ | ` organization ` | ` openai.orgId ` | ` OPENAI_ORG_ID ` | false | - |
131
+ | ` project ` | ` openai.projectId ` | ` OPENAI_PROJECT_ID ` | false | - |
132
+ | ` webhookSecret ` | ` openai.webhookSecret ` | ` OPENAI_WEBHOOK_SECRET ` | false | - |
133
+ | ` baseUrl ` | ` openai.baseUrl ` | ` OPENAI_BASE_URL ` | true | ` "https://api.openai.com/v1" ` |
134
+
135
+ System properties take precedence over environment variables.
131
136
132
137
> [ !TIP]
133
138
> Don't create more than one client in the same application. Each client has a connection pool and
@@ -174,7 +179,8 @@ import com.openai.models.chat.completions.ChatCompletion;
174
179
import com.openai.models.chat.completions.ChatCompletionCreateParams ;
175
180
import java.util.concurrent.CompletableFuture ;
176
181
177
- // Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
182
+ // Configures using the `openai.apiKey`, `openai.orgId`, `openai.projectId`, `openai.webhookSecret` and `openai.baseUrl` system properties
183
+ // Or configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
178
184
OpenAIClient client = OpenAIOkHttpClient . fromEnv();
179
185
180
186
ChatCompletionCreateParams params = ChatCompletionCreateParams . builder()
@@ -194,7 +200,8 @@ import com.openai.models.chat.completions.ChatCompletion;
194
200
import com.openai.models.chat.completions.ChatCompletionCreateParams ;
195
201
import java.util.concurrent.CompletableFuture ;
196
202
197
- // Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
203
+ // Configures using the `openai.apiKey`, `openai.orgId`, `openai.projectId`, `openai.webhookSecret` and `openai.baseUrl` system properties
204
+ // Or configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
198
205
OpenAIClientAsync client = OpenAIOkHttpClientAsync . fromEnv();
199
206
200
207
ChatCompletionCreateParams params = ChatCompletionCreateParams . builder()
0 commit comments