Skip to content

Commit 79859a1

Browse files
feat(api): webhook and deep research support
1 parent da7f492 commit 79859a1

File tree

76 files changed

+13483
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+13483
-365
lines changed

.github/workflows/detect-breaking-changes.yml

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

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 86
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-ef4ecb19eb61e24c49d77fef769ee243e5279bc0bdbaee8d0f8dba4da8722559.yml
3-
openapi_spec_hash: 1b8a9767c9f04e6865b06c41948cdc24
4-
config_hash: cae2d1f187b5b9f8dfa00daa807da42a
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-cca460eaf5cc13e9d6e5293eb97aac53d66dc1385c691f74b768c97d165b6e8b.yml
3+
openapi_spec_hash: 9ec43d443b3dd58ca5aa87eb0a7eb49f
4+
config_hash: e74d6791681e3af1b548748ff47a22c2

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import com.openai.models.ChatModel;
7373
import com.openai.models.chat.completions.ChatCompletion;
7474
import com.openai.models.chat.completions.ChatCompletionCreateParams;
7575

76-
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID` and `OPENAI_BASE_URL` environment variables
76+
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
7777
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
7878

7979
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
@@ -91,7 +91,7 @@ Configure the client using environment variables:
9191
import com.openai.client.OpenAIClient;
9292
import com.openai.client.okhttp.OpenAIOkHttpClient;
9393

94-
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID` and `OPENAI_BASE_URL` environment variables
94+
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
9595
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
9696
```
9797

@@ -113,20 +113,21 @@ import com.openai.client.OpenAIClient;
113113
import com.openai.client.okhttp.OpenAIOkHttpClient;
114114

115115
OpenAIClient client = OpenAIOkHttpClient.builder()
116-
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID` and `OPENAI_BASE_URL` environment variables
116+
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
117117
.fromEnv()
118118
.apiKey("My API Key")
119119
.build();
120120
```
121121

122122
See this table for the available options:
123123

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-
| `baseUrl` | `OPENAI_BASE_URL` | true | `"https://api.openai.com/v1"` |
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"` |
130131

131132
> [!TIP]
132133
> Don't create more than one client in the same application. Each client has a connection pool and
@@ -173,7 +174,7 @@ import com.openai.models.chat.completions.ChatCompletion;
173174
import com.openai.models.chat.completions.ChatCompletionCreateParams;
174175
import java.util.concurrent.CompletableFuture;
175176

176-
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID` and `OPENAI_BASE_URL` environment variables
177+
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
177178
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
178179

179180
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
@@ -193,7 +194,7 @@ import com.openai.models.chat.completions.ChatCompletion;
193194
import com.openai.models.chat.completions.ChatCompletionCreateParams;
194195
import java.util.concurrent.CompletableFuture;
195196

196-
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID` and `OPENAI_BASE_URL` environment variables
197+
// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID`, `OPENAI_WEBHOOK_SECRET` and `OPENAI_BASE_URL` environment variables
197198
OpenAIClientAsync client = OpenAIOkHttpClientAsync.fromEnv();
198199

199200
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()

openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ class OpenAIOkHttpClient private constructor() {
176176
/** Alias for calling [Builder.project] with `project.orElse(null)`. */
177177
fun project(project: Optional<String>) = project(project.getOrNull())
178178

179+
fun webhookSecret(webhookSecret: String?) = apply {
180+
clientOptions.webhookSecret(webhookSecret)
181+
}
182+
183+
/** Alias for calling [Builder.webhookSecret] with `webhookSecret.orElse(null)`. */
184+
fun webhookSecret(webhookSecret: Optional<String>) =
185+
webhookSecret(webhookSecret.getOrNull())
186+
179187
fun fromEnv() = apply { clientOptions.fromEnv() }
180188

181189
/**

openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ class OpenAIOkHttpClientAsync private constructor() {
176176
/** Alias for calling [Builder.project] with `project.orElse(null)`. */
177177
fun project(project: Optional<String>) = project(project.getOrNull())
178178

179+
fun webhookSecret(webhookSecret: String?) = apply {
180+
clientOptions.webhookSecret(webhookSecret)
181+
}
182+
183+
/** Alias for calling [Builder.webhookSecret] with `webhookSecret.orElse(null)`. */
184+
fun webhookSecret(webhookSecret: Optional<String>) =
185+
webhookSecret(webhookSecret.getOrNull())
186+
179187
fun fromEnv() = apply { clientOptions.fromEnv() }
180188

181189
/**

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.openai.services.blocking.ModerationService
2020
import com.openai.services.blocking.ResponseService
2121
import com.openai.services.blocking.UploadService
2222
import com.openai.services.blocking.VectorStoreService
23+
import com.openai.services.blocking.WebhookService
2324
import java.util.function.Consumer
2425

2526
/**
@@ -80,6 +81,8 @@ interface OpenAIClient {
8081

8182
fun vectorStores(): VectorStoreService
8283

84+
fun webhooks(): WebhookService
85+
8386
fun beta(): BetaService
8487

8588
fun batches(): BatchService
@@ -137,6 +140,8 @@ interface OpenAIClient {
137140

138141
fun vectorStores(): VectorStoreService.WithRawResponse
139142

143+
fun webhooks(): WebhookService.WithRawResponse
144+
140145
fun beta(): BetaService.WithRawResponse
141146

142147
fun batches(): BatchService.WithRawResponse

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.openai.services.async.ModerationServiceAsync
2020
import com.openai.services.async.ResponseServiceAsync
2121
import com.openai.services.async.UploadServiceAsync
2222
import com.openai.services.async.VectorStoreServiceAsync
23+
import com.openai.services.async.WebhookServiceAsync
2324
import java.util.function.Consumer
2425

2526
/**
@@ -80,6 +81,8 @@ interface OpenAIClientAsync {
8081

8182
fun vectorStores(): VectorStoreServiceAsync
8283

84+
fun webhooks(): WebhookServiceAsync
85+
8386
fun beta(): BetaServiceAsync
8487

8588
fun batches(): BatchServiceAsync
@@ -139,6 +142,8 @@ interface OpenAIClientAsync {
139142

140143
fun vectorStores(): VectorStoreServiceAsync.WithRawResponse
141144

145+
fun webhooks(): WebhookServiceAsync.WithRawResponse
146+
142147
fun beta(): BetaServiceAsync.WithRawResponse
143148

144149
fun batches(): BatchServiceAsync.WithRawResponse

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import com.openai.services.async.UploadServiceAsync
3838
import com.openai.services.async.UploadServiceAsyncImpl
3939
import com.openai.services.async.VectorStoreServiceAsync
4040
import com.openai.services.async.VectorStoreServiceAsyncImpl
41+
import com.openai.services.async.WebhookServiceAsync
42+
import com.openai.services.async.WebhookServiceAsyncImpl
4143
import java.util.function.Consumer
4244

4345
class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAIClientAsync {
@@ -97,6 +99,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
9799
VectorStoreServiceAsyncImpl(clientOptionsWithUserAgent)
98100
}
99101

102+
private val webhooks: WebhookServiceAsync by lazy {
103+
WebhookServiceAsyncImpl(clientOptionsWithUserAgent)
104+
}
105+
100106
private val beta: BetaServiceAsync by lazy { BetaServiceAsyncImpl(clientOptionsWithUserAgent) }
101107

102108
private val batches: BatchServiceAsync by lazy {
@@ -146,6 +152,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
146152

147153
override fun vectorStores(): VectorStoreServiceAsync = vectorStores
148154

155+
override fun webhooks(): WebhookServiceAsync = webhooks
156+
149157
override fun beta(): BetaServiceAsync = beta
150158

151159
override fun batches(): BatchServiceAsync = batches
@@ -207,6 +215,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
207215
VectorStoreServiceAsyncImpl.WithRawResponseImpl(clientOptions)
208216
}
209217

218+
private val webhooks: WebhookServiceAsync.WithRawResponse by lazy {
219+
WebhookServiceAsyncImpl.WithRawResponseImpl(clientOptions)
220+
}
221+
210222
private val beta: BetaServiceAsync.WithRawResponse by lazy {
211223
BetaServiceAsyncImpl.WithRawResponseImpl(clientOptions)
212224
}
@@ -260,6 +272,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
260272

261273
override fun vectorStores(): VectorStoreServiceAsync.WithRawResponse = vectorStores
262274

275+
override fun webhooks(): WebhookServiceAsync.WithRawResponse = webhooks
276+
263277
override fun beta(): BetaServiceAsync.WithRawResponse = beta
264278

265279
override fun batches(): BatchServiceAsync.WithRawResponse = batches

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import com.openai.services.blocking.UploadService
3838
import com.openai.services.blocking.UploadServiceImpl
3939
import com.openai.services.blocking.VectorStoreService
4040
import com.openai.services.blocking.VectorStoreServiceImpl
41+
import com.openai.services.blocking.WebhookService
42+
import com.openai.services.blocking.WebhookServiceImpl
4143
import java.util.function.Consumer
4244

4345
class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient {
@@ -89,6 +91,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
8991
VectorStoreServiceImpl(clientOptionsWithUserAgent)
9092
}
9193

94+
private val webhooks: WebhookService by lazy { WebhookServiceImpl(clientOptionsWithUserAgent) }
95+
9296
private val beta: BetaService by lazy { BetaServiceImpl(clientOptionsWithUserAgent) }
9397

9498
private val batches: BatchService by lazy { BatchServiceImpl(clientOptionsWithUserAgent) }
@@ -134,6 +138,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
134138

135139
override fun vectorStores(): VectorStoreService = vectorStores
136140

141+
override fun webhooks(): WebhookService = webhooks
142+
137143
override fun beta(): BetaService = beta
138144

139145
override fun batches(): BatchService = batches
@@ -195,6 +201,10 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
195201
VectorStoreServiceImpl.WithRawResponseImpl(clientOptions)
196202
}
197203

204+
private val webhooks: WebhookService.WithRawResponse by lazy {
205+
WebhookServiceImpl.WithRawResponseImpl(clientOptions)
206+
}
207+
198208
private val beta: BetaService.WithRawResponse by lazy {
199209
BetaServiceImpl.WithRawResponseImpl(clientOptions)
200210
}
@@ -248,6 +258,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
248258

249259
override fun vectorStores(): VectorStoreService.WithRawResponse = vectorStores
250260

261+
override fun webhooks(): WebhookService.WithRawResponse = webhooks
262+
251263
override fun beta(): BetaService.WithRawResponse = beta
252264

253265
override fun batches(): BatchService.WithRawResponse = batches

openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private constructor(
3838
@get:JvmName("azureServiceVersion") val azureServiceVersion: AzureOpenAIServiceVersion?,
3939
private val organization: String?,
4040
private val project: String?,
41+
private val webhookSecret: String?,
4142
) {
4243

4344
init {
@@ -52,6 +53,8 @@ private constructor(
5253

5354
fun project(): Optional<String> = Optional.ofNullable(project)
5455

56+
fun webhookSecret(): Optional<String> = Optional.ofNullable(webhookSecret)
57+
5558
fun toBuilder() = Builder().from(this)
5659

5760
companion object {
@@ -90,6 +93,7 @@ private constructor(
9093
private var azureServiceVersion: AzureOpenAIServiceVersion? = null
9194
private var organization: String? = null
9295
private var project: String? = null
96+
private var webhookSecret: String? = null
9397

9498
@JvmSynthetic
9599
internal fun from(clientOptions: ClientOptions) = apply {
@@ -108,6 +112,7 @@ private constructor(
108112
azureServiceVersion = clientOptions.azureServiceVersion
109113
organization = clientOptions.organization
110114
project = clientOptions.project
115+
webhookSecret = clientOptions.webhookSecret
111116
}
112117

113118
fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient }
@@ -157,6 +162,12 @@ private constructor(
157162
/** Alias for calling [Builder.project] with `project.orElse(null)`. */
158163
fun project(project: Optional<String>) = project(project.getOrNull())
159164

165+
fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret }
166+
167+
/** Alias for calling [Builder.webhookSecret] with `webhookSecret.orElse(null)`. */
168+
fun webhookSecret(webhookSecret: Optional<String>) =
169+
webhookSecret(webhookSecret.getOrNull())
170+
160171
fun headers(headers: Headers) = apply {
161172
this.headers.clear()
162173
putAllHeaders(headers)
@@ -239,6 +250,12 @@ private constructor(
239250

240251
fun fromEnv() = apply {
241252
System.getenv("OPENAI_BASE_URL")?.let { baseUrl(it) }
253+
<<<<<<< generated--merge-conflict
254+
System.getenv("OPENAI_API_KEY")?.let { apiKey(it) }
255+
System.getenv("OPENAI_ORG_ID")?.let { organization(it) }
256+
System.getenv("OPENAI_PROJECT_ID")?.let { project(it) }
257+
System.getenv("OPENAI_WEBHOOK_SECRET")?.let { webhookSecret(it) }
258+
=======
242259
val openAIKey = System.getenv("OPENAI_API_KEY")
243260
val openAIOrgId = System.getenv("OPENAI_ORG_ID")
244261
val openAIProjectId = System.getenv("OPENAI_PROJECT_ID")
@@ -259,6 +276,7 @@ private constructor(
259276
credential(AzureApiKeyCredential.create(azureOpenAIKey))
260277
}
261278
}
279+
>>>>>>> integrated--merge-conflict
262280
}
263281

264282
/**
@@ -354,6 +372,7 @@ private constructor(
354372
azureServiceVersion,
355373
organization,
356374
project,
375+
webhookSecret,
357376
)
358377
}
359378
}

0 commit comments

Comments
 (0)