@@ -35,6 +35,9 @@ use crate::v1::message::{
3535} ;
3636use crate :: v1:: model:: { ModelResponse , ModelsResponse } ;
3737use crate :: v1:: moderation:: { CreateModerationRequest , CreateModerationResponse } ;
38+ use crate :: v1:: responses:: {
39+ CountTokensRequest , CountTokensResponse , CreateResponseRequest , ListResponses , ResponseObject ,
40+ } ;
3841use crate :: v1:: run:: {
3942 CreateRunRequest , CreateThreadAndRunRequest , ListRun , ListRunStep , ModifyRunRequest , RunObject ,
4043 RunStepObject ,
@@ -819,6 +822,70 @@ impl OpenAIClient {
819822 self . get ( & url) . await
820823 }
821824
825+ // Responses API
826+ pub async fn create_response (
827+ & mut self ,
828+ req : CreateResponseRequest ,
829+ ) -> Result < ResponseObject , APIError > {
830+ self . post ( "responses" , & req) . await
831+ }
832+
833+ pub async fn retrieve_response (
834+ & mut self ,
835+ response_id : String ,
836+ ) -> Result < ResponseObject , APIError > {
837+ self . get ( & format ! ( "responses/{response_id}" ) ) . await
838+ }
839+
840+ pub async fn delete_response (
841+ & mut self ,
842+ response_id : String ,
843+ ) -> Result < common:: DeletionStatus , APIError > {
844+ self . delete ( & format ! ( "responses/{response_id}" ) ) . await
845+ }
846+
847+ pub async fn cancel_response (
848+ & mut self ,
849+ response_id : String ,
850+ ) -> Result < ResponseObject , APIError > {
851+ self . post (
852+ & format ! ( "responses/{response_id}/cancel" ) ,
853+ & common:: EmptyRequestBody { } ,
854+ )
855+ . await
856+ }
857+
858+ pub async fn list_response_input_items (
859+ & mut self ,
860+ response_id : String ,
861+ after : Option < String > ,
862+ limit : Option < i64 > ,
863+ order : Option < String > ,
864+ ) -> Result < ListResponses , APIError > {
865+ let mut url = format ! ( "responses/{}/input_items" , response_id) ;
866+ let mut params = vec ! [ ] ;
867+ if let Some ( after) = after {
868+ params. push ( format ! ( "after={}" , after) ) ;
869+ }
870+ if let Some ( limit) = limit {
871+ params. push ( format ! ( "limit={}" , limit) ) ;
872+ }
873+ if let Some ( order) = order {
874+ params. push ( format ! ( "order={}" , order) ) ;
875+ }
876+ if !params. is_empty ( ) {
877+ url = format ! ( "{}?{}" , url, params. join( "&" ) ) ;
878+ }
879+ self . get ( & url) . await
880+ }
881+
882+ pub async fn count_response_input_tokens (
883+ & mut self ,
884+ req : CountTokensRequest ,
885+ ) -> Result < CountTokensResponse , APIError > {
886+ self . post ( "responses/input_tokens" , & req) . await
887+ }
888+
822889 pub async fn list_models ( & mut self ) -> Result < ModelsResponse , APIError > {
823890 self . get ( "models" ) . await
824891 }
0 commit comments