Skip to content

Commit 472d723

Browse files
steebchenclaude
andauthored
fix(gateway): support JSON schema for Responses API (#1417)
Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent e307f96 commit 472d723

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/models/src/prepare-request-body.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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

packages/models/src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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

226237
export interface AnthropicSystemContent {

0 commit comments

Comments
 (0)