diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index b4e9013ba..6db19b956 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.16.0"
+ ".": "0.17.0"
}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6721301d1..08b74dd9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
# Changelog
+## 0.17.0 (2025-01-29)
+
+Full Changelog: [v0.16.0...v0.17.0](https://github.com/openai/openai-java/compare/v0.16.0...v0.17.0)
+
+### Features
+
+* **client:** add `_queryParams` and `_headers` methods ([#177](https://github.com/openai/openai-java/issues/177)) ([2d67005](https://github.com/openai/openai-java/commit/2d67005735b554440ed0578de6a182a73b129ffa))
+
+
+### Refactors
+
+* **internal:** extract request preparation logic ([2d67005](https://github.com/openai/openai-java/commit/2d67005735b554440ed0578de6a182a73b129ffa))
+
## 0.16.0 (2025-01-28)
Full Changelog: [v0.15.1...v0.16.0](https://github.com/openai/openai-java/compare/v0.15.1...v0.16.0)
diff --git a/README.md b/README.md
index b83e5ab3b..3d8e15351 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@
-[](https://central.sonatype.com/artifact/com.openai/openai-java/0.16.0)
-[](https://javadoc.io/doc/com.openai/openai-java/0.16.0)
+[](https://central.sonatype.com/artifact/com.openai/openai-java/0.17.0)
+[](https://javadoc.io/doc/com.openai/openai-java/0.17.0)
@@ -25,7 +25,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
### Gradle
```kotlin
-implementation("com.openai:openai-java:0.16.0")
+implementation("com.openai:openai-java:0.17.0")
```
### Maven
@@ -34,7 +34,7 @@ implementation("com.openai:openai-java:0.16.0")
com.openai
openai-java
- 0.16.0
+ 0.17.0
```
diff --git a/build.gradle.kts b/build.gradle.kts
index a19523d92..b2f977628 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -8,7 +8,7 @@ repositories {
allprojects {
group = "com.openai"
- version = "0.16.0" // x-release-please-version
+ version = "0.17.0" // x-release-please-version
}
subprojects {
diff --git a/openai-java-core/src/main/kotlin/com/openai/azure/HttpRequestBuilderExtensions.kt b/openai-java-core/src/main/kotlin/com/openai/azure/HttpRequestBuilderExtensions.kt
index c6b7ff449..c45a696e0 100644
--- a/openai-java-core/src/main/kotlin/com/openai/azure/HttpRequestBuilderExtensions.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/azure/HttpRequestBuilderExtensions.kt
@@ -8,9 +8,9 @@ import com.openai.credential.BearerTokenCredential
@JvmSynthetic
internal fun HttpRequest.Builder.addPathSegmentsForAzure(
clientOptions: ClientOptions,
- deploymentModel: String
+ deploymentModel: String?
): HttpRequest.Builder = apply {
- if (isAzureEndpoint(clientOptions.baseUrl)) {
+ if (isAzureEndpoint(clientOptions.baseUrl) && deploymentModel != null) {
addPathSegments("openai", "deployments", deploymentModel)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Params.kt b/openai-java-core/src/main/kotlin/com/openai/core/Params.kt
new file mode 100644
index 000000000..1ce472aee
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/core/Params.kt
@@ -0,0 +1,16 @@
+package com.openai.core
+
+import com.openai.core.http.Headers
+import com.openai.core.http.QueryParams
+
+/** An interface representing parameters passed to a service method. */
+interface Params {
+ /** The full set of headers in the parameters, including both fixed and additional headers. */
+ fun _headers(): Headers
+
+ /**
+ * The full set of query params in the parameters, including both fixed and additional query
+ * params.
+ */
+ fun _queryParams(): QueryParams
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/PrepareRequest.kt b/openai-java-core/src/main/kotlin/com/openai/core/PrepareRequest.kt
new file mode 100644
index 000000000..ab0c04b4a
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/core/PrepareRequest.kt
@@ -0,0 +1,36 @@
+@file:JvmName("PrepareRequest")
+
+package com.openai.core
+
+import com.openai.azure.addPathSegmentsForAzure
+import com.openai.azure.replaceBearerTokenForAzure
+import com.openai.core.http.HttpRequest
+import java.util.concurrent.CompletableFuture
+
+@JvmSynthetic
+internal fun HttpRequest.prepare(
+ clientOptions: ClientOptions,
+ params: Params,
+ deploymentModel: String?
+): HttpRequest =
+ toBuilder()
+ // Clear the path segments and add them back below after the Azure path segments.
+ .pathSegments(listOf())
+ .addPathSegmentsForAzure(clientOptions, deploymentModel)
+ .addPathSegments(*pathSegments.toTypedArray())
+ .putAllQueryParams(clientOptions.queryParams)
+ .replaceAllQueryParams(params._queryParams())
+ .putAllHeaders(clientOptions.headers)
+ .replaceBearerTokenForAzure(clientOptions)
+ .replaceAllHeaders(params._headers())
+ .build()
+
+@JvmSynthetic
+internal fun HttpRequest.prepareAsync(
+ clientOptions: ClientOptions,
+ params: Params,
+ deploymentModel: String?
+): CompletableFuture =
+ // This async version exists to make it easier to add async specific preparation logic in the
+ // future.
+ CompletableFuture.completedFuture(prepare(clientOptions, params, deploymentModel))
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequest.kt b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequest.kt
index b335da29e..dd8802350 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequest.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequest.kt
@@ -45,6 +45,10 @@ private constructor(
fun url(url: String) = apply { this.url = url }
+ fun pathSegments(pathSegments: List) = apply {
+ this.pathSegments = pathSegments.toMutableList()
+ }
+
fun addPathSegment(pathSegment: String) = apply { pathSegments.add(pathSegment) }
fun addPathSegments(vararg pathSegments: String) = apply {
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt
index a4431b373..7f4ab1bad 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt
@@ -4,6 +4,7 @@ package com.openai.models
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.Params
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
@@ -22,7 +23,7 @@ private constructor(
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
private val additionalBodyProperties: Map,
-) {
+) : Params {
fun batchId(): String = batchId
@@ -33,12 +34,12 @@ private constructor(
fun _additionalBodyProperties(): Map = additionalBodyProperties
@JvmSynthetic
- internal fun getBody(): Optional