I am consistently getting internal server error when trying to send a http request to gemini services.
I have tried the exact same api requests with the same prompts/settings etc. with a pdf file and it worked. I also did not hard code the mimetype so that is also correct.
I am also using the same file upload method with the pdfs and text files, but for some reason only with text files I am getting this error.
I have also tried making the input much shorter, the file much smaller but nothing seems to work.
It happens with 2.5 flash and 2.5 pro the others I have not tried yet.
I am sending the requests from n8n, but it even worked seamlessly with text files before and now there seems to be an issue with the text file processing on the server.
Would really appreciate some help.
Here is the n8n code for the test scenario where I could reproduce the error:
{
“nodes”: [
{
“parameters”: {
“formTitle”: “test”,
“formDescription”: “test”,
“formFields”: {
“values”: [
{
“fieldLabel”: “text file”,
“fieldType”: “file”,
“multipleFiles”: false,
“acceptFileTypes”: “text/plain”
},
{
“fieldLabel”: “prompt”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.formTrigger”,
“typeVersion”: 2.2,
“position”: [
-140,
-20
],
“id”: “921665b7-33ce-4d11-b547-0903d914df10”,
“name”: “On form submission”,
“webhookId”: “45c4d306-6c23-4818-9611-9e4237efa9b1”
},
{
“parameters”: {
“method”: “POST”,
“url”: “https://generativelanguage.googleapis.com/upload/v1beta/files?key=”,
“sendBody”: true,
“contentType”: “binaryData”,
“inputDataFieldName”: “text_file”,
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
120,
-20
],
“id”: “328d5347-80a9-4e0d-925d-fd598e16b5da”,
“name”: “Instruction Creator from PDF Social Post”,
“retryOnFail”: true,
“maxTries”: 5,
“waitBetweenTries”: 5000
},
{
“parameters”: {
“jsCode”: “// — Vereinfachter Code nur zum Testen der fileUri-Verarbeitung —\n\n// 1. Hole nur die absolut notwendigen Inputs: die URI und den Mime-Type der hochgeladenen Datei.\n// Stelle sicher, dass die Node-Namen (‘Instruction Creator…’ und ‘Supabase12’) korrekt sind.\nconst uploadedFileUri = $(‘Instruction Creator from PDF Social Post’).first().json.file.uri;\n\n// 2. Erstelle eine sehr einfache, direkte Anweisung.\nconst simplePrompt = "Please summarize the content of the attached document in a few bullet points.";\n\n// 3. Baue den minimalen Request-Body zusammen.\n// Wir senden nur die einfache Anweisung und den Verweis auf die Datei.\nconst geminiRequestBody = {\n contents: [{\n role: "user",\n parts: [\n { text: simplePrompt },\n { fileData: { mimeType: "text/plain", fileUri: uploadedFileUri } }\n ]\n }],\n generationConfig: {\n temperature: 0.5 // Eine niedrigere Temperatur ist für einfache Zusammenfassungen oft besser.\n }\n};\n\n// 4. Gib den fertigen Request-Body für den nächsten HTTP-Request-Node aus.\nreturn { requestbody: JSON.stringify(geminiRequestBody) };”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
380,
-20
],
“id”: “dc9dee38-3d2e-428b-8cb7-d4e3e6701a52”,
“name”: “No Image Route”
},
{
“parameters”: {
“method”: “POST”,
“url”: “https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-pro:generateContent?key=”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “Content-Type”,
“value”: “application/json”
}
]
},
“sendBody”: true,
“specifyBody”: “json”,
“jsonBody”: “={{$json.requestbody}}”,
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
620,
-20
],
“id”: “39effab2-4058-46b5-80a7-d220f7c9caad”,
“name”: “Instruction Creator from PDF Social Post2”,
“retryOnFail”: true,
“maxTries”: 5
}
],
“connections”: {
“On form submission”: {
“main”: [
[
{
“node”: “Instruction Creator from PDF Social Post”,
“type”: “main”,
“index”: 0
}
]
]
},
“Instruction Creator from PDF Social Post”: {
“main”: [
[
{
“node”: “No Image Route”,
“type”: “main”,
“index”: 0
}
]
]
},
“No Image Route”: {
“main”: [
[
{
“node”: “Instruction Creator from PDF Social Post2”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“instanceId”: “eed8d1c552ba8bd8f7cc26587c697aac1c948343fb2cebafbf50797b134258df”
}
}