Immutable solution version
client.files.upload() fails with KeyError: 'file' when uploading .jsonl (Batch API)
Complete solution
Covers this Google Gemini problem: client.files.upload() fails with KeyError: 'file' when uploading .jsonl (Batch API). [dget, orhansonmeztr, alexerhardt, prathapbelli (reporters)]: The docs example passed mime_type='jsonl', which the backend rejects with 'Unsupported MIME type: application/jsonl'.
The problem
Issue googleapis/python-genai#1590 (closed, 28 comments): Hi team, thank you for the great Gemini SDK! I just wanted to report that the JSONL upload example from the official Batch API docs currently fails with a KeyError: 'file' when using client.files.upload(). When following the official Gemini Batch API documentation, uploading a .jsonl file via client.files.upload() fails with KeyError: 'file'. This happens when using the example code from the docs verbatim. The API call succeeds (HTTP 200), but the SDK throws a KeyError because the JSON response
What fixed it
[dget, orhansonmeztr, alexerhardt, prathapbelli (reporters)]: The docs example passed mimetype='jsonl', which the backend rejects with 'Unsupported MIME type: application/jsonl'. The SDK does not check the upload response for errors, so that backend 400 surfaces as a confusing KeyError: 'file' instead of the real error. Workaround confirmed by several reporters on the thread: upload the .jsonl file with mimetype='application/json'. If you hit a bare KeyError after files.upload, print the raw response first, the real API error is hiding behind it.
Evidence
In gh:googleapis/python-genai#1590 (Google Gemini), the issue reported was: Issue googleapis/python-genai#1590 (closed, 28 comments): Hi team, thank you for the great Gemini SDK! I just wanted to report that the JSONL upload example from the official Batch API docs currently fails with a KeyError: 'file' when using client.files.upload(). When following the official Gemini Batch API documentation, uploading a .jsonl file via client.files.upload() fails with KeyError: 'file'. This happens when using the example code from the docs verbatim. The API call succeeds (HTTP 200), but the SDK throws a KeyError because the JSON response The verified resolution from the thread: [dget, orhansonmeztr, alexerhardt, prathapbelli (reporters)]: The docs example passed mimetype='jsonl', which the backend rejects with 'Unsupported MIME type: application/jsonl'. The SDK does not check the upload response for errors, so that backend 400 surfaces as a confusing KeyError: 'file' instead of the real error. Workaround confirmed by several reporters on the thread: upload the .jsonl file with mimetype='application/json'. If you hit a bare KeyError after files.upload, print the raw response first, the real API error is hiding behind it. Source: mount the host path https at container path //github.com/googleapis/python-genai/issues/1590
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_YNG_7Nbysg_52WEb-2Y0tA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">client.files.upload() fails with KeyError: 'file' when uploading .jsonl (Batch API) <span>— Vectle</span></a>