@@ -1713,6 +1713,7 @@ async function fetchOpenAI(
1713
1713
delete bodyData . response_format ;
1714
1714
break ;
1715
1715
case "json_schema" :
1716
+ case "json_object" :
1716
1717
if (
1717
1718
bodyData . model . startsWith ( "gpt" ) ||
1718
1719
bodyData . model . startsWith ( "o1" ) ||
@@ -1734,8 +1735,20 @@ async function fetchOpenAI(
1734
1735
function : {
1735
1736
name : "json" ,
1736
1737
description : "Output the result in JSON format" ,
1737
- parameters : responseFormatParsed . data . json_schema . schema ,
1738
- strict : responseFormatParsed . data . json_schema . strict ,
1738
+ parameters :
1739
+ responseFormatParsed . data . type === "json_schema"
1740
+ ? responseFormatParsed . data . json_schema . schema
1741
+ : {
1742
+ type : "object" ,
1743
+ description :
1744
+ "A flexible schema that accepts any JSON object." ,
1745
+ properties : { } ,
1746
+ additionalProperties : true ,
1747
+ } ,
1748
+ strict :
1749
+ responseFormatParsed . data . type === "json_schema"
1750
+ ? responseFormatParsed . data . json_schema . strict
1751
+ : false ,
1739
1752
} ,
1740
1753
} ,
1741
1754
] ;
@@ -2113,7 +2126,10 @@ async function fetchAnthropicChatCompletions({
2113
2126
2114
2127
let isStructuredOutput = false ;
2115
2128
const parsed = responseFormatSchema . safeParse ( oaiParams . response_format ) ;
2116
- if ( parsed . success && parsed . data . type === "json_schema" ) {
2129
+ if (
2130
+ parsed . success &&
2131
+ ( parsed . data . type === "json_schema" || parsed . data . type === "json_object" )
2132
+ ) {
2117
2133
isStructuredOutput = true ;
2118
2134
if ( params . tools || params . tool_choice ) {
2119
2135
throw new ProxyBadRequestError (
@@ -2124,7 +2140,15 @@ async function fetchAnthropicChatCompletions({
2124
2140
{
2125
2141
name : "json" ,
2126
2142
description : "Output the result in JSON format" ,
2127
- input_schema : parsed . data . json_schema . schema ,
2143
+ input_schema :
2144
+ parsed . data . type === "json_schema"
2145
+ ? parsed . data . json_schema . schema
2146
+ : {
2147
+ type : "object" ,
2148
+ description : "A flexible schema that accepts any JSON object." ,
2149
+ properties : { } ,
2150
+ additionalProperties : true ,
2151
+ } ,
2128
2152
} ,
2129
2153
] ;
2130
2154
params . tool_choice = { type : "tool" , name : "json" } ;
0 commit comments