@@ -73,7 +73,8 @@ import com.openai.models.ChatModel;
7373import com.openai.models.chat.completions.ChatCompletion ;
7474import com.openai.models.chat.completions.ChatCompletionCreateParams ;
7575
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
7778OpenAIClient client = OpenAIOkHttpClient . fromEnv();
7879
7980ChatCompletionCreateParams params = ChatCompletionCreateParams . builder()
@@ -85,13 +86,14 @@ ChatCompletion chatCompletion = client.chat().completions().create(params);
8586
8687## Client configuration
8788
88- Configure the client using environment variables:
89+ Configure the client using system properties or environment variables:
8990
9091``` java
9192import com.openai.client.OpenAIClient ;
9293import com.openai.client.okhttp.OpenAIOkHttpClient ;
9394
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
9597OpenAIClient client = OpenAIOkHttpClient . fromEnv();
9698```
9799
@@ -113,21 +115,24 @@ import com.openai.client.OpenAIClient;
113115import com.openai.client.okhttp.OpenAIOkHttpClient ;
114116
115117OpenAIClient 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
117120 .fromEnv()
118121 .apiKey(" My API Key" )
119122 .build();
120123```
121124
122125See this table for the available options:
123126
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.
131136
132137> [ !TIP]
133138> 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;
174179import com.openai.models.chat.completions.ChatCompletionCreateParams ;
175180import java.util.concurrent.CompletableFuture ;
176181
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
178184OpenAIClient client = OpenAIOkHttpClient . fromEnv();
179185
180186ChatCompletionCreateParams params = ChatCompletionCreateParams . builder()
@@ -194,7 +200,8 @@ import com.openai.models.chat.completions.ChatCompletion;
194200import com.openai.models.chat.completions.ChatCompletionCreateParams ;
195201import java.util.concurrent.CompletableFuture ;
196202
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
198205OpenAIClientAsync client = OpenAIOkHttpClientAsync . fromEnv();
199206
200207ChatCompletionCreateParams params = ChatCompletionCreateParams . builder()
0 commit comments