Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix: translate input_file↔file content parts

AveryanAlex0b85d8a9bcbe
diff --git a/open-sse/translator/request/openai-responses.ts b/open-sse/translator/request/openai-responses.ts
index a9fcca0331..715126044b 100644
--- a/open-sse/translator/request/openai-responses.ts
+++ b/open-sse/translator/request/openai-responses.ts
@@ -122,6 +122,14 @@ export function openaiResponsesToOpenAIRequest(
}
return imgResult;
}
+ if (contentItem.type === "input_file") {
+ const fileObj: JsonRecord = {};
+ if (contentItem.file_data !== undefined) fileObj.file_data = contentItem.file_data;
+ if (contentItem.file_id !== undefined) fileObj.file_id = contentItem.file_id;
+ if (contentItem.file_url !== undefined) fileObj.file_url = contentItem.file_url;
+ if (contentItem.filename !== undefined) fileObj.filename = contentItem.filename;
+ return { type: "file", file: fileObj };
+ }
return contentValue;
})
: item.content;
@@ -308,6 +316,15 @@ export function openaiToOpenAIResponsesRequest(
}
return imgResult;
}
+ if (contentItem.type === "file") {
+ const file = toRecord(contentItem.file);
+ const fileResult: JsonRecord = { type: "input_file" };
+ if (file.file_data !== undefined) fileResult.file_data = file.file_data;
+ if (file.file_id !== undefined) fileResult.file_id = file.file_id;
+ if (file.file_url !== undefined) fileResult.file_url = file.file_url;
+ if (file.filename !== undefined) fileResult.filename = file.filename;
+ return fileResult;
+ }
return contentValue;
})
: [{ type: "input_text", text: "" }];
diff --git a/tests/unit/responses-translation-fixes.test.mjs b/tests/unit/responses-translation-fixes.test.mjs
index fd0355d5db..7c41feb9df 100644
--- a/tests/unit/responses-translation-fixes.test.mjs
+++ b/tests/unit/responses-translation-fixes.test.mjs
@@ -117,3 +117,44 @@ test("Chat→Responses: image_url without detail omits detail", () => {
assert.ok(imgPart);
assert.equal(imgPart.detail, undefined);
});
+
+test("Responses→Chat: input_file converted to file content part", () => {
+ const body = {
+ model: "gpt-4",
+ input: [
+ {
+ type: "message",
+ role: "user",
+ content: [
+ { type: "input_file", file_id: "file-abc", filename: "data.csv" },
+ ],
+ },
+ ],
+ };
+ const result = openaiResponsesToOpenAIRequest(null, body, null, null);
+ const userMsg = result.messages.find((m) => m.role === "user");
+ const filePart = userMsg.content.find((c) => c.type === "file");
+ assert.ok(filePart, "should have file content part");
+ assert.equal(filePart.file.file_id, "file-abc");
+ assert.equal(filePart.file.filename, "data.csv");
+});
+
+test("Chat→Responses: file content part converted to input_file", () => {
+ const body = {
+ model: "gpt-4",
+ messages: [
+ {
+ role: "user",
+ content: [
+ { type: "file", file: { file_id: "file-abc", filename: "data.csv" } },
+ ],
+ },
+ ],
+ };
+ const result = openaiToOpenAIResponsesRequest("gpt-4", body, true, null);
+ const userItem = result.input.find((i) => i.type === "message" && i.role === "user");
+ const filePart = userItem.content.find((c) => c.type === "input_file");
+ assert.ok(filePart, "should have input_file content part");
+ assert.equal(filePart.file_id, "file-abc");
+ assert.equal(filePart.filename, "data.csv");
+});