Repository navigation
Expand file tree
/
Copy pathResponse.kt
More file actions
8754 lines (7536 loc) · 361 KB
/
Copy pathResponse.kt
File metadata and controls
8754 lines (7536 loc) · 361 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
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.JsonNull
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 Response
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
private constructor(
private val id: JsonField<String>,
private val accessPrograms: JsonField<AccessPrograms>,
private val createdAt: JsonField<Double>,
private val error: JsonField<ResponseError>,
private val incompleteDetails: JsonField<IncompleteDetails>,
private val instructions: JsonField<Instructions>,
private val metadata: JsonField<Metadata>,
private val model: JsonField<ResponsesModel>,
private val object_: JsonValue,
private val output: JsonField<List<ResponseOutputItem>>,
private val parallelToolCalls: JsonField<Boolean>,
private val temperature: JsonField<Double>,
private val toolChoice: JsonField<ToolChoice>,
private val tools: JsonField<List<Tool>>,
private val topP: JsonField<Double>,
private val background: JsonField<Boolean>,
private val completedAt: JsonField<Double>,
private val conversation: JsonField<Conversation>,
private val maxOutputTokens: JsonField<Long>,
private val maxToolCalls: JsonField<Long>,
private val moderation: JsonField<Moderation>,
private val previousResponseId: JsonField<String>,
private val prompt: JsonField<ResponsePrompt>,
private val promptCacheDiagnostics: JsonField<PromptCacheDiagnostics>,
private val promptCacheKey: JsonField<String>,
private val promptCacheOptions: JsonField<PromptCacheOptions>,
private val promptCacheRetention: JsonField<PromptCacheRetention>,
private val reasoning: JsonField<Reasoning>,
private val safetyIdentifier: JsonField<String>,
private val serviceTier: JsonField<ServiceTier>,
private val status: JsonField<ResponseStatus>,
private val text: JsonField<ResponseTextConfig>,
private val topLogprobs: JsonField<Long>,
private val truncation: JsonField<Truncation>,
private val usage: JsonField<ResponseUsage>,
private val user: JsonField<String>,
private val additionalProperties: MutableMap<String, JsonValue>,
) {
@JsonCreator
private constructor(
@JsonProperty("id") @ExcludeMissing id: JsonField<String> = JsonMissing.of(),
@JsonProperty("access_programs")
@ExcludeMissing
accessPrograms: JsonField<AccessPrograms> = JsonMissing.of(),
@JsonProperty("created_at") @ExcludeMissing createdAt: JsonField<Double> = JsonMissing.of(),
@JsonProperty("error") @ExcludeMissing error: JsonField<ResponseError> = JsonMissing.of(),
@JsonProperty("incomplete_details")
@ExcludeMissing
incompleteDetails: JsonField<IncompleteDetails> = JsonMissing.of(),
@JsonProperty("instructions")
@ExcludeMissing
instructions: JsonField<Instructions> = JsonMissing.of(),
@JsonProperty("metadata") @ExcludeMissing metadata: JsonField<Metadata> = JsonMissing.of(),
@JsonProperty("model") @ExcludeMissing model: JsonField<ResponsesModel> = JsonMissing.of(),
@JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(),
@JsonProperty("output")
@ExcludeMissing
output: JsonField<List<ResponseOutputItem>> = JsonMissing.of(),
@JsonProperty("parallel_tool_calls")
@ExcludeMissing
parallelToolCalls: JsonField<Boolean> = JsonMissing.of(),
@JsonProperty("temperature")
@ExcludeMissing
temperature: JsonField<Double> = JsonMissing.of(),
@JsonProperty("tool_choice")
@ExcludeMissing
toolChoice: JsonField<ToolChoice> = JsonMissing.of(),
@JsonProperty("tools") @ExcludeMissing tools: JsonField<List<Tool>> = JsonMissing.of(),
@JsonProperty("top_p") @ExcludeMissing topP: JsonField<Double> = JsonMissing.of(),
@JsonProperty("background")
@ExcludeMissing
background: JsonField<Boolean> = JsonMissing.of(),
@JsonProperty("completed_at")
@ExcludeMissing
completedAt: JsonField<Double> = JsonMissing.of(),
@JsonProperty("conversation")
@ExcludeMissing
conversation: JsonField<Conversation> = JsonMissing.of(),
@JsonProperty("max_output_tokens")
@ExcludeMissing
maxOutputTokens: JsonField<Long> = JsonMissing.of(),
@JsonProperty("max_tool_calls")
@ExcludeMissing
maxToolCalls: JsonField<Long> = JsonMissing.of(),
@JsonProperty("moderation")
@ExcludeMissing
moderation: JsonField<Moderation> = JsonMissing.of(),
@JsonProperty("previous_response_id")
@ExcludeMissing
previousResponseId: JsonField<String> = JsonMissing.of(),
@JsonProperty("prompt")
@ExcludeMissing
prompt: JsonField<ResponsePrompt> = JsonMissing.of(),
@JsonProperty("prompt_cache_diagnostics")
@ExcludeMissing
promptCacheDiagnostics: JsonField<PromptCacheDiagnostics> = JsonMissing.of(),
@JsonProperty("prompt_cache_key")
@ExcludeMissing
promptCacheKey: JsonField<String> = JsonMissing.of(),
@JsonProperty("prompt_cache_options")
@ExcludeMissing
promptCacheOptions: JsonField<PromptCacheOptions> = JsonMissing.of(),
@JsonProperty("prompt_cache_retention")
@ExcludeMissing
promptCacheRetention: JsonField<PromptCacheRetention> = JsonMissing.of(),
@JsonProperty("reasoning")
@ExcludeMissing
reasoning: JsonField<Reasoning> = JsonMissing.of(),
@JsonProperty("safety_identifier")
@ExcludeMissing
safetyIdentifier: JsonField<String> = JsonMissing.of(),
@JsonProperty("service_tier")
@ExcludeMissing
serviceTier: JsonField<ServiceTier> = JsonMissing.of(),
@JsonProperty("status")
@ExcludeMissing
status: JsonField<ResponseStatus> = JsonMissing.of(),
@JsonProperty("text")
@ExcludeMissing
text: JsonField<ResponseTextConfig> = JsonMissing.of(),
@JsonProperty("top_logprobs")
@ExcludeMissing
topLogprobs: JsonField<Long> = JsonMissing.of(),
@JsonProperty("truncation")
@ExcludeMissing
truncation: JsonField<Truncation> = JsonMissing.of(),
@JsonProperty("usage") @ExcludeMissing usage: JsonField<ResponseUsage> = JsonMissing.of(),
@JsonProperty("user") @ExcludeMissing user: JsonField<String> = JsonMissing.of(),
) : this(
id,
accessPrograms,
createdAt,
error,
incompleteDetails,
instructions,
metadata,
model,
object_,
output,
parallelToolCalls,
temperature,
toolChoice,
tools,
topP,
background,
completedAt,
conversation,
maxOutputTokens,
maxToolCalls,
moderation,
previousResponseId,
prompt,
promptCacheDiagnostics,
promptCacheKey,
promptCacheOptions,
promptCacheRetention,
reasoning,
safetyIdentifier,
serviceTier,
status,
text,
topLogprobs,
truncation,
usage,
user,
mutableMapOf(),
)
/**
* Unique identifier for this Response.
*
* @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 id(): String = id.getRequired("id")
/**
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun accessPrograms(): Optional<AccessPrograms> = accessPrograms.getOptional("access_programs")
/**
* Unix timestamp (in seconds) of when this Response was created.
*
* @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 createdAt(): Double = createdAt.getRequired("created_at")
/**
* An error object returned when the model fails to generate a Response.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun error(): Optional<ResponseError> = error.getOptional("error")
/**
* Details about why the response is incomplete.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun incompleteDetails(): Optional<IncompleteDetails> =
incompleteDetails.getOptional("incomplete_details")
/**
* 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> = instructions.getOptional("instructions")
/**
* 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> = metadata.getOptional("metadata")
/**
* Model ID used to generate the response, like `gpt-6-astra`. OpenAI offers a wide range of
* models with different capabilities, performance characteristics, and price points. Refer to
* the [model guide](https://developers.openai.com/api/docs/models) to browse and compare
* available models.
*
* @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 model(): ResponsesModel = model.getRequired("model")
/**
* The object type of this resource - always set to `response`.
*
* Expected to always return the following:
* ```java
* JsonValue.from("response")
* ```
*
* However, this method can be useful for debugging and logging (e.g. if the server responded
* with an unexpected value).
*/
@JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_
/**
* An array of content items generated by the model.
* - The length and order of items in the `output` array is dependent on the model's response.
* - Rather than accessing the first item in the `output` array and assuming it's an `assistant`
* message with the content generated by the model, you might consider using the `output_text`
* property where supported in SDKs.
*
* @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 output(): List<ResponseOutputItem> = output.getRequired("output")
/**
* Whether to allow the model to run tool calls in parallel.
*
* @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 parallelToolCalls(): Boolean = parallelToolCalls.getRequired("parallel_tool_calls")
/**
* 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<Double> = temperature.getOptional("temperature")
/**
* 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 or is
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
*/
fun toolChoice(): ToolChoice = toolChoice.getRequired("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://developers.openai.com/api/docs/guides/tools-web-search) or
* [file search](https://developers.openai.com/api/docs/guides/tools-file-search). Learn more
* about [built-in tools](https://developers.openai.com/api/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://developers.openai.com/api/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://developers.openai.com/api/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 or is
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
*/
fun tools(): List<Tool> = tools.getRequired("tools")
/**
* 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<Double> = topP.getOptional("top_p")
/**
* Whether to run the model response in the background.
* [Learn more](https://developers.openai.com/api/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<Boolean> = background.getOptional("background")
/**
* Unix timestamp (in seconds) of when this Response was completed. Only present when the status
* is `completed`.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun completedAt(): Optional<Double> = completedAt.getOptional("completed_at")
/**
* The conversation that this response belonged to. Input items and output items from this
* response were automatically added to this conversation.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun conversation(): Optional<Conversation> = conversation.getOptional("conversation")
/**
* An upper bound for the number of tokens that can be generated for a response, including
* visible output tokens and
* [reasoning tokens](https://developers.openai.com/api/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<Long> = 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<Long> = maxToolCalls.getOptional("max_tool_calls")
/**
* Moderation results for the response input and output, if moderated completions were
* requested.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun moderation(): Optional<Moderation> = moderation.getOptional("moderation")
/**
* The unique ID of the previous response to the model. Use this to create multi-turn
* conversations. Learn more about
* [conversation state](https://developers.openai.com/api/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<String> =
previousResponseId.getOptional("previous_response_id")
/**
* Reference to a prompt template and its variables.
* [Learn more](https://developers.openai.com/api/docs/guides/text?api-mode=responses#version-prompts-in-code).
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun prompt(): Optional<ResponsePrompt> = prompt.getOptional("prompt")
/**
* Prompt cache diagnostics requested for this response.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun promptCacheDiagnostics(): Optional<PromptCacheDiagnostics> =
promptCacheDiagnostics.getOptional("prompt_cache_diagnostics")
/**
* Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.
* Replaces the `user` field.
* [Learn more](https://developers.openai.com/api/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<String> = promptCacheKey.getOptional("prompt_cache_key")
/**
* The prompt-caching options that were applied to the response. Supported for `gpt-5.6` and
* later models.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun promptCacheOptions(): Optional<PromptCacheOptions> =
promptCacheOptions.getOptional("prompt_cache_options")
/**
* Deprecated. Use `prompt_cache_options.ttl` instead.
*
* 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://developers.openai.com/api/docs/guides/prompt-caching#prompt-cache-retention).
* This field expresses a maximum retention policy, while `prompt_cache_options.ttl` expresses a
* minimum cache lifetime. The two fields are independent and do not interact. For `gpt-5.5`,
* `gpt-5.5-pro`, and future models, only `24h` is supported.
*
* For older models that support both `in_memory` and `24h`, the default depends on your
* organization's data retention policy:
* - Organizations without ZDR enabled default to `24h`.
* - Organizations with ZDR enabled default to `in_memory` when `prompt_cache_retention` is not
* specified.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
@Deprecated("deprecated")
fun promptCacheRetention(): Optional<PromptCacheRetention> =
promptCacheRetention.getOptional("prompt_cache_retention")
/**
* Configuration options for
* [reasoning models](https://developers.openai.com/api/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> = 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://developers.openai.com/api/docs/guides/safety-best-practices#implement-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<String> = 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://developers.openai.com/api/docs/guides/flex-processing)', then the
* request will be processed with the Flex Processing service tier.
* - To opt-in to [Fast mode](https://developers.openai.com/api/docs/guides/fast-mode) at the
* request level, include the `service_tier=fast` or `service_tier=priority` parameter for
* Responses or Chat Completions. The response will show `service_tier=priority` regardless of
* if you specify `service_tier=fast` or `priority` in your request.
* - If set to 'ultrafast', then the request will be processed with the access-controlled
* Ultrafast Processing service tier. This tier is currently available for `gpt-5.6-sol`; a
* response served through it will show `service_tier=ultrafast`.
* - 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> = serviceTier.getOptional("service_tier")
/**
* The status of the response generation. One of `completed`, `failed`, `in_progress`,
* `cancelled`, `queued`, or `incomplete`.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun status(): Optional<ResponseStatus> = status.getOptional("status")
/**
* Configuration options for a text response from the model. Can be plain text or structured
* JSON data. Learn more:
* - [Text inputs and outputs](https://developers.openai.com/api/docs/guides/text)
* - [Structured Outputs](https://developers.openai.com/api/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<ResponseTextConfig> = text.getOptional("text")
/**
* An integer between 0 and 20 specifying the maximum number of most likely tokens to return at
* each token position, each with an associated log probability. In some cases, the number of
* returned tokens may be fewer than requested.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun topLogprobs(): Optional<Long> = topLogprobs.getOptional("top_logprobs")
/**
* 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> = truncation.getOptional("truncation")
/**
* Represents token usage details including input tokens, output tokens, a breakdown of output
* tokens, and the total tokens used.
*
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
* server responded with an unexpected value).
*/
fun usage(): Optional<ResponseUsage> = usage.getOptional("usage")
/**
* 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://developers.openai.com/api/docs/guides/safety-best-practices#implement-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<String> = user.getOptional("user")
/**
* Returns the raw JSON value of [id].
*
* Unlike [id], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("id") @ExcludeMissing fun _id(): JsonField<String> = id
/**
* Returns the raw JSON value of [accessPrograms].
*
* Unlike [accessPrograms], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("access_programs")
@ExcludeMissing
fun _accessPrograms(): JsonField<AccessPrograms> = accessPrograms
/**
* Returns the raw JSON value of [createdAt].
*
* Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField<Double> = createdAt
/**
* Returns the raw JSON value of [error].
*
* Unlike [error], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("error") @ExcludeMissing fun _error(): JsonField<ResponseError> = error
/**
* Returns the raw JSON value of [incompleteDetails].
*
* Unlike [incompleteDetails], this method doesn't throw if the JSON field has an unexpected
* type.
*/
@JsonProperty("incomplete_details")
@ExcludeMissing
fun _incompleteDetails(): JsonField<IncompleteDetails> = incompleteDetails
/**
* 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> = instructions
/**
* 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> = 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<ResponsesModel> = model
/**
* Returns the raw JSON value of [output].
*
* Unlike [output], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("output")
@ExcludeMissing
fun _output(): JsonField<List<ResponseOutputItem>> = output
/**
* 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<Boolean> = parallelToolCalls
/**
* 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<Double> = temperature
/**
* 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> = 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<List<Tool>> = tools
/**
* 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<Double> = topP
/**
* 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<Boolean> = background
/**
* Returns the raw JSON value of [completedAt].
*
* Unlike [completedAt], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("completed_at")
@ExcludeMissing
fun _completedAt(): JsonField<Double> = completedAt
/**
* 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> = conversation
/**
* 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<Long> = 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<Long> = maxToolCalls
/**
* Returns the raw JSON value of [moderation].
*
* Unlike [moderation], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("moderation")
@ExcludeMissing
fun _moderation(): JsonField<Moderation> = moderation
/**
* 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<String> = 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<ResponsePrompt> = prompt
/**
* Returns the raw JSON value of [promptCacheDiagnostics].
*
* Unlike [promptCacheDiagnostics], this method doesn't throw if the JSON field has an
* unexpected type.
*/
@JsonProperty("prompt_cache_diagnostics")
@ExcludeMissing
fun _promptCacheDiagnostics(): JsonField<PromptCacheDiagnostics> = promptCacheDiagnostics
/**
* 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<String> = promptCacheKey
/**
* Returns the raw JSON value of [promptCacheOptions].
*
* Unlike [promptCacheOptions], this method doesn't throw if the JSON field has an unexpected
* type.
*/
@JsonProperty("prompt_cache_options")
@ExcludeMissing
fun _promptCacheOptions(): JsonField<PromptCacheOptions> = promptCacheOptions
/**
* Returns the raw JSON value of [promptCacheRetention].
*
* Unlike [promptCacheRetention], this method doesn't throw if the JSON field has an unexpected
* type.
*/
@Deprecated("deprecated")
@JsonProperty("prompt_cache_retention")
@ExcludeMissing
fun _promptCacheRetention(): JsonField<PromptCacheRetention> = 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> = 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<String> = 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> = serviceTier
/**
* Returns the raw JSON value of [status].
*
* Unlike [status], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("status") @ExcludeMissing fun _status(): JsonField<ResponseStatus> = status
/**
* 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<ResponseTextConfig> = text
/**
* 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<Long> = topLogprobs
/**
* 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> = truncation
/**
* Returns the raw JSON value of [usage].
*
* Unlike [usage], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("usage") @ExcludeMissing fun _usage(): JsonField<ResponseUsage> = usage
/**
* 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<String> = user
@JsonAnySetter
private fun putAdditionalProperty(key: String, value: JsonValue) {
additionalProperties.put(key, value)
}
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map<String, JsonValue> =
Collections.unmodifiableMap(additionalProperties)
fun toBuilder() = Builder().from(this)
companion object {
/**
* Returns a mutable builder for constructing an instance of [Response].
*
* The following fields are required:
* ```java
* .id()
* .createdAt()
* .error()
* .incompleteDetails()
* .instructions()
* .metadata()
* .model()
* .output()
* .parallelToolCalls()
* .temperature()
* .toolChoice()
* .tools()
* .topP()
* ```
*/
@JvmStatic fun builder() = Builder()
}
/** A builder for [Response]. */
class Builder internal constructor() {
private var id: JsonField<String>? = null
private var accessPrograms: JsonField<AccessPrograms>? = JsonNull.of()
private var createdAt: JsonField<Double>? = null
private var error: JsonField<ResponseError>? = null
private var incompleteDetails: JsonField<IncompleteDetails>? = null
private var instructions: JsonField<Instructions>? = null
private var metadata: JsonField<Metadata>? = null
private var model: JsonField<ResponsesModel>? = null
private var object_: JsonValue = JsonValue.from("response")
private var output: JsonField<MutableList<ResponseOutputItem>>? = null
private var parallelToolCalls: JsonField<Boolean>? = null
private var temperature: JsonField<Double>? = null
private var toolChoice: JsonField<ToolChoice>? = null
private var tools: JsonField<MutableList<Tool>>? = null
private var topP: JsonField<Double>? = null
private var background: JsonField<Boolean> = JsonMissing.of()
private var completedAt: JsonField<Double> = JsonMissing.of()
private var conversation: JsonField<Conversation> = JsonMissing.of()
private var maxOutputTokens: JsonField<Long> = JsonMissing.of()
private var maxToolCalls: JsonField<Long> = JsonMissing.of()
private var moderation: JsonField<Moderation> = JsonMissing.of()
private var previousResponseId: JsonField<String> = JsonMissing.of()
private var prompt: JsonField<ResponsePrompt> = JsonMissing.of()
private var promptCacheDiagnostics: JsonField<PromptCacheDiagnostics> = JsonMissing.of()
private var promptCacheKey: JsonField<String> = JsonMissing.of()
private var promptCacheOptions: JsonField<PromptCacheOptions> = JsonMissing.of()
private var promptCacheRetention: JsonField<PromptCacheRetention> = JsonMissing.of()
private var reasoning: JsonField<Reasoning> = JsonMissing.of()
private var safetyIdentifier: JsonField<String> = JsonMissing.of()
private var serviceTier: JsonField<ServiceTier> = JsonMissing.of()
private var status: JsonField<ResponseStatus> = JsonMissing.of()
private var text: JsonField<ResponseTextConfig> = JsonMissing.of()
private var topLogprobs: JsonField<Long> = JsonMissing.of()
private var truncation: JsonField<Truncation> = JsonMissing.of()
private var usage: JsonField<ResponseUsage> = JsonMissing.of()
private var user: JsonField<String> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
@JvmSynthetic
internal fun from(response: Response) = apply {
id = response.id
accessPrograms = response.accessPrograms
createdAt = response.createdAt
error = response.error
incompleteDetails = response.incompleteDetails
instructions = response.instructions
metadata = response.metadata
model = response.model
object_ = response.object_
output = response.output.map { it.toMutableList() }
parallelToolCalls = response.parallelToolCalls
temperature = response.temperature
toolChoice = response.toolChoice
tools = response.tools.map { it.toMutableList() }
topP = response.topP
background = response.background