Skip to content

Commit cdf6cd1

Browse files
release: 0.31.0 (#260)
* docs: update URLs from stainlessapi.com to stainless.com (#259) More details at https://www.stainless.com/changelog/stainless-com * chore(internal): refactor `ErrorHandlingTest` (#264) * feat(client): allow configuring timeouts granularly (#266) Note that previously the `timeout(Duration)` method on the client and `RequestOptions` corresponded to connect, read, write, and request timeout. Now it only corresponds to the request timeout. Use the new `timeout(Timeout)` method to configure other timeout values granularly. * feat(client): add file upload endpoints (#268) chore(client)!: refactor multipart formdata impl chore(internal): move `HttpRequestBodies` file chore(internal): extract function for checking for lists in json fields # Migration 1. Builder methods that used to take `contentType` and `filename` as positional parameters after the main argument now no longer do. To set a custom `contentType` or `filename`, pass `MultipartField`, which can be constructed via `MultipartField.builder()`. 2. It's unlikely you were referencing it, but `MultipartFormValue` is now called `MultipartField` if you were. * docs: add raw response readme documentation (#269) * chore(internal): run example files in CI (#271) * release: 0.31.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent 21a2374 commit cdf6cd1

File tree

219 files changed

+18362
-5526
lines changed

Some content is hidden

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

219 files changed

+18362
-5526
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,25 @@ jobs:
5353

5454
- name: Run tests
5555
run: ./scripts/test
56+
examples:
57+
name: examples
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- name: Set up Java
64+
uses: actions/setup-java@v4
65+
with:
66+
distribution: temurin
67+
java-version: |
68+
8
69+
17
70+
cache: gradle
71+
- name: Set up Gradle
72+
uses: gradle/gradle-build-action@v2
5673

74+
- env:
75+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
76+
run: |
77+
./gradlew :openai-java-example:run

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.30.0"
2+
".": "0.31.0"
33
}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 65
1+
configured_endpoints: 72
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-5d30684c3118d049682ea30cdb4dbef39b97d51667da484689193dc40162af32.yml

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
## 0.31.0 (2025-03-04)
4+
5+
Full Changelog: [v0.30.0...v0.31.0](https://github.com/openai/openai-java/compare/v0.30.0...v0.31.0)
6+
7+
### Features
8+
9+
* **client:** add file upload endpoints ([#268](https://github.com/openai/openai-java/issues/268)) ([456274d](https://github.com/openai/openai-java/commit/456274d2dc572ad4711d2fc3640c7e01aa08f4b8))
10+
* **client:** allow configuring timeouts granularly ([#266](https://github.com/openai/openai-java/issues/266)) ([c3bc6e4](https://github.com/openai/openai-java/commit/c3bc6e4fb9717c7f6146f864ce3cc2451619c9f0))
11+
12+
13+
### Chores
14+
15+
* **internal:** refactor `ErrorHandlingTest` ([#264](https://github.com/openai/openai-java/issues/264)) ([2472f85](https://github.com/openai/openai-java/commit/2472f859b49f49cf14539e787cf15e8f863f5dac))
16+
* **internal:** run example files in CI ([#271](https://github.com/openai/openai-java/issues/271)) ([8da7851](https://github.com/openai/openai-java/commit/8da785184c3e039ea4b9d2b26c6d14b607291750))
17+
18+
19+
### Documentation
20+
21+
* add raw response readme documentation ([#269](https://github.com/openai/openai-java/issues/269)) ([2839903](https://github.com/openai/openai-java/commit/28399031c60eed8899475c5d1d38677c2eaa2284))
22+
* update URLs from stainlessapi.com to stainless.com ([#259](https://github.com/openai/openai-java/issues/259)) ([b824bf3](https://github.com/openai/openai-java/commit/b824bf39a44251e15c7c8b5b14bc6cbf9133dff5))
23+
324
## 0.30.0 (2025-02-27)
425

526
Full Changelog: [v0.29.0...v0.30.0](https://github.com/openai/openai-java/compare/v0.29.0...v0.30.0)

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
1010
<!-- x-release-please-start-version -->
1111

12-
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.30.0)
13-
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.30.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.30.0)
12+
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.31.0)
13+
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.31.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.31.0)
1414

1515
<!-- x-release-please-end -->
1616

@@ -25,7 +25,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
2525
### Gradle
2626

2727
```kotlin
28-
implementation("com.openai:openai-java:0.30.0")
28+
implementation("com.openai:openai-java:0.31.0")
2929
```
3030

3131
### Maven
@@ -34,7 +34,7 @@ implementation("com.openai:openai-java:0.30.0")
3434
<dependency>
3535
<groupId>com.openai</groupId>
3636
<artifactId>openai-java</artifactId>
37-
<version>0.30.0</version>
37+
<version>0.31.0</version>
3838
</dependency>
3939
```
4040

@@ -314,6 +314,37 @@ try (HttpResponse response = client.files().content(params)) {
314314
}
315315
```
316316

317+
## Raw responses
318+
319+
The SDK defines methods that deserialize responses into instances of Java classes. However, these methods don't provide access to the response headers, status code, or the raw response body.
320+
321+
To access this data, prefix any HTTP method call on a client or service with `withRawResponse()`:
322+
323+
```java
324+
import com.openai.core.http.Headers;
325+
import com.openai.core.http.HttpResponseFor;
326+
import com.openai.models.ChatCompletion;
327+
import com.openai.models.ChatCompletionCreateParams;
328+
import com.openai.models.ChatModel;
329+
330+
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
331+
.addUserMessage("Say this is a test")
332+
.model(ChatModel.O3_MINI)
333+
.build();
334+
HttpResponseFor<ChatCompletion> chatCompletion = client.chat().completions().withRawResponse().create(params);
335+
336+
int statusCode = chatCompletion.statusCode();
337+
Headers headers = chatCompletion.headers();
338+
```
339+
340+
You can still deserialize the response into an instance of a Java class if needed:
341+
342+
```java
343+
import com.openai.models.ChatCompletion;
344+
345+
ChatCompletion parsedChatCompletion = chatCompletion.parse();
346+
```
347+
317348
## Error handling
318349

319350
The SDK throws custom unchecked exception types:

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Reporting Security Issues
44

5-
This SDK is generated by [Stainless Software Inc](http://stainlessapi.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
5+
This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
66

7-
To report a security issue, please contact the Stainless team at security@stainlessapi.com.
7+
To report a security issue, please contact the Stainless team at security@stainless.com.
88

99
## Responsible Disclosure
1010

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repositories {
88

99
allprojects {
1010
group = "com.openai"
11-
version = "0.30.0" // x-release-please-version
11+
version = "0.31.0" // x-release-please-version
1212
}
1313

1414
subprojects {

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.openai.client.okhttp
22

33
import com.openai.core.RequestOptions
4+
import com.openai.core.Timeout
45
import com.openai.core.checkRequired
56
import com.openai.core.http.Headers
67
import com.openai.core.http.HttpClient
@@ -88,13 +89,12 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
8889
)
8990
}
9091

91-
val timeout = requestOptions.timeout
92-
if (timeout != null) {
92+
requestOptions.timeout?.let {
9393
clientBuilder
94-
.connectTimeout(timeout)
95-
.readTimeout(timeout)
96-
.writeTimeout(timeout)
97-
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
94+
.connectTimeout(it.connect())
95+
.readTimeout(it.read())
96+
.writeTimeout(it.write())
97+
.callTimeout(it.request())
9898
}
9999

100100
val client = clientBuilder.build()
@@ -195,23 +195,24 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
195195
class Builder internal constructor() {
196196

197197
private var baseUrl: HttpUrl? = null
198-
// The default timeout is 10 minutes.
199-
private var timeout: Duration = Duration.ofSeconds(600)
198+
private var timeout: Timeout = Timeout.default()
200199
private var proxy: Proxy? = null
201200

202201
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl.toHttpUrl() }
203202

204-
fun timeout(timeout: Duration) = apply { this.timeout = timeout }
203+
fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
204+
205+
fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
205206

206207
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
207208

208209
fun build(): OkHttpClient =
209210
OkHttpClient(
210211
okhttp3.OkHttpClient.Builder()
211-
.connectTimeout(timeout)
212-
.readTimeout(timeout)
213-
.writeTimeout(timeout)
214-
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
212+
.connectTimeout(timeout.connect())
213+
.readTimeout(timeout.read())
214+
.writeTimeout(timeout.write())
215+
.callTimeout(timeout.request())
215216
.proxy(proxy)
216217
.build(),
217218
checkRequired("baseUrl", baseUrl),

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.openai.azure.AzureOpenAIServiceVersion
77
import com.openai.client.OpenAIClient
88
import com.openai.client.OpenAIClientImpl
99
import com.openai.core.ClientOptions
10+
import com.openai.core.Timeout
1011
import com.openai.core.http.Headers
1112
import com.openai.core.http.QueryParams
1213
import com.openai.credential.Credential
@@ -30,8 +31,7 @@ class OpenAIOkHttpClient private constructor() {
3031

3132
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
3233
private var baseUrl: String = ClientOptions.PRODUCTION_URL
33-
// The default timeout for the client is 10 minutes.
34-
private var timeout: Duration = Duration.ofSeconds(600)
34+
private var timeout: Timeout = Timeout.default()
3535
private var proxy: Proxy? = null
3636

3737
fun baseUrl(baseUrl: String) = apply {
@@ -127,7 +127,19 @@ class OpenAIOkHttpClient private constructor() {
127127
clientOptions.removeAllQueryParams(keys)
128128
}
129129

130-
fun timeout(timeout: Duration) = apply { this.timeout = timeout }
130+
fun timeout(timeout: Timeout) = apply {
131+
clientOptions.timeout(timeout)
132+
this.timeout = timeout
133+
}
134+
135+
/**
136+
* Sets the maximum time allowed for a complete HTTP call, not including retries.
137+
*
138+
* See [Timeout.request] for more details.
139+
*
140+
* For fine-grained control, pass a [Timeout] object.
141+
*/
142+
fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
131143

132144
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
133145

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.openai.azure.AzureOpenAIServiceVersion
77
import com.openai.client.OpenAIClientAsync
88
import com.openai.client.OpenAIClientAsyncImpl
99
import com.openai.core.ClientOptions
10+
import com.openai.core.Timeout
1011
import com.openai.core.http.Headers
1112
import com.openai.core.http.QueryParams
1213
import com.openai.credential.Credential
@@ -30,8 +31,7 @@ class OpenAIOkHttpClientAsync private constructor() {
3031

3132
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
3233
private var baseUrl: String = ClientOptions.PRODUCTION_URL
33-
// The default timeout for the client is 10 minutes.
34-
private var timeout: Duration = Duration.ofSeconds(600)
34+
private var timeout: Timeout = Timeout.default()
3535
private var proxy: Proxy? = null
3636

3737
fun baseUrl(baseUrl: String) = apply {
@@ -127,7 +127,19 @@ class OpenAIOkHttpClientAsync private constructor() {
127127
clientOptions.removeAllQueryParams(keys)
128128
}
129129

130-
fun timeout(timeout: Duration) = apply { this.timeout = timeout }
130+
fun timeout(timeout: Timeout) = apply {
131+
clientOptions.timeout(timeout)
132+
this.timeout = timeout
133+
}
134+
135+
/**
136+
* Sets the maximum time allowed for a complete HTTP call, not including retries.
137+
*
138+
* See [Timeout.request] for more details.
139+
*
140+
* For fine-grained control, pass a [Timeout] object.
141+
*/
142+
fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
131143

132144
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
133145

0 commit comments

Comments
 (0)