diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e6ce3d043..0ce7297f9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -38,7 +38,7 @@ jobs:
run: ./scripts/lint
build:
- timeout-minutes: 15
+ timeout-minutes: 30
name: build
permissions:
contents: read
@@ -67,23 +67,51 @@ jobs:
GRADLE_OPTS: "-Dkotlin.compiler.execution.strategy=in-process"
run: ./scripts/build
- - name: Get GitHub OIDC Token
- if: github.repository == 'stainless-sdks/openai-java'
- id: github-oidc
- uses: actions/github-script@v8
- with:
- script: core.setOutput('github_token', await core.getIDToken());
-
- name: Build and upload Maven artifacts
if: github.repository == 'stainless-sdks/openai-java'
env:
URL: https://pkg.stainless.com/s
- AUTH: ${{ steps.github-oidc.outputs.github_token }}
SHA: ${{ github.sha }}
PROJECT: openai-java
- run: ./scripts/upload-artifacts
+ run: |
+ set -euo pipefail
+
+ max_retries=5
+ attempt=1
+
+ while true; do
+ echo "Maven artifact upload attempt ${attempt}/${max_retries}"
+
+ oidc_response="$(curl -sSf \
+ -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
+ "${ACTIONS_ID_TOKEN_REQUEST_URL}")"
+ github_token="$(printf '%s' "$oidc_response" | jq -er '.value')"
+
+ upload_log="$(mktemp)"
+ set +e
+ AUTH="$github_token" ./scripts/upload-artifacts 2>&1 | tee "$upload_log"
+ upload_status=${PIPESTATUS[0]}
+ set -e
+
+ if [ "$upload_status" -eq 0 ]; then
+ break
+ fi
+
+ if [ "$attempt" -lt "$max_retries" ] && \
+ grep -q "Failed to get valid signed URL" "$upload_log" && \
+ grep -q "GitHub JWT is missing or invalid\\." "$upload_log"; then
+ sleep_seconds=$((3 * (1 << (attempt - 1))))
+ echo "Retrying after fresh OIDC token due to transient GitHub JWT validation failure"
+ echo "Sleeping ${sleep_seconds}s before retry"
+ sleep "$sleep_seconds"
+ attempt=$((attempt + 1))
+ continue
+ fi
+
+ exit "$upload_status"
+ done
test:
- timeout-minutes: 15
+ timeout-minutes: 30
name: test
runs-on: ${{ github.repository == 'stainless-sdks/openai-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index c032d3110..69e5aa20c 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "4.22.0"
+ ".": "4.23.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index fe36e289f..704ee3211 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,4 +1,4 @@
configured_endpoints: 147
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a6dd5f8d7318fb1c5370d5ccb7148bacdfb3f3a665c4b85b7666e6188d9bd909.yml
-openapi_spec_hash: c4824e385a81b9021428304ccc96538f
-config_hash: 948733484caf41e71093c6582dbc319c
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a0aa54a302fbd7fff4ed7ad8a8547587d37b63324fc4af652bfa685ee9f8da44.yml
+openapi_spec_hash: e45c5af19307cfc8b9baa4b8f8e865a0
+config_hash: 4c2841519fd72fe44c18de4c18db231f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f0c2344d..293a40237 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,32 @@
# Changelog
+## 4.23.0 (2026-02-23)
+
+Full Changelog: [v4.22.0...v4.23.0](https://github.com/openai/openai-java/compare/v4.22.0...v4.23.0)
+
+### Features
+
+* **api:** add gpt-realtime-1.5 and gpt-audio-1.5 models to realtime session ([b00b515](https://github.com/openai/openai-java/commit/b00b515f591c8651ab4d5d46606e31a69787eebf))
+
+
+### Bug Fixes
+
+* **api:** manual updates ([bd83804](https://github.com/openai/openai-java/commit/bd83804f76f2be62a2a09e4b9f2ed7832fdb740f))
+* set Accept header in more places ([9e2e714](https://github.com/openai/openai-java/commit/9e2e7145e357dfe6e8b3f8701df70a42e07a4f63))
+* **tests:** skip unsupported streaming tests ([24f9854](https://github.com/openai/openai-java/commit/24f9854de6299572a6b836059855218f68f2e412))
+
+
+### Chores
+
+* drop apache dependency ([37805bf](https://github.com/openai/openai-java/commit/37805bf5dad1f503cec009dfaca6c6b2b21fc279))
+* make `Properties` more resilient to `null` ([0039eb0](https://github.com/openai/openai-java/commit/0039eb008840c33d9f62d44999e4b4533a3a50d2))
+
+
+### Documentation
+
+* **api:** add batch size limit to file batch create parameters ([764fd86](https://github.com/openai/openai-java/commit/764fd868ab4d0f9642ae2facb6ca98ef3a491888))
+* **api:** clarify safety_identifier max length in chat completions and responses ([b2735b0](https://github.com/openai/openai-java/commit/b2735b002e3591513ea743062e36d6f965f1fd46))
+
## 4.22.0 (2026-02-19)
Full Changelog: [v4.21.0...v4.22.0](https://github.com/openai/openai-java/compare/v4.21.0...v4.22.0)
diff --git a/README.md b/README.md
index 9ac179bea..49b96936b 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
-[](https://central.sonatype.com/artifact/com.openai/openai-java/4.22.0)
-[](https://javadoc.io/doc/com.openai/openai-java/4.22.0)
+[](https://central.sonatype.com/artifact/com.openai/openai-java/4.23.0)
+[](https://javadoc.io/doc/com.openai/openai-java/4.23.0)
@@ -11,7 +11,7 @@ The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https://
-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.22.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.23.0).
@@ -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.22.0")
+implementation("com.openai:openai-java:4.23.0")
```
### Maven
@@ -33,7 +33,7 @@ implementation("com.openai:openai-java:4.22.0")
com.openaiopenai-java
- 4.22.0
+ 4.23.0
```
@@ -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.22.0")
+implementation("com.openai:openai-java-spring-boot-starter:4.23.0")
```
#### Maven
@@ -1351,7 +1351,7 @@ implementation("com.openai:openai-java-spring-boot-starter:4.22.0")
com.openaiopenai-java-spring-boot-starter
- 4.22.0
+ 4.23.0
```
diff --git a/build.gradle.kts b/build.gradle.kts
index 2918ba8ac..d6eea49e8 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -8,7 +8,7 @@ repositories {
allprojects {
group = "com.openai"
- version = "4.22.0" // x-release-please-version
+ version = "4.23.0" // x-release-please-version
}
subprojects {
diff --git a/openai-java-core/build.gradle.kts b/openai-java-core/build.gradle.kts
index cddd7776f..b723288c6 100644
--- a/openai-java-core/build.gradle.kts
+++ b/openai-java-core/build.gradle.kts
@@ -29,8 +29,6 @@ dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2")
- implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4")
- implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
implementation("com.github.victools:jsonschema-generator:4.38.0")
implementation("com.github.victools:jsonschema-module-jackson:4.38.0")
implementation("com.github.victools:jsonschema-module-swagger-2:4.38.0")
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Properties.kt b/openai-java-core/src/main/kotlin/com/openai/core/Properties.kt
index 677d5fd60..354311006 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/Properties.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/Properties.kt
@@ -34,9 +34,9 @@ fun getOsName(): String {
}
}
-fun getOsVersion(): String = System.getProperty("os.version", "unknown")
+fun getOsVersion(): String = System.getProperty("os.version", "unknown") ?: "unknown"
fun getPackageVersion(): String =
- OpenAIClient::class.java.`package`.implementationVersion ?: "unknown"
+ OpenAIClient::class.java.`package`?.implementationVersion ?: "unknown"
-fun getJavaVersion(): String = System.getProperty("java.version", "unknown")
+fun getJavaVersion(): String = System.getProperty("java.version", "unknown") ?: "unknown"
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequestBodies.kt b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequestBodies.kt
index 898c83474..9c1e9e901 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequestBodies.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequestBodies.kt
@@ -8,13 +8,13 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.databind.node.JsonNodeType
import com.openai.core.MultipartField
+import com.openai.core.toImmutable
import com.openai.errors.OpenAIInvalidDataException
+import java.io.ByteArrayInputStream
import java.io.InputStream
import java.io.OutputStream
+import java.util.UUID
import kotlin.jvm.optionals.getOrNull
-import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder
-import org.apache.hc.core5.http.ContentType
-import org.apache.hc.core5.http.HttpEntity
@JvmSynthetic
internal inline fun json(jsonMapper: JsonMapper, value: T): HttpRequestBody =
@@ -37,70 +37,207 @@ internal fun multipartFormData(
jsonMapper: JsonMapper,
fields: Map>,
): HttpRequestBody =
- object : HttpRequestBody {
- private val entity: HttpEntity by lazy {
- MultipartEntityBuilder.create()
- .apply {
- fields.forEach { (name, field) ->
- val knownValue = field.value.asKnown().getOrNull()
- val parts =
- if (knownValue is InputStream) {
- // Read directly from the `InputStream` instead of reading it all
- // into memory due to the `jsonMapper` serialization below.
- sequenceOf(name to knownValue)
- } else {
- val node = jsonMapper.valueToTree(field.value)
- serializePart(name, node)
+ MultipartBody.Builder()
+ .apply {
+ fields.forEach { (name, field) ->
+ val knownValue = field.value.asKnown().getOrNull()
+ val parts =
+ if (knownValue is InputStream) {
+ // Read directly from the `InputStream` instead of reading it all
+ // into memory due to the `jsonMapper` serialization below.
+ sequenceOf(name to knownValue)
+ } else {
+ val node = jsonMapper.valueToTree(field.value)
+ serializePart(name, node)
+ }
+
+ parts.forEach { (name, bytes) ->
+ val partBody =
+ if (bytes is ByteArrayInputStream) {
+ val byteArray = bytes.readBytes()
+
+ object : HttpRequestBody {
+
+ override fun writeTo(outputStream: OutputStream) {
+ outputStream.write(byteArray)
+ }
+
+ override fun contentType(): String = field.contentType
+
+ override fun contentLength(): Long = byteArray.size.toLong()
+
+ override fun repeatable(): Boolean = true
+
+ override fun close() {}
}
+ } else {
+ object : HttpRequestBody {
+
+ override fun writeTo(outputStream: OutputStream) {
+ bytes.copyTo(outputStream)
+ }
+
+ override fun contentType(): String = field.contentType
- parts.forEach { (name, bytes) ->
- addBinaryBody(
- name,
- bytes,
- ContentType.parseLenient(field.contentType),
- field.filename().getOrNull(),
- )
+ override fun contentLength(): Long = -1L
+
+ override fun repeatable(): Boolean = false
+
+ override fun close() = bytes.close()
+ }
}
- }
+
+ addPart(
+ MultipartBody.Part.create(
+ name,
+ field.filename().getOrNull(),
+ field.contentType,
+ partBody,
+ )
+ )
}
- .build()
+ }
}
+ .build()
+
+private fun serializePart(name: String, node: JsonNode): Sequence> =
+ when (node.nodeType) {
+ JsonNodeType.MISSING,
+ JsonNodeType.NULL -> emptySequence()
+ JsonNodeType.BINARY -> sequenceOf(name to node.binaryValue().inputStream())
+ JsonNodeType.STRING -> sequenceOf(name to node.textValue().byteInputStream())
+ JsonNodeType.BOOLEAN -> sequenceOf(name to node.booleanValue().toString().byteInputStream())
+ JsonNodeType.NUMBER -> sequenceOf(name to node.numberValue().toString().byteInputStream())
+ JsonNodeType.ARRAY ->
+ node.elements().asSequence().flatMap { element -> serializePart("$name[]", element) }
+ JsonNodeType.OBJECT ->
+ node.fields().asSequence().flatMap { (key, value) ->
+ serializePart("$name[$key]", value)
+ }
+ JsonNodeType.POJO,
+ null -> throw OpenAIInvalidDataException("Unexpected JsonNode type: ${node.nodeType}")
+ }
- private fun serializePart(
- name: String,
- node: JsonNode,
- ): Sequence> =
- when (node.nodeType) {
- JsonNodeType.MISSING,
- JsonNodeType.NULL -> emptySequence()
- JsonNodeType.BINARY -> sequenceOf(name to node.binaryValue().inputStream())
- JsonNodeType.STRING -> sequenceOf(name to node.textValue().inputStream())
- JsonNodeType.BOOLEAN ->
- sequenceOf(name to node.booleanValue().toString().inputStream())
- JsonNodeType.NUMBER ->
- sequenceOf(name to node.numberValue().toString().inputStream())
- JsonNodeType.ARRAY ->
- node.elements().asSequence().flatMap { element ->
- serializePart("$name[]", element)
- }
- JsonNodeType.OBJECT ->
- node.fields().asSequence().flatMap { (key, value) ->
- serializePart("$name[$key]", value)
- }
- JsonNodeType.POJO,
- null ->
- throw OpenAIInvalidDataException("Unexpected JsonNode type: ${node.nodeType}")
+private class MultipartBody
+private constructor(private val boundary: String, private val parts: List) : HttpRequestBody {
+ private val boundaryBytes: ByteArray = boundary.toByteArray()
+ private val contentType = "multipart/form-data; boundary=$boundary"
+
+ // This must remain in sync with `contentLength`.
+ override fun writeTo(outputStream: OutputStream) {
+ parts.forEach { part ->
+ outputStream.write(DASHDASH)
+ outputStream.write(boundaryBytes)
+ outputStream.write(CRLF)
+
+ outputStream.write(CONTENT_DISPOSITION)
+ outputStream.write(part.contentDisposition.toByteArray())
+ outputStream.write(CRLF)
+
+ outputStream.write(CONTENT_TYPE)
+ outputStream.write(part.contentType.toByteArray())
+ outputStream.write(CRLF)
+
+ outputStream.write(CRLF)
+ part.body.writeTo(outputStream)
+ outputStream.write(CRLF)
+ }
+
+ outputStream.write(DASHDASH)
+ outputStream.write(boundaryBytes)
+ outputStream.write(DASHDASH)
+ outputStream.write(CRLF)
+ }
+
+ override fun contentType(): String = contentType
+
+ // This must remain in sync with `writeTo`.
+ override fun contentLength(): Long {
+ var byteCount = 0L
+
+ parts.forEach { part ->
+ val contentLength = part.body.contentLength()
+ if (contentLength == -1L) {
+ return -1L
}
- private fun String.inputStream(): InputStream = toByteArray().inputStream()
+ byteCount +=
+ DASHDASH.size +
+ boundaryBytes.size +
+ CRLF.size +
+ CONTENT_DISPOSITION.size +
+ part.contentDisposition.toByteArray().size +
+ CRLF.size +
+ CONTENT_TYPE.size +
+ part.contentType.toByteArray().size +
+ CRLF.size +
+ CRLF.size +
+ contentLength +
+ CRLF.size
+ }
- override fun writeTo(outputStream: OutputStream) = entity.writeTo(outputStream)
+ byteCount += DASHDASH.size + boundaryBytes.size + DASHDASH.size + CRLF.size
+ return byteCount
+ }
- override fun contentType(): String = entity.contentType
+ override fun repeatable(): Boolean = parts.all { it.body.repeatable() }
- override fun contentLength(): Long = entity.contentLength
+ override fun close() {
+ parts.forEach { it.body.close() }
+ }
- override fun repeatable(): Boolean = entity.isRepeatable
+ class Builder {
+ private val boundary = UUID.randomUUID().toString()
+ private val parts: MutableList = mutableListOf()
- override fun close() = entity.close()
+ fun addPart(part: Part) = apply { parts.add(part) }
+
+ fun build() = MultipartBody(boundary, parts.toImmutable())
+ }
+
+ class Part
+ private constructor(
+ val contentDisposition: String,
+ val contentType: String,
+ val body: HttpRequestBody,
+ ) {
+ companion object {
+ fun create(
+ name: String,
+ filename: String?,
+ contentType: String,
+ body: HttpRequestBody,
+ ): Part {
+ val disposition = buildString {
+ append("form-data; name=")
+ appendQuotedString(name)
+ if (filename != null) {
+ append("; filename=")
+ appendQuotedString(filename)
+ }
+ }
+ return Part(disposition, contentType, body)
+ }
+ }
+ }
+
+ companion object {
+ private val CRLF = byteArrayOf('\r'.code.toByte(), '\n'.code.toByte())
+ private val DASHDASH = byteArrayOf('-'.code.toByte(), '-'.code.toByte())
+ private val CONTENT_DISPOSITION = "Content-Disposition: ".toByteArray()
+ private val CONTENT_TYPE = "Content-Type: ".toByteArray()
+
+ private fun StringBuilder.appendQuotedString(key: String) {
+ append('"')
+ for (ch in key) {
+ when (ch) {
+ '\n' -> append("%0A")
+ '\r' -> append("%0D")
+ '"' -> append("%22")
+ else -> append(ch)
+ }
+ }
+ append('"')
+ }
}
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParams.kt
index 4e66cb423..73fffa0bd 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParams.kt
@@ -314,9 +314,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user. We
- * recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user, with
+ * a maximum length of 64 characters. We recommend hashing their username or email address, in
+ * order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
@@ -1484,9 +1484,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user.
- * We recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user,
+ * with a maximum length of 64 characters. We recommend hashing their username or email
+ * address, in order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*/
fun safetyIdentifier(safetyIdentifier: String) = apply {
@@ -2476,9 +2476,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user.
- * We recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user,
+ * with a maximum length of 64 characters. We recommend hashing their username or email
+ * address, in order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
@@ -3822,8 +3822,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be
* violating OpenAI's usage policies. The IDs should be a string that uniquely
- * identifies each user. We recommend hashing their username or email address, in order
- * to avoid sending us any identifying information.
+ * identifies each user, with a maximum length of 64 characters. We recommend hashing
+ * their username or email address, in order to avoid sending us any identifying
+ * information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*/
fun safetyIdentifier(safetyIdentifier: String) =
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt
index 8e8a56591..5cdfe031d 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt
@@ -1865,6 +1865,8 @@ private constructor(
@JvmField val GPT_REALTIME = of("gpt-realtime")
+ @JvmField val GPT_REALTIME_1_5 = of("gpt-realtime-1.5")
+
@JvmField val GPT_REALTIME_2025_08_28 = of("gpt-realtime-2025-08-28")
@JvmField val GPT_4O_REALTIME_PREVIEW = of("gpt-4o-realtime-preview")
@@ -1890,6 +1892,8 @@ private constructor(
@JvmField val GPT_REALTIME_MINI_2025_12_15 = of("gpt-realtime-mini-2025-12-15")
+ @JvmField val GPT_AUDIO_1_5 = of("gpt-audio-1.5")
+
@JvmField val GPT_AUDIO_MINI = of("gpt-audio-mini")
@JvmField val GPT_AUDIO_MINI_2025_10_06 = of("gpt-audio-mini-2025-10-06")
@@ -1902,6 +1906,7 @@ private constructor(
/** An enum containing [Model]'s known values. */
enum class Known {
GPT_REALTIME,
+ GPT_REALTIME_1_5,
GPT_REALTIME_2025_08_28,
GPT_4O_REALTIME_PREVIEW,
GPT_4O_REALTIME_PREVIEW_2024_10_01,
@@ -1912,6 +1917,7 @@ private constructor(
GPT_REALTIME_MINI,
GPT_REALTIME_MINI_2025_10_06,
GPT_REALTIME_MINI_2025_12_15,
+ GPT_AUDIO_1_5,
GPT_AUDIO_MINI,
GPT_AUDIO_MINI_2025_10_06,
GPT_AUDIO_MINI_2025_12_15,
@@ -1928,6 +1934,7 @@ private constructor(
*/
enum class Value {
GPT_REALTIME,
+ GPT_REALTIME_1_5,
GPT_REALTIME_2025_08_28,
GPT_4O_REALTIME_PREVIEW,
GPT_4O_REALTIME_PREVIEW_2024_10_01,
@@ -1938,6 +1945,7 @@ private constructor(
GPT_REALTIME_MINI,
GPT_REALTIME_MINI_2025_10_06,
GPT_REALTIME_MINI_2025_12_15,
+ GPT_AUDIO_1_5,
GPT_AUDIO_MINI,
GPT_AUDIO_MINI_2025_10_06,
GPT_AUDIO_MINI_2025_12_15,
@@ -1955,6 +1963,7 @@ private constructor(
fun value(): Value =
when (this) {
GPT_REALTIME -> Value.GPT_REALTIME
+ GPT_REALTIME_1_5 -> Value.GPT_REALTIME_1_5
GPT_REALTIME_2025_08_28 -> Value.GPT_REALTIME_2025_08_28
GPT_4O_REALTIME_PREVIEW -> Value.GPT_4O_REALTIME_PREVIEW
GPT_4O_REALTIME_PREVIEW_2024_10_01 -> Value.GPT_4O_REALTIME_PREVIEW_2024_10_01
@@ -1966,6 +1975,7 @@ private constructor(
GPT_REALTIME_MINI -> Value.GPT_REALTIME_MINI
GPT_REALTIME_MINI_2025_10_06 -> Value.GPT_REALTIME_MINI_2025_10_06
GPT_REALTIME_MINI_2025_12_15 -> Value.GPT_REALTIME_MINI_2025_12_15
+ GPT_AUDIO_1_5 -> Value.GPT_AUDIO_1_5
GPT_AUDIO_MINI -> Value.GPT_AUDIO_MINI
GPT_AUDIO_MINI_2025_10_06 -> Value.GPT_AUDIO_MINI_2025_10_06
GPT_AUDIO_MINI_2025_12_15 -> Value.GPT_AUDIO_MINI_2025_12_15
@@ -1984,6 +1994,7 @@ private constructor(
fun known(): Known =
when (this) {
GPT_REALTIME -> Known.GPT_REALTIME
+ GPT_REALTIME_1_5 -> Known.GPT_REALTIME_1_5
GPT_REALTIME_2025_08_28 -> Known.GPT_REALTIME_2025_08_28
GPT_4O_REALTIME_PREVIEW -> Known.GPT_4O_REALTIME_PREVIEW
GPT_4O_REALTIME_PREVIEW_2024_10_01 -> Known.GPT_4O_REALTIME_PREVIEW_2024_10_01
@@ -1995,6 +2006,7 @@ private constructor(
GPT_REALTIME_MINI -> Known.GPT_REALTIME_MINI
GPT_REALTIME_MINI_2025_10_06 -> Known.GPT_REALTIME_MINI_2025_10_06
GPT_REALTIME_MINI_2025_12_15 -> Known.GPT_REALTIME_MINI_2025_12_15
+ GPT_AUDIO_1_5 -> Known.GPT_AUDIO_1_5
GPT_AUDIO_MINI -> Known.GPT_AUDIO_MINI
GPT_AUDIO_MINI_2025_10_06 -> Known.GPT_AUDIO_MINI_2025_10_06
GPT_AUDIO_MINI_2025_12_15 -> Known.GPT_AUDIO_MINI_2025_12_15
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt
index 7463b3edb..9bad2ba3f 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt
@@ -1137,6 +1137,8 @@ private constructor(
@JvmField val GPT_REALTIME = of("gpt-realtime")
+ @JvmField val GPT_REALTIME_1_5 = of("gpt-realtime-1.5")
+
@JvmField val GPT_REALTIME_2025_08_28 = of("gpt-realtime-2025-08-28")
@JvmField val GPT_4O_REALTIME_PREVIEW = of("gpt-4o-realtime-preview")
@@ -1162,6 +1164,8 @@ private constructor(
@JvmField val GPT_REALTIME_MINI_2025_12_15 = of("gpt-realtime-mini-2025-12-15")
+ @JvmField val GPT_AUDIO_1_5 = of("gpt-audio-1.5")
+
@JvmField val GPT_AUDIO_MINI = of("gpt-audio-mini")
@JvmField val GPT_AUDIO_MINI_2025_10_06 = of("gpt-audio-mini-2025-10-06")
@@ -1174,6 +1178,7 @@ private constructor(
/** An enum containing [Model]'s known values. */
enum class Known {
GPT_REALTIME,
+ GPT_REALTIME_1_5,
GPT_REALTIME_2025_08_28,
GPT_4O_REALTIME_PREVIEW,
GPT_4O_REALTIME_PREVIEW_2024_10_01,
@@ -1184,6 +1189,7 @@ private constructor(
GPT_REALTIME_MINI,
GPT_REALTIME_MINI_2025_10_06,
GPT_REALTIME_MINI_2025_12_15,
+ GPT_AUDIO_1_5,
GPT_AUDIO_MINI,
GPT_AUDIO_MINI_2025_10_06,
GPT_AUDIO_MINI_2025_12_15,
@@ -1200,6 +1206,7 @@ private constructor(
*/
enum class Value {
GPT_REALTIME,
+ GPT_REALTIME_1_5,
GPT_REALTIME_2025_08_28,
GPT_4O_REALTIME_PREVIEW,
GPT_4O_REALTIME_PREVIEW_2024_10_01,
@@ -1210,6 +1217,7 @@ private constructor(
GPT_REALTIME_MINI,
GPT_REALTIME_MINI_2025_10_06,
GPT_REALTIME_MINI_2025_12_15,
+ GPT_AUDIO_1_5,
GPT_AUDIO_MINI,
GPT_AUDIO_MINI_2025_10_06,
GPT_AUDIO_MINI_2025_12_15,
@@ -1227,6 +1235,7 @@ private constructor(
fun value(): Value =
when (this) {
GPT_REALTIME -> Value.GPT_REALTIME
+ GPT_REALTIME_1_5 -> Value.GPT_REALTIME_1_5
GPT_REALTIME_2025_08_28 -> Value.GPT_REALTIME_2025_08_28
GPT_4O_REALTIME_PREVIEW -> Value.GPT_4O_REALTIME_PREVIEW
GPT_4O_REALTIME_PREVIEW_2024_10_01 -> Value.GPT_4O_REALTIME_PREVIEW_2024_10_01
@@ -1238,6 +1247,7 @@ private constructor(
GPT_REALTIME_MINI -> Value.GPT_REALTIME_MINI
GPT_REALTIME_MINI_2025_10_06 -> Value.GPT_REALTIME_MINI_2025_10_06
GPT_REALTIME_MINI_2025_12_15 -> Value.GPT_REALTIME_MINI_2025_12_15
+ GPT_AUDIO_1_5 -> Value.GPT_AUDIO_1_5
GPT_AUDIO_MINI -> Value.GPT_AUDIO_MINI
GPT_AUDIO_MINI_2025_10_06 -> Value.GPT_AUDIO_MINI_2025_10_06
GPT_AUDIO_MINI_2025_12_15 -> Value.GPT_AUDIO_MINI_2025_12_15
@@ -1256,6 +1266,7 @@ private constructor(
fun known(): Known =
when (this) {
GPT_REALTIME -> Known.GPT_REALTIME
+ GPT_REALTIME_1_5 -> Known.GPT_REALTIME_1_5
GPT_REALTIME_2025_08_28 -> Known.GPT_REALTIME_2025_08_28
GPT_4O_REALTIME_PREVIEW -> Known.GPT_4O_REALTIME_PREVIEW
GPT_4O_REALTIME_PREVIEW_2024_10_01 -> Known.GPT_4O_REALTIME_PREVIEW_2024_10_01
@@ -1267,6 +1278,7 @@ private constructor(
GPT_REALTIME_MINI -> Known.GPT_REALTIME_MINI
GPT_REALTIME_MINI_2025_10_06 -> Known.GPT_REALTIME_MINI_2025_10_06
GPT_REALTIME_MINI_2025_12_15 -> Known.GPT_REALTIME_MINI_2025_12_15
+ GPT_AUDIO_1_5 -> Known.GPT_AUDIO_1_5
GPT_AUDIO_MINI -> Known.GPT_AUDIO_MINI
GPT_AUDIO_MINI_2025_10_06 -> Known.GPT_AUDIO_MINI_2025_10_06
GPT_AUDIO_MINI_2025_12_15 -> Known.GPT_AUDIO_MINI_2025_12_15
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt
index 7df571215..958dcb920 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt
@@ -3548,6 +3548,8 @@ private constructor(
@JvmField val GPT_REALTIME = of("gpt-realtime")
+ @JvmField val GPT_REALTIME_1_5 = of("gpt-realtime-1.5")
+
@JvmField val GPT_REALTIME_2025_08_28 = of("gpt-realtime-2025-08-28")
@JvmField val GPT_4O_REALTIME_PREVIEW = of("gpt-4o-realtime-preview")
@@ -3573,6 +3575,8 @@ private constructor(
@JvmField val GPT_REALTIME_MINI_2025_12_15 = of("gpt-realtime-mini-2025-12-15")
+ @JvmField val GPT_AUDIO_1_5 = of("gpt-audio-1.5")
+
@JvmField val GPT_AUDIO_MINI = of("gpt-audio-mini")
@JvmField val GPT_AUDIO_MINI_2025_10_06 = of("gpt-audio-mini-2025-10-06")
@@ -3585,6 +3589,7 @@ private constructor(
/** An enum containing [Model]'s known values. */
enum class Known {
GPT_REALTIME,
+ GPT_REALTIME_1_5,
GPT_REALTIME_2025_08_28,
GPT_4O_REALTIME_PREVIEW,
GPT_4O_REALTIME_PREVIEW_2024_10_01,
@@ -3595,6 +3600,7 @@ private constructor(
GPT_REALTIME_MINI,
GPT_REALTIME_MINI_2025_10_06,
GPT_REALTIME_MINI_2025_12_15,
+ GPT_AUDIO_1_5,
GPT_AUDIO_MINI,
GPT_AUDIO_MINI_2025_10_06,
GPT_AUDIO_MINI_2025_12_15,
@@ -3611,6 +3617,7 @@ private constructor(
*/
enum class Value {
GPT_REALTIME,
+ GPT_REALTIME_1_5,
GPT_REALTIME_2025_08_28,
GPT_4O_REALTIME_PREVIEW,
GPT_4O_REALTIME_PREVIEW_2024_10_01,
@@ -3621,6 +3628,7 @@ private constructor(
GPT_REALTIME_MINI,
GPT_REALTIME_MINI_2025_10_06,
GPT_REALTIME_MINI_2025_12_15,
+ GPT_AUDIO_1_5,
GPT_AUDIO_MINI,
GPT_AUDIO_MINI_2025_10_06,
GPT_AUDIO_MINI_2025_12_15,
@@ -3638,6 +3646,7 @@ private constructor(
fun value(): Value =
when (this) {
GPT_REALTIME -> Value.GPT_REALTIME
+ GPT_REALTIME_1_5 -> Value.GPT_REALTIME_1_5
GPT_REALTIME_2025_08_28 -> Value.GPT_REALTIME_2025_08_28
GPT_4O_REALTIME_PREVIEW -> Value.GPT_4O_REALTIME_PREVIEW
GPT_4O_REALTIME_PREVIEW_2024_10_01 -> Value.GPT_4O_REALTIME_PREVIEW_2024_10_01
@@ -3649,6 +3658,7 @@ private constructor(
GPT_REALTIME_MINI -> Value.GPT_REALTIME_MINI
GPT_REALTIME_MINI_2025_10_06 -> Value.GPT_REALTIME_MINI_2025_10_06
GPT_REALTIME_MINI_2025_12_15 -> Value.GPT_REALTIME_MINI_2025_12_15
+ GPT_AUDIO_1_5 -> Value.GPT_AUDIO_1_5
GPT_AUDIO_MINI -> Value.GPT_AUDIO_MINI
GPT_AUDIO_MINI_2025_10_06 -> Value.GPT_AUDIO_MINI_2025_10_06
GPT_AUDIO_MINI_2025_12_15 -> Value.GPT_AUDIO_MINI_2025_12_15
@@ -3667,6 +3677,7 @@ private constructor(
fun known(): Known =
when (this) {
GPT_REALTIME -> Known.GPT_REALTIME
+ GPT_REALTIME_1_5 -> Known.GPT_REALTIME_1_5
GPT_REALTIME_2025_08_28 -> Known.GPT_REALTIME_2025_08_28
GPT_4O_REALTIME_PREVIEW -> Known.GPT_4O_REALTIME_PREVIEW
GPT_4O_REALTIME_PREVIEW_2024_10_01 -> Known.GPT_4O_REALTIME_PREVIEW_2024_10_01
@@ -3678,6 +3689,7 @@ private constructor(
GPT_REALTIME_MINI -> Known.GPT_REALTIME_MINI
GPT_REALTIME_MINI_2025_10_06 -> Known.GPT_REALTIME_MINI_2025_10_06
GPT_REALTIME_MINI_2025_12_15 -> Known.GPT_REALTIME_MINI_2025_12_15
+ GPT_AUDIO_1_5 -> Known.GPT_AUDIO_1_5
GPT_AUDIO_MINI -> Known.GPT_AUDIO_MINI
GPT_AUDIO_MINI_2025_10_06 -> Known.GPT_AUDIO_MINI_2025_10_06
GPT_AUDIO_MINI_2025_12_15 -> Known.GPT_AUDIO_MINI_2025_12_15
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/Response.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/Response.kt
index c2f6a1bfc..0eff08c49 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/responses/Response.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/Response.kt
@@ -443,9 +443,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user. We
- * recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user, with
+ * a maximum length of 64 characters. We recommend hashing their username or email address, in
+ * order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
@@ -1671,9 +1671,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user.
- * We recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user,
+ * with a maximum length of 64 characters. We recommend hashing their username or email
+ * address, in order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*/
fun safetyIdentifier(safetyIdentifier: String) =
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseCreateParams.kt
index c08c22777..45eaef04b 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseCreateParams.kt
@@ -236,9 +236,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user. We
- * recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user, with
+ * a maximum length of 64 characters. We recommend hashing their username or email address, in
+ * order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
@@ -1048,9 +1048,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user.
- * We recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user,
+ * with a maximum length of 64 characters. We recommend hashing their username or email
+ * address, in order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*/
fun safetyIdentifier(safetyIdentifier: String) = apply {
@@ -1964,9 +1964,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be violating
- * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user.
- * We recommend hashing their username or email address, in order to avoid sending us any
- * identifying information.
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user,
+ * with a maximum length of 64 characters. We recommend hashing their username or email
+ * address, in order to avoid sending us any identifying information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
@@ -2881,8 +2881,9 @@ private constructor(
/**
* A stable identifier used to help detect users of your application that may be
* violating OpenAI's usage policies. The IDs should be a string that uniquely
- * identifies each user. We recommend hashing their username or email address, in order
- * to avoid sending us any identifying information.
+ * identifies each user, with a maximum length of 64 characters. We recommend hashing
+ * their username or email address, in order to avoid sending us any identifying
+ * information.
* [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
*/
fun safetyIdentifier(safetyIdentifier: String) =
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponsesClientEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponsesClientEvent.kt
new file mode 100644
index 000000000..4a8eedc5a
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponsesClientEvent.kt
@@ -0,0 +1,3693 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models.responses
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.ObjectCodec
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.SerializerProvider
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
+import com.openai.core.BaseDeserializer
+import com.openai.core.BaseSerializer
+import com.openai.core.Enum
+import com.openai.core.ExcludeMissing
+import com.openai.core.JsonField
+import com.openai.core.JsonMissing
+import com.openai.core.JsonValue
+import com.openai.core.allMaxBy
+import com.openai.core.checkKnown
+import com.openai.core.checkRequired
+import com.openai.core.getOrThrow
+import com.openai.core.toImmutable
+import com.openai.errors.OpenAIInvalidDataException
+import com.openai.models.ChatModel
+import com.openai.models.Reasoning
+import com.openai.models.ResponsesModel
+import java.util.Collections
+import java.util.Objects
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
+
+class ResponsesClientEvent
+@JsonCreator(mode = JsonCreator.Mode.DISABLED)
+private constructor(
+ private val type: JsonValue,
+ private val background: JsonField,
+ private val contextManagement: JsonField>,
+ private val conversation: JsonField,
+ private val include: JsonField>,
+ private val input: JsonField,
+ private val instructions: JsonField,
+ private val maxOutputTokens: JsonField,
+ private val maxToolCalls: JsonField,
+ private val metadata: JsonField,
+ private val model: JsonField,
+ private val parallelToolCalls: JsonField,
+ private val previousResponseId: JsonField,
+ private val prompt: JsonField,
+ private val promptCacheKey: JsonField,
+ private val promptCacheRetention: JsonField,
+ private val reasoning: JsonField,
+ private val safetyIdentifier: JsonField,
+ private val serviceTier: JsonField,
+ private val store: JsonField,
+ private val stream: JsonField,
+ private val streamOptions: JsonField,
+ private val temperature: JsonField,
+ private val text: JsonField,
+ private val toolChoice: JsonField,
+ private val tools: JsonField>,
+ private val topLogprobs: JsonField,
+ private val topP: JsonField,
+ private val truncation: JsonField,
+ private val user: JsonField,
+ private val additionalProperties: MutableMap,
+) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
+ @JsonProperty("background")
+ @ExcludeMissing
+ background: JsonField = JsonMissing.of(),
+ @JsonProperty("context_management")
+ @ExcludeMissing
+ contextManagement: JsonField> = JsonMissing.of(),
+ @JsonProperty("conversation")
+ @ExcludeMissing
+ conversation: JsonField = JsonMissing.of(),
+ @JsonProperty("include")
+ @ExcludeMissing
+ include: JsonField> = JsonMissing.of(),
+ @JsonProperty("input") @ExcludeMissing input: JsonField = JsonMissing.of(),
+ @JsonProperty("instructions")
+ @ExcludeMissing
+ instructions: JsonField = JsonMissing.of(),
+ @JsonProperty("max_output_tokens")
+ @ExcludeMissing
+ maxOutputTokens: JsonField = JsonMissing.of(),
+ @JsonProperty("max_tool_calls")
+ @ExcludeMissing
+ maxToolCalls: JsonField = JsonMissing.of(),
+ @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(),
+ @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(),
+ @JsonProperty("parallel_tool_calls")
+ @ExcludeMissing
+ parallelToolCalls: JsonField = JsonMissing.of(),
+ @JsonProperty("previous_response_id")
+ @ExcludeMissing
+ previousResponseId: JsonField = JsonMissing.of(),
+ @JsonProperty("prompt")
+ @ExcludeMissing
+ prompt: JsonField = JsonMissing.of(),
+ @JsonProperty("prompt_cache_key")
+ @ExcludeMissing
+ promptCacheKey: JsonField = JsonMissing.of(),
+ @JsonProperty("prompt_cache_retention")
+ @ExcludeMissing
+ promptCacheRetention: JsonField = JsonMissing.of(),
+ @JsonProperty("reasoning")
+ @ExcludeMissing
+ reasoning: JsonField = JsonMissing.of(),
+ @JsonProperty("safety_identifier")
+ @ExcludeMissing
+ safetyIdentifier: JsonField = JsonMissing.of(),
+ @JsonProperty("service_tier")
+ @ExcludeMissing
+ serviceTier: JsonField = JsonMissing.of(),
+ @JsonProperty("store") @ExcludeMissing store: JsonField = JsonMissing.of(),
+ @JsonProperty("stream") @ExcludeMissing stream: JsonField = JsonMissing.of(),
+ @JsonProperty("stream_options")
+ @ExcludeMissing
+ streamOptions: JsonField = JsonMissing.of(),
+ @JsonProperty("temperature")
+ @ExcludeMissing
+ temperature: JsonField = JsonMissing.of(),
+ @JsonProperty("text")
+ @ExcludeMissing
+ text: JsonField = JsonMissing.of(),
+ @JsonProperty("tool_choice")
+ @ExcludeMissing
+ toolChoice: JsonField = JsonMissing.of(),
+ @JsonProperty("tools") @ExcludeMissing tools: JsonField> = JsonMissing.of(),
+ @JsonProperty("top_logprobs")
+ @ExcludeMissing
+ topLogprobs: JsonField = JsonMissing.of(),
+ @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(),
+ @JsonProperty("truncation")
+ @ExcludeMissing
+ truncation: JsonField = JsonMissing.of(),
+ @JsonProperty("user") @ExcludeMissing user: JsonField = JsonMissing.of(),
+ ) : this(
+ type,
+ background,
+ contextManagement,
+ conversation,
+ include,
+ input,
+ instructions,
+ maxOutputTokens,
+ maxToolCalls,
+ metadata,
+ model,
+ parallelToolCalls,
+ previousResponseId,
+ prompt,
+ promptCacheKey,
+ promptCacheRetention,
+ reasoning,
+ safetyIdentifier,
+ serviceTier,
+ store,
+ stream,
+ streamOptions,
+ temperature,
+ text,
+ toolChoice,
+ tools,
+ topLogprobs,
+ topP,
+ truncation,
+ user,
+ mutableMapOf(),
+ )
+
+ /**
+ * The type of the client event. Always `response.create`.
+ *
+ * Expected to always return the following:
+ * ```java
+ * JsonValue.from("response.create")
+ * ```
+ *
+ * However, this method can be useful for debugging and logging (e.g. if the server responded
+ * with an unexpected value).
+ */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type
+
+ /**
+ * Whether to run the model response in the background.
+ * [Learn more](https://platform.openai.com/docs/guides/background).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun background(): Optional = background.getOptional("background")
+
+ /**
+ * Context management configuration for this request.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun contextManagement(): Optional> =
+ contextManagement.getOptional("context_management")
+
+ /**
+ * The conversation that this response belongs to. Items from this conversation are prepended to
+ * `input_items` for this response request. Input items and output items from this response are
+ * automatically added to this conversation after this response completes.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun conversation(): Optional = conversation.getOptional("conversation")
+
+ /**
+ * Specify additional output data to include in the model response. Currently supported values
+ * are:
+ * - `web_search_call.action.sources`: Include the sources of the web search tool call.
+ * - `code_interpreter_call.outputs`: Includes the outputs of python code execution in code
+ * interpreter tool call items.
+ * - `computer_call_output.output.image_url`: Include image urls from the computer call output.
+ * - `file_search_call.results`: Include the search results of the file search tool call.
+ * - `message.input_image.image_url`: Include image urls from the input message.
+ * - `message.output_text.logprobs`: Include logprobs with assistant messages.
+ * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning tokens in
+ * reasoning item outputs. This enables reasoning items to be used in multi-turn conversations
+ * when using the Responses API statelessly (like when the `store` parameter is set to
+ * `false`, or when an organization is enrolled in the zero data retention program).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun include(): Optional> = include.getOptional("include")
+
+ /**
+ * Text, image, or file inputs to the model, used to generate a response.
+ *
+ * Learn more:
+ * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
+ * - [Image inputs](https://platform.openai.com/docs/guides/images)
+ * - [File inputs](https://platform.openai.com/docs/guides/pdf-files)
+ * - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)
+ * - [Function calling](https://platform.openai.com/docs/guides/function-calling)
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun input(): Optional = input.getOptional("input")
+
+ /**
+ * A system (or developer) message inserted into the model's context.
+ *
+ * When using along with `previous_response_id`, the instructions from a previous response will
+ * not be carried over to the next response. This makes it simple to swap out system (or
+ * developer) messages in new responses.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun instructions(): Optional = instructions.getOptional("instructions")
+
+ /**
+ * An upper bound for the number of tokens that can be generated for a response, including
+ * visible output tokens and
+ * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun maxOutputTokens(): Optional = maxOutputTokens.getOptional("max_output_tokens")
+
+ /**
+ * The maximum number of total calls to built-in tools that can be processed in a response. This
+ * maximum number applies across all built-in tool calls, not per individual tool. Any further
+ * attempts to call a tool by the model will be ignored.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun maxToolCalls(): Optional = maxToolCalls.getOptional("max_tool_calls")
+
+ /**
+ * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
+ * additional information about the object in a structured format, and querying for objects via
+ * API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum
+ * length of 512 characters.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun metadata(): Optional = metadata.getOptional("metadata")
+
+ /**
+ * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a wide range of
+ * models with different capabilities, performance characteristics, and price points. Refer to
+ * the [model guide](https://platform.openai.com/docs/models) to browse and compare available
+ * models.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun model(): Optional = model.getOptional("model")
+
+ /**
+ * Whether to allow the model to run tool calls in parallel.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun parallelToolCalls(): Optional =
+ parallelToolCalls.getOptional("parallel_tool_calls")
+
+ /**
+ * The unique ID of the previous response to the model. Use this to create multi-turn
+ * conversations. Learn more about
+ * [conversation state](https://platform.openai.com/docs/guides/conversation-state). Cannot be
+ * used in conjunction with `conversation`.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun previousResponseId(): Optional =
+ previousResponseId.getOptional("previous_response_id")
+
+ /**
+ * Reference to a prompt template and its variables.
+ * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun prompt(): Optional = prompt.getOptional("prompt")
+
+ /**
+ * Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.
+ * Replaces the `user` field.
+ * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun promptCacheKey(): Optional = promptCacheKey.getOptional("prompt_cache_key")
+
+ /**
+ * The retention policy for the prompt cache. Set to `24h` to enable extended prompt caching,
+ * which keeps cached prefixes active for longer, up to a maximum of 24 hours.
+ * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun promptCacheRetention(): Optional =
+ promptCacheRetention.getOptional("prompt_cache_retention")
+
+ /**
+ * **gpt-5 and o-series models only**
+ *
+ * Configuration options for
+ * [reasoning models](https://platform.openai.com/docs/guides/reasoning).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun reasoning(): Optional = reasoning.getOptional("reasoning")
+
+ /**
+ * A stable identifier used to help detect users of your application that may be violating
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user, with
+ * a maximum length of 64 characters. We recommend hashing their username or email address, in
+ * order to avoid sending us any identifying information.
+ * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun safetyIdentifier(): Optional = safetyIdentifier.getOptional("safety_identifier")
+
+ /**
+ * Specifies the processing type used for serving the request.
+ * - If set to 'auto', then the request will be processed with the service tier configured in
+ * the Project settings. Unless otherwise configured, the Project will use 'default'.
+ * - If set to 'default', then the request will be processed with the standard pricing and
+ * performance for the selected model.
+ * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
+ * '[priority](https://openai.com/api-priority-processing/)', then the request will be
+ * processed with the corresponding service tier.
+ * - When not set, the default behavior is 'auto'.
+ *
+ * When the `service_tier` parameter is set, the response body will include the `service_tier`
+ * value based on the processing mode actually used to serve the request. This response value
+ * may be different from the value set in the parameter.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun serviceTier(): Optional = serviceTier.getOptional("service_tier")
+
+ /**
+ * Whether to store the generated model response for later retrieval via API.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun store(): Optional = store.getOptional("store")
+
+ /**
+ * If set to true, the model response data will be streamed to the client as it is generated
+ * using
+ * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
+ * See the
+ * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)
+ * for more information.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun stream(): Optional = stream.getOptional("stream")
+
+ /**
+ * Options for streaming responses. Only set this when you set `stream: true`.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun streamOptions(): Optional = streamOptions.getOptional("stream_options")
+
+ /**
+ * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the
+ * output more random, while lower values like 0.2 will make it more focused and deterministic.
+ * We generally recommend altering this or `top_p` but not both.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun temperature(): Optional = temperature.getOptional("temperature")
+
+ /**
+ * Configuration options for a text response from the model. Can be plain text or structured
+ * JSON data. Learn more:
+ * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
+ * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun text(): Optional = text.getOptional("text")
+
+ /**
+ * How the model should select which tool (or tools) to use when generating a response. See the
+ * `tools` parameter to see how to specify which tools the model can call.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun toolChoice(): Optional = toolChoice.getOptional("tool_choice")
+
+ /**
+ * An array of tools the model may call while generating a response. You can specify which tool
+ * to use by setting the `tool_choice` parameter.
+ *
+ * We support the following categories of tools:
+ * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's capabilities,
+ * like [web search](https://platform.openai.com/docs/guides/tools-web-search) or
+ * [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more about
+ * [built-in tools](https://platform.openai.com/docs/guides/tools).
+ * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or predefined
+ * connectors such as Google Drive and SharePoint. Learn more about
+ * [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
+ * - **Function calls (custom tools)**: Functions that are defined by you, enabling the model to
+ * call your own code with strongly typed arguments and outputs. Learn more about
+ * [function calling](https://platform.openai.com/docs/guides/function-calling). You can also
+ * use custom tools to call your own code.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun tools(): Optional> = tools.getOptional("tools")
+
+ /**
+ * An integer between 0 and 20 specifying the number of most likely tokens to return at each
+ * token position, each with an associated log probability.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun topLogprobs(): Optional = topLogprobs.getOptional("top_logprobs")
+
+ /**
+ * An alternative to sampling with temperature, called nucleus sampling, where the model
+ * considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens
+ * comprising the top 10% probability mass are considered.
+ *
+ * We generally recommend altering this or `temperature` but not both.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun topP(): Optional = topP.getOptional("top_p")
+
+ /**
+ * The truncation strategy to use for the model response.
+ * - `auto`: If the input to this Response exceeds the model's context window size, the model
+ * will truncate the response to fit the context window by dropping items from the beginning
+ * of the conversation.
+ * - `disabled` (default): If the input size will exceed the context window size for a model,
+ * the request will fail with a 400 error.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun truncation(): Optional = truncation.getOptional("truncation")
+
+ /**
+ * This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
+ * `prompt_cache_key` instead to maintain caching optimizations. A stable identifier for your
+ * end-users. Used to boost cache hit rates by better bucketing similar requests and to help
+ * OpenAI detect and prevent abuse.
+ * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ @Deprecated("deprecated") fun user(): Optional = user.getOptional("user")
+
+ /**
+ * Returns the raw JSON value of [background].
+ *
+ * Unlike [background], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("background") @ExcludeMissing fun _background(): JsonField = background
+
+ /**
+ * Returns the raw JSON value of [contextManagement].
+ *
+ * Unlike [contextManagement], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("context_management")
+ @ExcludeMissing
+ fun _contextManagement(): JsonField> = contextManagement
+
+ /**
+ * Returns the raw JSON value of [conversation].
+ *
+ * Unlike [conversation], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("conversation")
+ @ExcludeMissing
+ fun _conversation(): JsonField = conversation
+
+ /**
+ * Returns the raw JSON value of [include].
+ *
+ * Unlike [include], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("include")
+ @ExcludeMissing
+ fun _include(): JsonField> = include
+
+ /**
+ * Returns the raw JSON value of [input].
+ *
+ * Unlike [input], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("input") @ExcludeMissing fun _input(): JsonField = input
+
+ /**
+ * Returns the raw JSON value of [instructions].
+ *
+ * Unlike [instructions], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("instructions")
+ @ExcludeMissing
+ fun _instructions(): JsonField = instructions
+
+ /**
+ * Returns the raw JSON value of [maxOutputTokens].
+ *
+ * Unlike [maxOutputTokens], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("max_output_tokens")
+ @ExcludeMissing
+ fun _maxOutputTokens(): JsonField = maxOutputTokens
+
+ /**
+ * Returns the raw JSON value of [maxToolCalls].
+ *
+ * Unlike [maxToolCalls], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("max_tool_calls")
+ @ExcludeMissing
+ fun _maxToolCalls(): JsonField = maxToolCalls
+
+ /**
+ * Returns the raw JSON value of [metadata].
+ *
+ * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata
+
+ /**
+ * Returns the raw JSON value of [model].
+ *
+ * Unlike [model], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model
+
+ /**
+ * Returns the raw JSON value of [parallelToolCalls].
+ *
+ * Unlike [parallelToolCalls], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("parallel_tool_calls")
+ @ExcludeMissing
+ fun _parallelToolCalls(): JsonField = parallelToolCalls
+
+ /**
+ * Returns the raw JSON value of [previousResponseId].
+ *
+ * Unlike [previousResponseId], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("previous_response_id")
+ @ExcludeMissing
+ fun _previousResponseId(): JsonField = previousResponseId
+
+ /**
+ * Returns the raw JSON value of [prompt].
+ *
+ * Unlike [prompt], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("prompt") @ExcludeMissing fun _prompt(): JsonField = prompt
+
+ /**
+ * Returns the raw JSON value of [promptCacheKey].
+ *
+ * Unlike [promptCacheKey], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("prompt_cache_key")
+ @ExcludeMissing
+ fun _promptCacheKey(): JsonField = promptCacheKey
+
+ /**
+ * Returns the raw JSON value of [promptCacheRetention].
+ *
+ * Unlike [promptCacheRetention], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("prompt_cache_retention")
+ @ExcludeMissing
+ fun _promptCacheRetention(): JsonField = promptCacheRetention
+
+ /**
+ * Returns the raw JSON value of [reasoning].
+ *
+ * Unlike [reasoning], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("reasoning") @ExcludeMissing fun _reasoning(): JsonField = reasoning
+
+ /**
+ * Returns the raw JSON value of [safetyIdentifier].
+ *
+ * Unlike [safetyIdentifier], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("safety_identifier")
+ @ExcludeMissing
+ fun _safetyIdentifier(): JsonField = safetyIdentifier
+
+ /**
+ * Returns the raw JSON value of [serviceTier].
+ *
+ * Unlike [serviceTier], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("service_tier")
+ @ExcludeMissing
+ fun _serviceTier(): JsonField = serviceTier
+
+ /**
+ * Returns the raw JSON value of [store].
+ *
+ * Unlike [store], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("store") @ExcludeMissing fun _store(): JsonField = store
+
+ /**
+ * Returns the raw JSON value of [stream].
+ *
+ * Unlike [stream], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("stream") @ExcludeMissing fun _stream(): JsonField = stream
+
+ /**
+ * Returns the raw JSON value of [streamOptions].
+ *
+ * Unlike [streamOptions], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("stream_options")
+ @ExcludeMissing
+ fun _streamOptions(): JsonField = streamOptions
+
+ /**
+ * Returns the raw JSON value of [temperature].
+ *
+ * Unlike [temperature], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("temperature") @ExcludeMissing fun _temperature(): JsonField = temperature
+
+ /**
+ * Returns the raw JSON value of [text].
+ *
+ * Unlike [text], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text
+
+ /**
+ * Returns the raw JSON value of [toolChoice].
+ *
+ * Unlike [toolChoice], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("tool_choice")
+ @ExcludeMissing
+ fun _toolChoice(): JsonField = toolChoice
+
+ /**
+ * Returns the raw JSON value of [tools].
+ *
+ * Unlike [tools], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("tools") @ExcludeMissing fun _tools(): JsonField> = tools
+
+ /**
+ * Returns the raw JSON value of [topLogprobs].
+ *
+ * Unlike [topLogprobs], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("top_logprobs") @ExcludeMissing fun _topLogprobs(): JsonField = topLogprobs
+
+ /**
+ * Returns the raw JSON value of [topP].
+ *
+ * Unlike [topP], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("top_p") @ExcludeMissing fun _topP(): JsonField = topP
+
+ /**
+ * Returns the raw JSON value of [truncation].
+ *
+ * Unlike [truncation], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("truncation")
+ @ExcludeMissing
+ fun _truncation(): JsonField = truncation
+
+ /**
+ * Returns the raw JSON value of [user].
+ *
+ * Unlike [user], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @Deprecated("deprecated")
+ @JsonProperty("user")
+ @ExcludeMissing
+ fun _user(): JsonField = user
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [ResponsesClientEvent]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [ResponsesClientEvent]. */
+ class Builder internal constructor() {
+
+ private var type: JsonValue = JsonValue.from("response.create")
+ private var background: JsonField = JsonMissing.of()
+ private var contextManagement: JsonField>? = null
+ private var conversation: JsonField = JsonMissing.of()
+ private var include: JsonField>? = null
+ private var input: JsonField = JsonMissing.of()
+ private var instructions: JsonField = JsonMissing.of()
+ private var maxOutputTokens: JsonField = JsonMissing.of()
+ private var maxToolCalls: JsonField = JsonMissing.of()
+ private var metadata: JsonField = JsonMissing.of()
+ private var model: JsonField = JsonMissing.of()
+ private var parallelToolCalls: JsonField = JsonMissing.of()
+ private var previousResponseId: JsonField = JsonMissing.of()
+ private var prompt: JsonField = JsonMissing.of()
+ private var promptCacheKey: JsonField = JsonMissing.of()
+ private var promptCacheRetention: JsonField = JsonMissing.of()
+ private var reasoning: JsonField = JsonMissing.of()
+ private var safetyIdentifier: JsonField = JsonMissing.of()
+ private var serviceTier: JsonField = JsonMissing.of()
+ private var store: JsonField = JsonMissing.of()
+ private var stream: JsonField = JsonMissing.of()
+ private var streamOptions: JsonField = JsonMissing.of()
+ private var temperature: JsonField = JsonMissing.of()
+ private var text: JsonField = JsonMissing.of()
+ private var toolChoice: JsonField = JsonMissing.of()
+ private var tools: JsonField>? = null
+ private var topLogprobs: JsonField = JsonMissing.of()
+ private var topP: JsonField = JsonMissing.of()
+ private var truncation: JsonField = JsonMissing.of()
+ private var user: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(responsesClientEvent: ResponsesClientEvent) = apply {
+ type = responsesClientEvent.type
+ background = responsesClientEvent.background
+ contextManagement = responsesClientEvent.contextManagement.map { it.toMutableList() }
+ conversation = responsesClientEvent.conversation
+ include = responsesClientEvent.include.map { it.toMutableList() }
+ input = responsesClientEvent.input
+ instructions = responsesClientEvent.instructions
+ maxOutputTokens = responsesClientEvent.maxOutputTokens
+ maxToolCalls = responsesClientEvent.maxToolCalls
+ metadata = responsesClientEvent.metadata
+ model = responsesClientEvent.model
+ parallelToolCalls = responsesClientEvent.parallelToolCalls
+ previousResponseId = responsesClientEvent.previousResponseId
+ prompt = responsesClientEvent.prompt
+ promptCacheKey = responsesClientEvent.promptCacheKey
+ promptCacheRetention = responsesClientEvent.promptCacheRetention
+ reasoning = responsesClientEvent.reasoning
+ safetyIdentifier = responsesClientEvent.safetyIdentifier
+ serviceTier = responsesClientEvent.serviceTier
+ store = responsesClientEvent.store
+ stream = responsesClientEvent.stream
+ streamOptions = responsesClientEvent.streamOptions
+ temperature = responsesClientEvent.temperature
+ text = responsesClientEvent.text
+ toolChoice = responsesClientEvent.toolChoice
+ tools = responsesClientEvent.tools.map { it.toMutableList() }
+ topLogprobs = responsesClientEvent.topLogprobs
+ topP = responsesClientEvent.topP
+ truncation = responsesClientEvent.truncation
+ user = responsesClientEvent.user
+ additionalProperties = responsesClientEvent.additionalProperties.toMutableMap()
+ }
+
+ /**
+ * Sets the field to an arbitrary JSON value.
+ *
+ * It is usually unnecessary to call this method because the field defaults to the
+ * following:
+ * ```java
+ * JsonValue.from("response.create")
+ * ```
+ *
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun type(type: JsonValue) = apply { this.type = type }
+
+ /**
+ * Whether to run the model response in the background.
+ * [Learn more](https://platform.openai.com/docs/guides/background).
+ */
+ fun background(background: Boolean?) = background(JsonField.ofNullable(background))
+
+ /**
+ * Alias for [Builder.background].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun background(background: Boolean) = background(background as Boolean?)
+
+ /** Alias for calling [Builder.background] with `background.orElse(null)`. */
+ fun background(background: Optional) = background(background.getOrNull())
+
+ /**
+ * Sets [Builder.background] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.background] with a well-typed [Boolean] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun background(background: JsonField) = apply { this.background = background }
+
+ /** Context management configuration for this request. */
+ fun contextManagement(contextManagement: List?) =
+ contextManagement(JsonField.ofNullable(contextManagement))
+
+ /** Alias for calling [Builder.contextManagement] with `contextManagement.orElse(null)`. */
+ fun contextManagement(contextManagement: Optional>) =
+ contextManagement(contextManagement.getOrNull())
+
+ /**
+ * Sets [Builder.contextManagement] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.contextManagement] with a well-typed
+ * `List` value instead. This method is primarily for setting the field
+ * to an undocumented or not yet supported value.
+ */
+ fun contextManagement(contextManagement: JsonField>) = apply {
+ this.contextManagement = contextManagement.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [ContextManagement] to [Builder.contextManagement].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addContextManagement(contextManagement: ContextManagement) = apply {
+ this.contextManagement =
+ (this.contextManagement ?: JsonField.of(mutableListOf())).also {
+ checkKnown("contextManagement", it).add(contextManagement)
+ }
+ }
+
+ /**
+ * The conversation that this response belongs to. Items from this conversation are
+ * prepended to `input_items` for this response request. Input items and output items from
+ * this response are automatically added to this conversation after this response completes.
+ */
+ fun conversation(conversation: Conversation?) =
+ conversation(JsonField.ofNullable(conversation))
+
+ /** Alias for calling [Builder.conversation] with `conversation.orElse(null)`. */
+ fun conversation(conversation: Optional) =
+ conversation(conversation.getOrNull())
+
+ /**
+ * Sets [Builder.conversation] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.conversation] with a well-typed [Conversation] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun conversation(conversation: JsonField) = apply {
+ this.conversation = conversation
+ }
+
+ /** Alias for calling [conversation] with `Conversation.ofId(id)`. */
+ fun conversation(id: String) = conversation(Conversation.ofId(id))
+
+ /**
+ * Alias for calling [conversation] with
+ * `Conversation.ofResponseConversationParam(responseConversationParam)`.
+ */
+ fun conversation(responseConversationParam: ResponseConversationParam) =
+ conversation(Conversation.ofResponseConversationParam(responseConversationParam))
+
+ /**
+ * Specify additional output data to include in the model response. Currently supported
+ * values are:
+ * - `web_search_call.action.sources`: Include the sources of the web search tool call.
+ * - `code_interpreter_call.outputs`: Includes the outputs of python code execution in code
+ * interpreter tool call items.
+ * - `computer_call_output.output.image_url`: Include image urls from the computer call
+ * output.
+ * - `file_search_call.results`: Include the search results of the file search tool call.
+ * - `message.input_image.image_url`: Include image urls from the input message.
+ * - `message.output_text.logprobs`: Include logprobs with assistant messages.
+ * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning tokens in
+ * reasoning item outputs. This enables reasoning items to be used in multi-turn
+ * conversations when using the Responses API statelessly (like when the `store` parameter
+ * is set to `false`, or when an organization is enrolled in the zero data retention
+ * program).
+ */
+ fun include(include: List?) = include(JsonField.ofNullable(include))
+
+ /** Alias for calling [Builder.include] with `include.orElse(null)`. */
+ fun include(include: Optional>) = include(include.getOrNull())
+
+ /**
+ * Sets [Builder.include] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.include] with a well-typed `List`
+ * value instead. This method is primarily for setting the field to an undocumented or not
+ * yet supported value.
+ */
+ fun include(include: JsonField>) = apply {
+ this.include = include.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [ResponseIncludable] to [Builder.include].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addInclude(include: ResponseIncludable) = apply {
+ this.include =
+ (this.include ?: JsonField.of(mutableListOf())).also {
+ checkKnown("include", it).add(include)
+ }
+ }
+
+ /**
+ * Text, image, or file inputs to the model, used to generate a response.
+ *
+ * Learn more:
+ * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
+ * - [Image inputs](https://platform.openai.com/docs/guides/images)
+ * - [File inputs](https://platform.openai.com/docs/guides/pdf-files)
+ * - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)
+ * - [Function calling](https://platform.openai.com/docs/guides/function-calling)
+ */
+ fun input(input: Input) = input(JsonField.of(input))
+
+ /**
+ * Sets [Builder.input] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.input] with a well-typed [Input] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported value.
+ */
+ fun input(input: JsonField) = apply { this.input = input }
+
+ /** Alias for calling [input] with `Input.ofText(text)`. */
+ fun input(text: String) = input(Input.ofText(text))
+
+ /** Alias for calling [input] with `Input.ofResponse(response)`. */
+ fun inputOfResponse(response: List) = input(Input.ofResponse(response))
+
+ /**
+ * A system (or developer) message inserted into the model's context.
+ *
+ * When using along with `previous_response_id`, the instructions from a previous response
+ * will not be carried over to the next response. This makes it simple to swap out system
+ * (or developer) messages in new responses.
+ */
+ fun instructions(instructions: String?) = instructions(JsonField.ofNullable(instructions))
+
+ /** Alias for calling [Builder.instructions] with `instructions.orElse(null)`. */
+ fun instructions(instructions: Optional) = instructions(instructions.getOrNull())
+
+ /**
+ * Sets [Builder.instructions] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.instructions] with a well-typed [String] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun instructions(instructions: JsonField) = apply {
+ this.instructions = instructions
+ }
+
+ /**
+ * An upper bound for the number of tokens that can be generated for a response, including
+ * visible output tokens and
+ * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
+ */
+ fun maxOutputTokens(maxOutputTokens: Long?) =
+ maxOutputTokens(JsonField.ofNullable(maxOutputTokens))
+
+ /**
+ * Alias for [Builder.maxOutputTokens].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun maxOutputTokens(maxOutputTokens: Long) = maxOutputTokens(maxOutputTokens as Long?)
+
+ /** Alias for calling [Builder.maxOutputTokens] with `maxOutputTokens.orElse(null)`. */
+ fun maxOutputTokens(maxOutputTokens: Optional) =
+ maxOutputTokens(maxOutputTokens.getOrNull())
+
+ /**
+ * Sets [Builder.maxOutputTokens] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.maxOutputTokens] with a well-typed [Long] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun maxOutputTokens(maxOutputTokens: JsonField) = apply {
+ this.maxOutputTokens = maxOutputTokens
+ }
+
+ /**
+ * The maximum number of total calls to built-in tools that can be processed in a response.
+ * This maximum number applies across all built-in tool calls, not per individual tool. Any
+ * further attempts to call a tool by the model will be ignored.
+ */
+ fun maxToolCalls(maxToolCalls: Long?) = maxToolCalls(JsonField.ofNullable(maxToolCalls))
+
+ /**
+ * Alias for [Builder.maxToolCalls].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun maxToolCalls(maxToolCalls: Long) = maxToolCalls(maxToolCalls as Long?)
+
+ /** Alias for calling [Builder.maxToolCalls] with `maxToolCalls.orElse(null)`. */
+ fun maxToolCalls(maxToolCalls: Optional) = maxToolCalls(maxToolCalls.getOrNull())
+
+ /**
+ * Sets [Builder.maxToolCalls] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.maxToolCalls] with a well-typed [Long] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun maxToolCalls(maxToolCalls: JsonField) = apply { this.maxToolCalls = maxToolCalls }
+
+ /**
+ * Set of 16 key-value pairs that can be attached to an object. This can be useful for
+ * storing additional information about the object in a structured format, and querying for
+ * objects via API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a
+ * maximum length of 512 characters.
+ */
+ fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata))
+
+ /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */
+ fun metadata(metadata: Optional) = metadata(metadata.getOrNull())
+
+ /**
+ * Sets [Builder.metadata] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun metadata(metadata: JsonField) = apply { this.metadata = metadata }
+
+ /**
+ * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a wide range
+ * of models with different capabilities, performance characteristics, and price points.
+ * Refer to the [model guide](https://platform.openai.com/docs/models) to browse and compare
+ * available models.
+ */
+ fun model(model: ResponsesModel) = model(JsonField.of(model))
+
+ /**
+ * Sets [Builder.model] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.model] with a well-typed [ResponsesModel] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun model(model: JsonField) = apply { this.model = model }
+
+ /** Alias for calling [model] with `ResponsesModel.ofString(string)`. */
+ fun model(string: String) = model(ResponsesModel.ofString(string))
+
+ /** Alias for calling [model] with `ResponsesModel.ofChat(chat)`. */
+ fun model(chat: ChatModel) = model(ResponsesModel.ofChat(chat))
+
+ /** Alias for calling [model] with `ResponsesModel.ofOnly(only)`. */
+ fun model(only: ResponsesModel.ResponsesOnlyModel) = model(ResponsesModel.ofOnly(only))
+
+ /** Whether to allow the model to run tool calls in parallel. */
+ fun parallelToolCalls(parallelToolCalls: Boolean?) =
+ parallelToolCalls(JsonField.ofNullable(parallelToolCalls))
+
+ /**
+ * Alias for [Builder.parallelToolCalls].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun parallelToolCalls(parallelToolCalls: Boolean) =
+ parallelToolCalls(parallelToolCalls as Boolean?)
+
+ /** Alias for calling [Builder.parallelToolCalls] with `parallelToolCalls.orElse(null)`. */
+ fun parallelToolCalls(parallelToolCalls: Optional) =
+ parallelToolCalls(parallelToolCalls.getOrNull())
+
+ /**
+ * Sets [Builder.parallelToolCalls] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.parallelToolCalls] with a well-typed [Boolean] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun parallelToolCalls(parallelToolCalls: JsonField) = apply {
+ this.parallelToolCalls = parallelToolCalls
+ }
+
+ /**
+ * The unique ID of the previous response to the model. Use this to create multi-turn
+ * conversations. Learn more about
+ * [conversation state](https://platform.openai.com/docs/guides/conversation-state). Cannot
+ * be used in conjunction with `conversation`.
+ */
+ fun previousResponseId(previousResponseId: String?) =
+ previousResponseId(JsonField.ofNullable(previousResponseId))
+
+ /**
+ * Alias for calling [Builder.previousResponseId] with `previousResponseId.orElse(null)`.
+ */
+ fun previousResponseId(previousResponseId: Optional) =
+ previousResponseId(previousResponseId.getOrNull())
+
+ /**
+ * Sets [Builder.previousResponseId] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.previousResponseId] with a well-typed [String] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun previousResponseId(previousResponseId: JsonField) = apply {
+ this.previousResponseId = previousResponseId
+ }
+
+ /**
+ * Reference to a prompt template and its variables.
+ * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
+ */
+ fun prompt(prompt: ResponsePrompt?) = prompt(JsonField.ofNullable(prompt))
+
+ /** Alias for calling [Builder.prompt] with `prompt.orElse(null)`. */
+ fun prompt(prompt: Optional) = prompt(prompt.getOrNull())
+
+ /**
+ * Sets [Builder.prompt] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.prompt] with a well-typed [ResponsePrompt] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun prompt(prompt: JsonField) = apply { this.prompt = prompt }
+
+ /**
+ * Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.
+ * Replaces the `user` field.
+ * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
+ */
+ fun promptCacheKey(promptCacheKey: String) = promptCacheKey(JsonField.of(promptCacheKey))
+
+ /**
+ * Sets [Builder.promptCacheKey] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.promptCacheKey] with a well-typed [String] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun promptCacheKey(promptCacheKey: JsonField) = apply {
+ this.promptCacheKey = promptCacheKey
+ }
+
+ /**
+ * The retention policy for the prompt cache. Set to `24h` to enable extended prompt
+ * caching, which keeps cached prefixes active for longer, up to a maximum of 24 hours.
+ * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).
+ */
+ fun promptCacheRetention(promptCacheRetention: PromptCacheRetention?) =
+ promptCacheRetention(JsonField.ofNullable(promptCacheRetention))
+
+ /**
+ * Alias for calling [Builder.promptCacheRetention] with
+ * `promptCacheRetention.orElse(null)`.
+ */
+ fun promptCacheRetention(promptCacheRetention: Optional) =
+ promptCacheRetention(promptCacheRetention.getOrNull())
+
+ /**
+ * Sets [Builder.promptCacheRetention] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.promptCacheRetention] with a well-typed
+ * [PromptCacheRetention] value instead. This method is primarily for setting the field to
+ * an undocumented or not yet supported value.
+ */
+ fun promptCacheRetention(promptCacheRetention: JsonField) = apply {
+ this.promptCacheRetention = promptCacheRetention
+ }
+
+ /**
+ * **gpt-5 and o-series models only**
+ *
+ * Configuration options for
+ * [reasoning models](https://platform.openai.com/docs/guides/reasoning).
+ */
+ fun reasoning(reasoning: Reasoning?) = reasoning(JsonField.ofNullable(reasoning))
+
+ /** Alias for calling [Builder.reasoning] with `reasoning.orElse(null)`. */
+ fun reasoning(reasoning: Optional) = reasoning(reasoning.getOrNull())
+
+ /**
+ * Sets [Builder.reasoning] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.reasoning] with a well-typed [Reasoning] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun reasoning(reasoning: JsonField) = apply { this.reasoning = reasoning }
+
+ /**
+ * A stable identifier used to help detect users of your application that may be violating
+ * OpenAI's usage policies. The IDs should be a string that uniquely identifies each user,
+ * with a maximum length of 64 characters. We recommend hashing their username or email
+ * address, in order to avoid sending us any identifying information.
+ * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
+ */
+ fun safetyIdentifier(safetyIdentifier: String) =
+ safetyIdentifier(JsonField.of(safetyIdentifier))
+
+ /**
+ * Sets [Builder.safetyIdentifier] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.safetyIdentifier] with a well-typed [String] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun safetyIdentifier(safetyIdentifier: JsonField) = apply {
+ this.safetyIdentifier = safetyIdentifier
+ }
+
+ /**
+ * Specifies the processing type used for serving the request.
+ * - If set to 'auto', then the request will be processed with the service tier configured
+ * in the Project settings. Unless otherwise configured, the Project will use 'default'.
+ * - If set to 'default', then the request will be processed with the standard pricing and
+ * performance for the selected model.
+ * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
+ * '[priority](https://openai.com/api-priority-processing/)', then the request will be
+ * processed with the corresponding service tier.
+ * - When not set, the default behavior is 'auto'.
+ *
+ * When the `service_tier` parameter is set, the response body will include the
+ * `service_tier` value based on the processing mode actually used to serve the request.
+ * This response value may be different from the value set in the parameter.
+ */
+ fun serviceTier(serviceTier: ServiceTier?) = serviceTier(JsonField.ofNullable(serviceTier))
+
+ /** Alias for calling [Builder.serviceTier] with `serviceTier.orElse(null)`. */
+ fun serviceTier(serviceTier: Optional) = serviceTier(serviceTier.getOrNull())
+
+ /**
+ * Sets [Builder.serviceTier] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.serviceTier] with a well-typed [ServiceTier] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun serviceTier(serviceTier: JsonField) = apply {
+ this.serviceTier = serviceTier
+ }
+
+ /** Whether to store the generated model response for later retrieval via API. */
+ fun store(store: Boolean?) = store(JsonField.ofNullable(store))
+
+ /**
+ * Alias for [Builder.store].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun store(store: Boolean) = store(store as Boolean?)
+
+ /** Alias for calling [Builder.store] with `store.orElse(null)`. */
+ fun store(store: Optional) = store(store.getOrNull())
+
+ /**
+ * Sets [Builder.store] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.store] with a well-typed [Boolean] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported value.
+ */
+ fun store(store: JsonField) = apply { this.store = store }
+
+ /**
+ * If set to true, the model response data will be streamed to the client as it is generated
+ * using
+ * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
+ * See the
+ * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)
+ * for more information.
+ */
+ fun stream(stream: Boolean?) = stream(JsonField.ofNullable(stream))
+
+ /**
+ * Alias for [Builder.stream].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun stream(stream: Boolean) = stream(stream as Boolean?)
+
+ /** Alias for calling [Builder.stream] with `stream.orElse(null)`. */
+ fun stream(stream: Optional) = stream(stream.getOrNull())
+
+ /**
+ * Sets [Builder.stream] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.stream] with a well-typed [Boolean] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported value.
+ */
+ fun stream(stream: JsonField) = apply { this.stream = stream }
+
+ /** Options for streaming responses. Only set this when you set `stream: true`. */
+ fun streamOptions(streamOptions: StreamOptions?) =
+ streamOptions(JsonField.ofNullable(streamOptions))
+
+ /** Alias for calling [Builder.streamOptions] with `streamOptions.orElse(null)`. */
+ fun streamOptions(streamOptions: Optional) =
+ streamOptions(streamOptions.getOrNull())
+
+ /**
+ * Sets [Builder.streamOptions] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.streamOptions] with a well-typed [StreamOptions] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun streamOptions(streamOptions: JsonField) = apply {
+ this.streamOptions = streamOptions
+ }
+
+ /**
+ * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the
+ * output more random, while lower values like 0.2 will make it more focused and
+ * deterministic. We generally recommend altering this or `top_p` but not both.
+ */
+ fun temperature(temperature: Double?) = temperature(JsonField.ofNullable(temperature))
+
+ /**
+ * Alias for [Builder.temperature].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun temperature(temperature: Double) = temperature(temperature as Double?)
+
+ /** Alias for calling [Builder.temperature] with `temperature.orElse(null)`. */
+ fun temperature(temperature: Optional) = temperature(temperature.getOrNull())
+
+ /**
+ * Sets [Builder.temperature] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.temperature] with a well-typed [Double] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun temperature(temperature: JsonField) = apply { this.temperature = temperature }
+
+ /**
+ * Configuration options for a text response from the model. Can be plain text or structured
+ * JSON data. Learn more:
+ * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
+ * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
+ */
+ fun text(text: ResponseTextConfig) = text(JsonField.of(text))
+
+ /**
+ * Sets [Builder.text] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.text] with a well-typed [ResponseTextConfig] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun text(text: JsonField) = apply { this.text = text }
+
+ /**
+ * How the model should select which tool (or tools) to use when generating a response. See
+ * the `tools` parameter to see how to specify which tools the model can call.
+ */
+ fun toolChoice(toolChoice: ToolChoice) = toolChoice(JsonField.of(toolChoice))
+
+ /**
+ * Sets [Builder.toolChoice] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.toolChoice] with a well-typed [ToolChoice] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun toolChoice(toolChoice: JsonField) = apply { this.toolChoice = toolChoice }
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofOptions(options)`. */
+ fun toolChoice(options: ToolChoiceOptions) = toolChoice(ToolChoice.ofOptions(options))
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofAllowed(allowed)`. */
+ fun toolChoice(allowed: ToolChoiceAllowed) = toolChoice(ToolChoice.ofAllowed(allowed))
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofTypes(types)`. */
+ fun toolChoice(types: ToolChoiceTypes) = toolChoice(ToolChoice.ofTypes(types))
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofFunction(function)`. */
+ fun toolChoice(function: ToolChoiceFunction) = toolChoice(ToolChoice.ofFunction(function))
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofMcp(mcp)`. */
+ fun toolChoice(mcp: ToolChoiceMcp) = toolChoice(ToolChoice.ofMcp(mcp))
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofCustom(custom)`. */
+ fun toolChoice(custom: ToolChoiceCustom) = toolChoice(ToolChoice.ofCustom(custom))
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofApplyPatch(applyPatch)`. */
+ fun toolChoice(applyPatch: ToolChoiceApplyPatch) =
+ toolChoice(ToolChoice.ofApplyPatch(applyPatch))
+
+ /** Alias for calling [toolChoice] with `ToolChoice.ofShell(shell)`. */
+ fun toolChoice(shell: ToolChoiceShell) = toolChoice(ToolChoice.ofShell(shell))
+
+ /**
+ * An array of tools the model may call while generating a response. You can specify which
+ * tool to use by setting the `tool_choice` parameter.
+ *
+ * We support the following categories of tools:
+ * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's
+ * capabilities, like
+ * [web search](https://platform.openai.com/docs/guides/tools-web-search) or
+ * [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more
+ * about [built-in tools](https://platform.openai.com/docs/guides/tools).
+ * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or
+ * predefined connectors such as Google Drive and SharePoint. Learn more about
+ * [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
+ * - **Function calls (custom tools)**: Functions that are defined by you, enabling the
+ * model to call your own code with strongly typed arguments and outputs. Learn more about
+ * [function calling](https://platform.openai.com/docs/guides/function-calling). You can
+ * also use custom tools to call your own code.
+ */
+ fun tools(tools: List) = tools(JsonField.of(tools))
+
+ /**
+ * Sets [Builder.tools] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.tools] with a well-typed `List` value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun tools(tools: JsonField>) = apply {
+ this.tools = tools.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [Tool] to [tools].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addTool(tool: Tool) = apply {
+ tools =
+ (tools ?: JsonField.of(mutableListOf())).also { checkKnown("tools", it).add(tool) }
+ }
+
+ /** Alias for calling [addTool] with `Tool.ofFunction(function)`. */
+ fun addTool(function: FunctionTool) = addTool(Tool.ofFunction(function))
+
+ /** Alias for calling [addTool] with `Tool.ofFileSearch(fileSearch)`. */
+ fun addTool(fileSearch: FileSearchTool) = addTool(Tool.ofFileSearch(fileSearch))
+
+ /**
+ * Alias for calling [addTool] with the following:
+ * ```java
+ * FileSearchTool.builder()
+ * .vectorStoreIds(vectorStoreIds)
+ * .build()
+ * ```
+ */
+ fun addFileSearchTool(vectorStoreIds: List) =
+ addTool(FileSearchTool.builder().vectorStoreIds(vectorStoreIds).build())
+
+ /** Alias for calling [addTool] with `Tool.ofComputerUsePreview(computerUsePreview)`. */
+ fun addTool(computerUsePreview: ComputerTool) =
+ addTool(Tool.ofComputerUsePreview(computerUsePreview))
+
+ /** Alias for calling [addTool] with `Tool.ofWebSearch(webSearch)`. */
+ fun addTool(webSearch: WebSearchTool) = addTool(Tool.ofWebSearch(webSearch))
+
+ /** Alias for calling [addTool] with `Tool.ofMcp(mcp)`. */
+ fun addTool(mcp: Tool.Mcp) = addTool(Tool.ofMcp(mcp))
+
+ /**
+ * Alias for calling [addTool] with the following:
+ * ```java
+ * Tool.Mcp.builder()
+ * .serverLabel(serverLabel)
+ * .build()
+ * ```
+ */
+ fun addMcpTool(serverLabel: String) =
+ addTool(Tool.Mcp.builder().serverLabel(serverLabel).build())
+
+ /** Alias for calling [addTool] with `Tool.ofCodeInterpreter(codeInterpreter)`. */
+ fun addTool(codeInterpreter: Tool.CodeInterpreter) =
+ addTool(Tool.ofCodeInterpreter(codeInterpreter))
+
+ /**
+ * Alias for calling [addTool] with the following:
+ * ```java
+ * Tool.CodeInterpreter.builder()
+ * .container(container)
+ * .build()
+ * ```
+ */
+ fun addCodeInterpreterTool(container: Tool.CodeInterpreter.Container) =
+ addTool(Tool.CodeInterpreter.builder().container(container).build())
+
+ /**
+ * Alias for calling [addCodeInterpreterTool] with
+ * `Tool.CodeInterpreter.Container.ofString(string)`.
+ */
+ fun addCodeInterpreterTool(string: String) =
+ addCodeInterpreterTool(Tool.CodeInterpreter.Container.ofString(string))
+
+ /**
+ * Alias for calling [addCodeInterpreterTool] with
+ * `Tool.CodeInterpreter.Container.ofCodeInterpreterToolAuto(codeInterpreterToolAuto)`.
+ */
+ fun addCodeInterpreterTool(
+ codeInterpreterToolAuto: Tool.CodeInterpreter.Container.CodeInterpreterToolAuto
+ ) =
+ addCodeInterpreterTool(
+ Tool.CodeInterpreter.Container.ofCodeInterpreterToolAuto(codeInterpreterToolAuto)
+ )
+
+ /** Alias for calling [addTool] with `Tool.ofImageGeneration(imageGeneration)`. */
+ fun addTool(imageGeneration: Tool.ImageGeneration) =
+ addTool(Tool.ofImageGeneration(imageGeneration))
+
+ /** Alias for calling [addTool] with `Tool.ofLocalShell()`. */
+ fun addToolLocalShell() = addTool(Tool.ofLocalShell())
+
+ /** Alias for calling [addTool] with `Tool.ofShell(shell)`. */
+ fun addTool(shell: FunctionShellTool) = addTool(Tool.ofShell(shell))
+
+ /** Alias for calling [addTool] with `Tool.ofCustom(custom)`. */
+ fun addTool(custom: CustomTool) = addTool(Tool.ofCustom(custom))
+
+ /**
+ * Alias for calling [addTool] with the following:
+ * ```java
+ * CustomTool.builder()
+ * .name(name)
+ * .build()
+ * ```
+ */
+ fun addCustomTool(name: String) = addTool(CustomTool.builder().name(name).build())
+
+ /** Alias for calling [addTool] with `Tool.ofWebSearchPreview(webSearchPreview)`. */
+ fun addTool(webSearchPreview: WebSearchPreviewTool) =
+ addTool(Tool.ofWebSearchPreview(webSearchPreview))
+
+ /** Alias for calling [addTool] with `Tool.ofApplyPatch(applyPatch)`. */
+ fun addTool(applyPatch: ApplyPatchTool) = addTool(Tool.ofApplyPatch(applyPatch))
+
+ /**
+ * An integer between 0 and 20 specifying the number of most likely tokens to return at each
+ * token position, each with an associated log probability.
+ */
+ fun topLogprobs(topLogprobs: Long?) = topLogprobs(JsonField.ofNullable(topLogprobs))
+
+ /**
+ * Alias for [Builder.topLogprobs].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun topLogprobs(topLogprobs: Long) = topLogprobs(topLogprobs as Long?)
+
+ /** Alias for calling [Builder.topLogprobs] with `topLogprobs.orElse(null)`. */
+ fun topLogprobs(topLogprobs: Optional) = topLogprobs(topLogprobs.getOrNull())
+
+ /**
+ * Sets [Builder.topLogprobs] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.topLogprobs] with a well-typed [Long] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun topLogprobs(topLogprobs: JsonField) = apply { this.topLogprobs = topLogprobs }
+
+ /**
+ * An alternative to sampling with temperature, called nucleus sampling, where the model
+ * considers the results of the tokens with top_p probability mass. So 0.1 means only the
+ * tokens comprising the top 10% probability mass are considered.
+ *
+ * We generally recommend altering this or `temperature` but not both.
+ */
+ fun topP(topP: Double?) = topP(JsonField.ofNullable(topP))
+
+ /**
+ * Alias for [Builder.topP].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun topP(topP: Double) = topP(topP as Double?)
+
+ /** Alias for calling [Builder.topP] with `topP.orElse(null)`. */
+ fun topP(topP: Optional) = topP(topP.getOrNull())
+
+ /**
+ * Sets [Builder.topP] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.topP] with a well-typed [Double] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported value.
+ */
+ fun topP(topP: JsonField) = apply { this.topP = topP }
+
+ /**
+ * The truncation strategy to use for the model response.
+ * - `auto`: If the input to this Response exceeds the model's context window size, the
+ * model will truncate the response to fit the context window by dropping items from the
+ * beginning of the conversation.
+ * - `disabled` (default): If the input size will exceed the context window size for a
+ * model, the request will fail with a 400 error.
+ */
+ fun truncation(truncation: Truncation?) = truncation(JsonField.ofNullable(truncation))
+
+ /** Alias for calling [Builder.truncation] with `truncation.orElse(null)`. */
+ fun truncation(truncation: Optional) = truncation(truncation.getOrNull())
+
+ /**
+ * Sets [Builder.truncation] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.truncation] with a well-typed [Truncation] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun truncation(truncation: JsonField) = apply { this.truncation = truncation }
+
+ /**
+ * This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
+ * `prompt_cache_key` instead to maintain caching optimizations. A stable identifier for
+ * your end-users. Used to boost cache hit rates by better bucketing similar requests and to
+ * help OpenAI detect and prevent abuse.
+ * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
+ */
+ @Deprecated("deprecated") fun user(user: String) = user(JsonField.of(user))
+
+ /**
+ * Sets [Builder.user] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.user] with a well-typed [String] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported value.
+ */
+ @Deprecated("deprecated") fun user(user: JsonField) = apply { this.user = user }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [ResponsesClientEvent].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ */
+ fun build(): ResponsesClientEvent =
+ ResponsesClientEvent(
+ type,
+ background,
+ (contextManagement ?: JsonMissing.of()).map { it.toImmutable() },
+ conversation,
+ (include ?: JsonMissing.of()).map { it.toImmutable() },
+ input,
+ instructions,
+ maxOutputTokens,
+ maxToolCalls,
+ metadata,
+ model,
+ parallelToolCalls,
+ previousResponseId,
+ prompt,
+ promptCacheKey,
+ promptCacheRetention,
+ reasoning,
+ safetyIdentifier,
+ serviceTier,
+ store,
+ stream,
+ streamOptions,
+ temperature,
+ text,
+ toolChoice,
+ (tools ?: JsonMissing.of()).map { it.toImmutable() },
+ topLogprobs,
+ topP,
+ truncation,
+ user,
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): ResponsesClientEvent = apply {
+ if (validated) {
+ return@apply
+ }
+
+ _type().let {
+ if (it != JsonValue.from("response.create")) {
+ throw OpenAIInvalidDataException("'type' is invalid, received $it")
+ }
+ }
+ background()
+ contextManagement().ifPresent { it.forEach { it.validate() } }
+ conversation().ifPresent { it.validate() }
+ include().ifPresent { it.forEach { it.validate() } }
+ input().ifPresent { it.validate() }
+ instructions()
+ maxOutputTokens()
+ maxToolCalls()
+ metadata().ifPresent { it.validate() }
+ model().ifPresent { it.validate() }
+ parallelToolCalls()
+ previousResponseId()
+ prompt().ifPresent { it.validate() }
+ promptCacheKey()
+ promptCacheRetention().ifPresent { it.validate() }
+ reasoning().ifPresent { it.validate() }
+ safetyIdentifier()
+ serviceTier().ifPresent { it.validate() }
+ store()
+ stream()
+ streamOptions().ifPresent { it.validate() }
+ temperature()
+ text().ifPresent { it.validate() }
+ toolChoice().ifPresent { it.validate() }
+ tools().ifPresent { it.forEach { it.validate() } }
+ topLogprobs()
+ topP()
+ truncation().ifPresent { it.validate() }
+ user()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ type.let { if (it == JsonValue.from("response.create")) 1 else 0 } +
+ (if (background.asKnown().isPresent) 1 else 0) +
+ (contextManagement.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (conversation.asKnown().getOrNull()?.validity() ?: 0) +
+ (include.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (input.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (instructions.asKnown().isPresent) 1 else 0) +
+ (if (maxOutputTokens.asKnown().isPresent) 1 else 0) +
+ (if (maxToolCalls.asKnown().isPresent) 1 else 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0) +
+ (model.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (parallelToolCalls.asKnown().isPresent) 1 else 0) +
+ (if (previousResponseId.asKnown().isPresent) 1 else 0) +
+ (prompt.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (promptCacheKey.asKnown().isPresent) 1 else 0) +
+ (promptCacheRetention.asKnown().getOrNull()?.validity() ?: 0) +
+ (reasoning.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (safetyIdentifier.asKnown().isPresent) 1 else 0) +
+ (serviceTier.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (store.asKnown().isPresent) 1 else 0) +
+ (if (stream.asKnown().isPresent) 1 else 0) +
+ (streamOptions.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (temperature.asKnown().isPresent) 1 else 0) +
+ (text.asKnown().getOrNull()?.validity() ?: 0) +
+ (toolChoice.asKnown().getOrNull()?.validity() ?: 0) +
+ (tools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (if (topLogprobs.asKnown().isPresent) 1 else 0) +
+ (if (topP.asKnown().isPresent) 1 else 0) +
+ (truncation.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (user.asKnown().isPresent) 1 else 0)
+
+ class ContextManagement
+ @JsonCreator(mode = JsonCreator.Mode.DISABLED)
+ private constructor(
+ private val type: JsonField,
+ private val compactThreshold: JsonField,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(),
+ @JsonProperty("compact_threshold")
+ @ExcludeMissing
+ compactThreshold: JsonField = JsonMissing.of(),
+ ) : this(type, compactThreshold, mutableMapOf())
+
+ /**
+ * The context management entry type. Currently only 'compaction' is supported.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun type(): String = type.getRequired("type")
+
+ /**
+ * Token threshold at which compaction should be triggered for this entry.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun compactThreshold(): Optional = compactThreshold.getOptional("compact_threshold")
+
+ /**
+ * Returns the raw JSON value of [type].
+ *
+ * Unlike [type], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type
+
+ /**
+ * Returns the raw JSON value of [compactThreshold].
+ *
+ * Unlike [compactThreshold], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("compact_threshold")
+ @ExcludeMissing
+ fun _compactThreshold(): JsonField = compactThreshold
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [ContextManagement].
+ *
+ * The following fields are required:
+ * ```java
+ * .type()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [ContextManagement]. */
+ class Builder internal constructor() {
+
+ private var type: JsonField? = null
+ private var compactThreshold: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(contextManagement: ContextManagement) = apply {
+ type = contextManagement.type
+ compactThreshold = contextManagement.compactThreshold
+ additionalProperties = contextManagement.additionalProperties.toMutableMap()
+ }
+
+ /** The context management entry type. Currently only 'compaction' is supported. */
+ fun type(type: String) = type(JsonField.of(type))
+
+ /**
+ * Sets [Builder.type] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.type] with a well-typed [String] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun type(type: JsonField) = apply { this.type = type }
+
+ /** Token threshold at which compaction should be triggered for this entry. */
+ fun compactThreshold(compactThreshold: Long?) =
+ compactThreshold(JsonField.ofNullable(compactThreshold))
+
+ /**
+ * Alias for [Builder.compactThreshold].
+ *
+ * This unboxed primitive overload exists for backwards compatibility.
+ */
+ fun compactThreshold(compactThreshold: Long) =
+ compactThreshold(compactThreshold as Long?)
+
+ /**
+ * Alias for calling [Builder.compactThreshold] with `compactThreshold.orElse(null)`.
+ */
+ fun compactThreshold(compactThreshold: Optional) =
+ compactThreshold(compactThreshold.getOrNull())
+
+ /**
+ * Sets [Builder.compactThreshold] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.compactThreshold] with a well-typed [Long] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun compactThreshold(compactThreshold: JsonField) = apply {
+ this.compactThreshold = compactThreshold
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [ContextManagement].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .type()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): ContextManagement =
+ ContextManagement(
+ checkRequired("type", type),
+ compactThreshold,
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): ContextManagement = apply {
+ if (validated) {
+ return@apply
+ }
+
+ type()
+ compactThreshold()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (type.asKnown().isPresent) 1 else 0) +
+ (if (compactThreshold.asKnown().isPresent) 1 else 0)
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return other is ContextManagement &&
+ type == other.type &&
+ compactThreshold == other.compactThreshold &&
+ additionalProperties == other.additionalProperties
+ }
+
+ private val hashCode: Int by lazy {
+ Objects.hash(type, compactThreshold, additionalProperties)
+ }
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "ContextManagement{type=$type, compactThreshold=$compactThreshold, additionalProperties=$additionalProperties}"
+ }
+
+ /**
+ * The conversation that this response belongs to. Items from this conversation are prepended to
+ * `input_items` for this response request. Input items and output items from this response are
+ * automatically added to this conversation after this response completes.
+ */
+ @JsonDeserialize(using = Conversation.Deserializer::class)
+ @JsonSerialize(using = Conversation.Serializer::class)
+ class Conversation
+ private constructor(
+ private val id: String? = null,
+ private val responseConversationParam: ResponseConversationParam? = null,
+ private val _json: JsonValue? = null,
+ ) {
+
+ /** The unique ID of the conversation. */
+ fun id(): Optional = Optional.ofNullable(id)
+
+ /** The conversation that this response belongs to. */
+ fun responseConversationParam(): Optional =
+ Optional.ofNullable(responseConversationParam)
+
+ fun isId(): Boolean = id != null
+
+ fun isResponseConversationParam(): Boolean = responseConversationParam != null
+
+ /** The unique ID of the conversation. */
+ fun asId(): String = id.getOrThrow("id")
+
+ /** The conversation that this response belongs to. */
+ fun asResponseConversationParam(): ResponseConversationParam =
+ responseConversationParam.getOrThrow("responseConversationParam")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T =
+ when {
+ id != null -> visitor.visitId(id)
+ responseConversationParam != null ->
+ visitor.visitResponseConversationParam(responseConversationParam)
+ else -> visitor.unknown(_json)
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): Conversation = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitId(id: String) {}
+
+ override fun visitResponseConversationParam(
+ responseConversationParam: ResponseConversationParam
+ ) {
+ responseConversationParam.validate()
+ }
+ }
+ )
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitId(id: String) = 1
+
+ override fun visitResponseConversationParam(
+ responseConversationParam: ResponseConversationParam
+ ) = responseConversationParam.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return other is Conversation &&
+ id == other.id &&
+ responseConversationParam == other.responseConversationParam
+ }
+
+ override fun hashCode(): Int = Objects.hash(id, responseConversationParam)
+
+ override fun toString(): String =
+ when {
+ id != null -> "Conversation{id=$id}"
+ responseConversationParam != null ->
+ "Conversation{responseConversationParam=$responseConversationParam}"
+ _json != null -> "Conversation{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid Conversation")
+ }
+
+ companion object {
+
+ /** The unique ID of the conversation. */
+ @JvmStatic fun ofId(id: String) = Conversation(id = id)
+
+ /** The conversation that this response belongs to. */
+ @JvmStatic
+ fun ofResponseConversationParam(responseConversationParam: ResponseConversationParam) =
+ Conversation(responseConversationParam = responseConversationParam)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [Conversation] to a value of type
+ * [T].
+ */
+ interface Visitor {
+
+ /** The unique ID of the conversation. */
+ fun visitId(id: String): T
+
+ /** The conversation that this response belongs to. */
+ fun visitResponseConversationParam(
+ responseConversationParam: ResponseConversationParam
+ ): T
+
+ /**
+ * Maps an unknown variant of [Conversation] to a value of type [T].
+ *
+ * An instance of [Conversation] can contain an unknown variant if it was deserialized
+ * from data that doesn't match any known variant. For example, if the SDK is on an
+ * older version than the API, then the API may respond with new variants that the SDK
+ * is unaware of.
+ *
+ * @throws OpenAIInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OpenAIInvalidDataException("Unknown Conversation: $json")
+ }
+ }
+
+ internal class Deserializer : BaseDeserializer(Conversation::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): Conversation {
+ val json = JsonValue.fromJsonNode(node)
+
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Conversation(responseConversationParam = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Conversation(id = it, _json = json)
+ },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely incompatible with
+ // all the possible variants (e.g. deserializing from boolean).
+ 0 -> Conversation(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then use the first
+ // completely valid match, or simply the first match if none are completely
+ // valid.
+ else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
+ }
+ }
+ }
+
+ internal class Serializer : BaseSerializer(Conversation::class) {
+
+ override fun serialize(
+ value: Conversation,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.id != null -> generator.writeObject(value.id)
+ value.responseConversationParam != null ->
+ generator.writeObject(value.responseConversationParam)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid Conversation")
+ }
+ }
+ }
+ }
+
+ /**
+ * Text, image, or file inputs to the model, used to generate a response.
+ *
+ * Learn more:
+ * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
+ * - [Image inputs](https://platform.openai.com/docs/guides/images)
+ * - [File inputs](https://platform.openai.com/docs/guides/pdf-files)
+ * - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)
+ * - [Function calling](https://platform.openai.com/docs/guides/function-calling)
+ */
+ @JsonDeserialize(using = Input.Deserializer::class)
+ @JsonSerialize(using = Input.Serializer::class)
+ class Input
+ private constructor(
+ private val text: String? = null,
+ private val response: List? = null,
+ private val _json: JsonValue? = null,
+ ) {
+
+ /** A text input to the model, equivalent to a text input with the `user` role. */
+ fun text(): Optional = Optional.ofNullable(text)
+
+ /** A list of one or many input items to the model, containing different content types. */
+ fun response(): Optional> = Optional.ofNullable(response)
+
+ fun isText(): Boolean = text != null
+
+ fun isResponse(): Boolean = response != null
+
+ /** A text input to the model, equivalent to a text input with the `user` role. */
+ fun asText(): String = text.getOrThrow("text")
+
+ /** A list of one or many input items to the model, containing different content types. */
+ fun asResponse(): List = response.getOrThrow("response")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T =
+ when {
+ text != null -> visitor.visitText(text)
+ response != null -> visitor.visitResponse(response)
+ else -> visitor.unknown(_json)
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): Input = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitText(text: String) {}
+
+ override fun visitResponse(response: List) {
+ response.forEach { it.validate() }
+ }
+ }
+ )
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitText(text: String) = 1
+
+ override fun visitResponse(response: List) =
+ response.sumOf { it.validity().toInt() }
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return other is Input && text == other.text && response == other.response
+ }
+
+ override fun hashCode(): Int = Objects.hash(text, response)
+
+ override fun toString(): String =
+ when {
+ text != null -> "Input{text=$text}"
+ response != null -> "Input{response=$response}"
+ _json != null -> "Input{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid Input")
+ }
+
+ companion object {
+
+ /** A text input to the model, equivalent to a text input with the `user` role. */
+ @JvmStatic fun ofText(text: String) = Input(text = text)
+
+ /**
+ * A list of one or many input items to the model, containing different content types.
+ */
+ @JvmStatic
+ fun ofResponse(response: List) =
+ Input(response = response.toImmutable())
+ }
+
+ /** An interface that defines how to map each variant of [Input] to a value of type [T]. */
+ interface Visitor {
+
+ /** A text input to the model, equivalent to a text input with the `user` role. */
+ fun visitText(text: String): T
+
+ /**
+ * A list of one or many input items to the model, containing different content types.
+ */
+ fun visitResponse(response: List