@@ -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
];
@@ -1745,6 +1758,11 @@ async function fetchOpenAI(
1745
1758
}
1746
1759
}
1747
1760
1761
+ console.log("fetching openai:", {
1762
+ fullURL: fullURL.toString(),
1763
+ headers,
1764
+ body: JSON.stringify(bodyData),
1765
+ });
1748
1766
const proxyResponse = await fetch(
1749
1767
fullURL.toString(),
1750
1768
method === "POST"
@@ -2113,7 +2131,10 @@ async function fetchAnthropicChatCompletions({
2113
2131
2114
2132
let isStructuredOutput = false;
2115
2133
const parsed = responseFormatSchema.safeParse(oaiParams.response_format);
2116
- if (parsed.success && parsed.data.type === "json_schema") {
2134
+ if (
2135
+ parsed.success &&
2136
+ (parsed.data.type === "json_schema" || parsed.data.type === "json_object")
2137
+ ) {
2117
2138
isStructuredOutput = true;
2118
2139
if (params.tools || params.tool_choice) {
2119
2140
throw new ProxyBadRequestError(
@@ -2124,7 +2145,15 @@ async function fetchAnthropicChatCompletions({
2124
2145
{
2125
2146
name: "json",
2126
2147
description: "Output the result in JSON format",
2127
- input_schema: parsed.data.json_schema.schema,
2148
+ input_schema:
2149
+ parsed.data.type === "json_schema"
2150
+ ? parsed.data.json_schema.schema
2151
+ : {
2152
+ type: "object",
2153
+ description: "A flexible schema that accepts any JSON object.",
2154
+ properties: {},
2155
+ additionalProperties: true,
2156
+ },
2128
2157
},
2129
2158
];
2130
2159
params.tool_choice = { type: "tool", name: "json" };
@@ -2155,6 +2184,15 @@ async function fetchAnthropicChatCompletions({
2155
2184
delete params.model;
2156
2185
}
2157
2186
2187
+ console.log("fetching anthropic:", {
2188
+ fullURL: fullURL.toString(),
2189
+ headers,
2190
+ body: JSON.stringify({
2191
+ messages,
2192
+ system,
2193
+ ...params,
2194
+ }),
2195
+ });
2158
2196
const proxyResponse = await fetch(fullURL.toString(), {
2159
2197
method: "POST",
2160
2198
headers,
0 commit comments