@@ -35,6 +35,7 @@ import sttp.openai.requests.images.variations.ImageVariationsConfig
35
35
import sttp .openai .requests .models .ModelsResponseData .{DeletedModelData , ModelData , ModelsResponse }
36
36
import sttp .openai .requests .moderations .ModerationsRequestBody .ModerationsBody
37
37
import sttp .openai .requests .moderations .ModerationsResponseData .ModerationData
38
+ import sttp .openai .requests .responses ._
38
39
import sttp .openai .requests .threads .QueryParameters
39
40
import sttp .openai .requests .threads .ThreadsRequestBody .CreateThreadBody
40
41
import sttp .openai .requests .threads .ThreadsResponseData .{DeleteThreadResponse , ThreadData }
@@ -405,6 +406,105 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
405
406
.delete(openAIUris.chatCompletion(completionId))
406
407
.response(asJson_parseErrors[DeleteChatCompletionResponse ])
407
408
409
+ /** Creates a model response.
410
+ *
411
+ * Provide text or image inputs to generate text or JSON outputs. Have the model call your own custom code or use built-in tools like web
412
+ * search or file search to use your own data as input for the model's response.
413
+ *
414
+ * [[https://platform.openai.com/docs/api-reference/responses/create ]]
415
+ *
416
+ * @param requestBody
417
+ * Model response request body.
418
+ *
419
+ * @return
420
+ * Returns a Response object.
421
+ */
422
+ def createModelResponse (requestBody : ResponsesRequestBody ): Request [Either [OpenAIException , ResponsesResponseBody ]] =
423
+ openAIAuthRequest
424
+ .post(openAIUris.Responses )
425
+ .body(asJson(requestBody))
426
+ .response(asJson_parseErrors[ResponsesResponseBody ])
427
+
428
+ /** Retrieves a model response with the given ID.
429
+ *
430
+ * [[https://platform.openai.com/docs/api-reference/responses/get ]]
431
+ *
432
+ * @param responseId
433
+ * The ID of the response to retrieve.
434
+ *
435
+ * @return
436
+ * The Response object matching the specified ID.
437
+ */
438
+ def getModelResponse (
439
+ responseId : String ,
440
+ queryParameters : GetResponseQueryParameters
441
+ ): Request [Either [OpenAIException , ResponsesResponseBody ]] = {
442
+ val uri = openAIUris
443
+ .response(responseId)
444
+ .withParams(queryParameters.toMap)
445
+
446
+ openAIAuthRequest
447
+ .get(uri)
448
+ .response(asJson_parseErrors[ResponsesResponseBody ])
449
+ }
450
+
451
+ /** Deletes a model response with the given ID.
452
+ *
453
+ * [[https://platform.openai.com/docs/api-reference/responses/delete ]]
454
+ *
455
+ * @param responseId
456
+ * The ID of the chat completion to delete.
457
+ *
458
+ * @return
459
+ * A deletion confirmation object.
460
+ */
461
+ def deleteModelResponse (responseId : String ): Request [Either [OpenAIException , DeleteModelResponseResponse ]] =
462
+ openAIAuthRequest
463
+ .delete(openAIUris.response(responseId))
464
+ .response(asJson_parseErrors[DeleteModelResponseResponse ])
465
+
466
+ /** Cancels a model response with the given ID.
467
+ *
468
+ * Only responses created with the background parameter set to true can be cancelled
469
+ *
470
+ * [[https://platform.openai.com/docs/api-reference/responses/cancel ]]
471
+ *
472
+ * @param responseId
473
+ * The ID of the Upload.
474
+ *
475
+ * @return
476
+ * The Upload object with status cancelled.
477
+ */
478
+ def cancelResponse (responseId : String ): Request [Either [OpenAIException , ResponsesResponseBody ]] =
479
+ openAIAuthRequest
480
+ .post(openAIUris.cancelResponse(responseId))
481
+ .response(asJson_parseErrors[ResponsesResponseBody ])
482
+
483
+ /** Returns a list of input items for a given response.
484
+ *
485
+ * [[https://platform.openai.com/docs/api-reference/responses/input-items ]]
486
+ *
487
+ * @param responseId
488
+ * The ID of the response to retrieve input items for.
489
+ * @param queryParameters
490
+ * Query parameters for pagination and filtering.
491
+ *
492
+ * @return
493
+ * A list of input items for the response.
494
+ */
495
+ def listResponsesInputItems (
496
+ responseId : String ,
497
+ queryParameters : ListInputItemsQueryParameters = ListInputItemsQueryParameters .empty
498
+ ): Request [Either [OpenAIException , InputItemsListResponseBody ]] = {
499
+ val uri = openAIUris
500
+ .responseInputItems(responseId)
501
+ .withParams(queryParameters.toMap)
502
+
503
+ openAIAuthRequest
504
+ .get(uri)
505
+ .response(asJson_parseErrors[InputItemsListResponseBody ])
506
+ }
507
+
408
508
/** Returns a list of files that belong to the user's organization.
409
509
*
410
510
* [[https://platform.openai.com/docs/api-reference/files ]]
@@ -1533,6 +1633,7 @@ private class OpenAIUris(val baseUri: Uri) {
1533
1633
val Translations : Uri = audioBase.addPath(" translations" )
1534
1634
val Speech : Uri = audioBase.addPath(" speech" )
1535
1635
val VariationsImage : Uri = imageBase.addPath(" variations" )
1636
+ val Responses : Uri = uri " $baseUri/responses "
1536
1637
1537
1638
val Assistants : Uri = uri " $baseUri/assistants "
1538
1639
val Threads : Uri = uri " $baseUri/threads "
@@ -1563,6 +1664,10 @@ private class OpenAIUris(val baseUri: Uri) {
1563
1664
1564
1665
def assistant (assistantId : String ): Uri = Assistants .addPath(assistantId)
1565
1666
1667
+ def response (responseId : String ): Uri = Responses .addPath(responseId)
1668
+ def cancelResponse (responseId : String ): Uri = response(responseId).addPath(" cancel" )
1669
+ def responseInputItems (responseId : String ): Uri = response(responseId).addPath(" input_items" )
1670
+
1566
1671
def thread (threadId : String ): Uri = Threads .addPath(threadId)
1567
1672
def threadMessages (threadId : String ): Uri = Threads .addPath(threadId).addPath(" messages" )
1568
1673
def threadMessage (threadId : String , messageId : String ): Uri = Threads .addPath(threadId).addPath(" messages" ).addPath(messageId)
0 commit comments