Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.13.0"
".": "4.14.0"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 4.14.0 (2026-01-06)

Full Changelog: [v4.13.0...v4.14.0](https://github.com/openai/openai-java/compare/v4.13.0...v4.14.0)

### Features

* **client:** add `HttpRequest#url()` method ([cf7d459](https://github.com/openai/openai-java/commit/cf7d459019625c6e08f376efb588c8aff332bf8c))

## 4.13.0 (2025-12-19)

Full Changelog: [v4.12.0...v4.13.0](https://github.com/openai/openai-java/compare/v4.12.0...v4.13.0)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2025 OpenAI
Copyright 2026 OpenAI

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/4.13.0)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.13.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.13.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/4.14.0)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.14.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.14.0)

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

The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https://platform.openai.com/docs) from applications written in Java.

<!-- x-release-please-start-version -->

The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/4.13.0).
The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/4.14.0).

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

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

```kotlin
implementation("com.openai:openai-java:4.13.0")
implementation("com.openai:openai-java:4.14.0")
```

### Maven
Expand All @@ -33,7 +33,7 @@ implementation("com.openai:openai-java:4.13.0")
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>4.13.0</version>
<version>4.14.0</version>
</dependency>
```

Expand Down Expand Up @@ -1342,7 +1342,7 @@ If you're using Spring Boot, then you can use the SDK's [Spring Boot starter](ht
#### Gradle

```kotlin
implementation("com.openai:openai-java-spring-boot-starter:4.13.0")
implementation("com.openai:openai-java-spring-boot-starter:4.14.0")
```

#### Maven
Expand All @@ -1351,7 +1351,7 @@ implementation("com.openai:openai-java-spring-boot-starter:4.13.0")
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java-spring-boot-starter</artifactId>
<version>4.13.0</version>
<version>4.14.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {

allprojects {
group = "com.openai"
version = "4.13.0" // x-release-please-version
version = "4.14.0" // x-release-please-version
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.openai.core.http

import com.openai.core.checkRequired
import com.openai.core.toImmutable
import java.net.URLEncoder

class HttpRequest
private constructor(
Expand All @@ -13,6 +14,35 @@ private constructor(
@get:JvmName("body") val body: HttpRequestBody?,
) {

fun url(): String = buildString {
append(baseUrl)

pathSegments.forEach { segment ->
if (!endsWith("/")) {
append("/")
}
append(URLEncoder.encode(segment, "UTF-8"))
}

if (queryParams.isEmpty()) {
return@buildString
}

append("?")
var isFirst = true
queryParams.keys().forEach { key ->
queryParams.values(key).forEach { value ->
if (!isFirst) {
append("&")
}
append(URLEncoder.encode(key, "UTF-8"))
append("=")
append(URLEncoder.encode(value, "UTF-8"))
isFirst = false
}
}
}

fun toBuilder(): Builder = Builder().from(this)

override fun toString(): String =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.openai.core.http

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource

internal class HttpRequestTest {

enum class UrlTestCase(val request: HttpRequest, val expectedUrl: String) {
BASE_URL_ONLY(
HttpRequest.builder().method(HttpMethod.GET).baseUrl("https://api.example.com").build(),
expectedUrl = "https://api.example.com",
),
BASE_URL_WITH_TRAILING_SLASH(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com/")
.build(),
expectedUrl = "https://api.example.com/",
),
SINGLE_PATH_SEGMENT(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com")
.addPathSegment("users")
.build(),
expectedUrl = "https://api.example.com/users",
),
MULTIPLE_PATH_SEGMENTS(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com")
.addPathSegments("users", "123", "profile")
.build(),
expectedUrl = "https://api.example.com/users/123/profile",
),
PATH_SEGMENT_WITH_SPECIAL_CHARS(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com")
.addPathSegment("user name")
.build(),
expectedUrl = "https://api.example.com/user+name",
),
SINGLE_QUERY_PARAM(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com")
.addPathSegment("users")
.putQueryParam("limit", "10")
.build(),
expectedUrl = "https://api.example.com/users?limit=10",
),
MULTIPLE_QUERY_PARAMS(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com")
.addPathSegment("users")
.putQueryParam("limit", "10")
.putQueryParam("offset", "20")
.build(),
expectedUrl = "https://api.example.com/users?limit=10&offset=20",
),
QUERY_PARAM_WITH_SPECIAL_CHARS(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com")
.addPathSegment("search")
.putQueryParam("q", "hello world")
.build(),
expectedUrl = "https://api.example.com/search?q=hello+world",
),
MULTIPLE_VALUES_SAME_PARAM(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com")
.addPathSegment("users")
.putQueryParams("tags", listOf("admin", "user"))
.build(),
expectedUrl = "https://api.example.com/users?tags=admin&tags=user",
),
BASE_URL_WITH_TRAILING_SLASH_AND_PATH(
HttpRequest.builder()
.method(HttpMethod.GET)
.baseUrl("https://api.example.com/")
.addPathSegment("users")
.build(),
expectedUrl = "https://api.example.com/users",
),
COMPLEX_URL(
HttpRequest.builder()
.method(HttpMethod.POST)
.baseUrl("https://api.example.com")
.addPathSegments("v1", "users", "123")
.putQueryParams("include", listOf("profile", "settings"))
.putQueryParam("format", "json")
.build(),
expectedUrl =
"https://api.example.com/v1/users/123?include=profile&include=settings&format=json",
),
}

@ParameterizedTest
@EnumSource
fun url(testCase: UrlTestCase) {
val actualUrl = testCase.request.url()

assertThat(actualUrl).isEqualTo(testCase.expectedUrl)
}
}