File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -369,6 +369,30 @@ export async function prepareRequestBody(
369369 responsesBody . max_output_tokens = max_tokens ;
370370 }
371371
372+ // Handle response_format for Responses API - transform to text.format
373+ if ( response_format ) {
374+ if (
375+ response_format . type === "json_schema" &&
376+ response_format . json_schema
377+ ) {
378+ responsesBody . text = {
379+ format : {
380+ type : "json_schema" ,
381+ name : response_format . json_schema . name ,
382+ schema : response_format . json_schema . schema as Record <
383+ string ,
384+ unknown
385+ > ,
386+ strict : response_format . json_schema . strict ,
387+ } ,
388+ } ;
389+ } else if ( response_format . type === "json_object" ) {
390+ responsesBody . text = {
391+ format : { type : "json_object" } ,
392+ } ;
393+ }
394+ }
395+
372396 return responsesBody ;
373397 } else {
374398 // Use regular chat completions format
Original file line number Diff line number Diff line change @@ -221,6 +221,17 @@ export interface OpenAIResponsesRequestBody {
221221 stream ?: boolean ;
222222 temperature ?: number ;
223223 max_output_tokens ?: number ;
224+ text ?: {
225+ format :
226+ | { type : "text" }
227+ | { type : "json_object" }
228+ | {
229+ type : "json_schema" ;
230+ name : string ;
231+ schema : Record < string , unknown > ;
232+ strict ?: boolean ;
233+ } ;
234+ } ;
224235}
225236
226237export interface AnthropicSystemContent {
You can’t perform that action at this time.
0 commit comments