googleapis / googleapis/python-genai
Critical Bug: Gemini Batch API generates Output File IDs that exceed the Files API 40-character limit (400 INVALID_ARGUMENT)
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
(Issue report generated by me with Gemini AI assistance)
#### Component
Gemini API (Batch Service / Files Service)
#### Severity
High (Prevents retrieval of batch job results)
#### Environment details
- SDK: google-genai Python SDK (Version 1.52.0)
- Model: gemini-2.5-flash
- API Endpoint: v1beta
Test case run in Google Colab
#### Steps to reproduce
1. Create a valid JSONL batch input file.
2. Upload the file using client.files.upload().
3. Submit a batch job using client.batches.create(model=..., src=...).
4. Wait for the job to reach JOB_STATE_SUCCEEDED.
5. Attempt to download the automatically generated output file (batch_job.dest.file_name) using the Files API.
#### Minimal Reproducible Code (Python)
```
import os
import time
import json
import requests
import mimetypes
from google import genai
from google.colab import userdata
# 1. Register mimetype to ensure SDK handles .jsonl upload correctly
mimetypes.add_type("application/jsonl", ".jsonl")
# 2. Setup Client
API_KEY = userdata.get('GEMINI_API_KEY') # Or your preferred key method
client = genai.Client(api_key=API_KEY)
MODEL_NAME = "gemini-2.5-flash"
INPUT_FILE = "repro_input.jsonl"
# 3. Create valid input file
request_data = {
"request": {
"contents": [{"role": "user", "parts": [{"text": "Hello world"}]}]
}
}
with open(INPUT_FILE, 'w') as f:
f.write(json.dumps(request_data) + "\n")
# 4. Upload and Submit
input_file_obj = client.files.upload(file=INPUT_FILE)
print(f"Input uploaded: {input_file_obj.name}")
batch_job = client.batches.create(model=MODEL_NAME, src=input_file_obj.name)
print(f"Job submitted: {batch_job.name}")
# 5. Wait for Completion
while batch_job.state.name not in ["JOB_STATE_SUCCEEDED", "JOB_STATE_FAILED"]:
time.sleep(10)
batch_job = client.batches.get(name=batch_job.name)
print(f"Status: {batch_job.state.name}")
# 6. Attempt Download (The Bug)
output_name = batch_job.dest.file_name
print(f"Generated Output Name: {output_name}")
file_id = output_name.split('/')[-1]
print(f"ID Length: {len(file_id)} chars")
url = f"https://generativelanguage.googleapis.com/v1beta/{output_name}?key={API_KEY}&alt=media"
response = requests.get(url)
print(f"Response: {response.status_code}")
print(f"Error: {response.text}")
```
#### Actual Result (Logs)
The job succeeds, but the download request fails validation because the server-generated ID is too long.
```
Status: JOB_STATE_SUCCEEDED
Generated Output Name: files/batch-3q7fs93gsd9ck3bycd0kelcrb85oa75xarhu
ID Length: 42 chars
Response: 400
Error: {
"error": {
"code": 400,
"message": "* GetFileRequest.name: File ID (name excluding 'files/') cannot be more than 40 characters.",
"status": "INVALID_ARGUMENT"
}
}
```
#### Analysis
**Generated ID:** batch-3q7fs93gsd9ck3bycd0kelcrb85oa75xarhu (42 characters)
**Files API Limit:** 40 characters.
**Conclusion:** The Batch service is generating IDs that the Files service considers illegal. Users cannot retrieve batch results until the Batch service shortens its IDs or the Files service increases its character limit.
Contributor guide
Assessment
This issue has not been assessed yet.