"Upload has already been terminated" error with markdown files after Gemini File Search API update

I’m experiencing an issue with the File Search API after the recent update (4 days ago). https://ai.google.dev/api/file-search/file-search-stores, Uploading markdown (.md) files fails with:

400 Bad Request: {‘message’: ‘Upload has already been terminated.’, ‘status’: ‘Bad Request’}

Additionally, I see 503 ServiceUnavailable errors in AI Studio.

What works:

  • PDF file uploads work fine
  • The uploadToFileSearchStore method executes

What fails:

  • Markdown file uploads consistently fail
  • Operation tracking throws “already terminated” error

Root cause I discovered:
The API documentation shows a new endpoint structure:

  • Old: fileSearchStores/{store}/operations/{id}
  • New: fileSearchStores/{store}/upload/operations/{id} (for upload operations)

However, the Python SDK (google-genai) doesn’t have client.file_search_stores.upload.operations yet - it only has client.operations.get() which uses the old endpoint.

Questions:

  1. When will the Python SDK be updated to support the new /upload/operations/ endpoint?
  2. Is there a workaround besides making direct REST API calls?
  3. Why do PDFs work but markdown files don’t with the same upload method?

Environment:

  • Python SDK: google-genai (latest)
  • Files: Markdown (.md) with explicit mime_type: ‘text/markdown’

Any guidance would be appreciated!

1 Like

Hi @0xneobyte
Welcome to the AI Forum!!!

Thank you for bringing this to our attention.
Could you please share the full payload details along with a sample of the code that you are using? We would like to reproduce the issue.

Environment:

  • Python SDK: google-genai (latest version from pip)
  • Python: 3.11+
  • OS: macOS arm

Full Code Sample:

from google import genai
import time

client = genai.Client(api_key="YOUR_API_KEY")

# This works fine for PDFs
pdf_operation = client.file_search_stores.upload_to_file_search_store(
    file="/path/to/document.pdf",
    file_search_store_name="fileSearchStores/YOUR_STORE_ID",
    config={
        'display_name': 'Test PDF',
        'custom_metadata': [
            {"key": "subject", "string_value": "mathematics"}
        ],
        'mime_type': 'application/pdf'
    }
)

works fine for PDF uploads

while not pdf_operation.done:
    time.sleep(2)
    pdf_operation = client.operations.get(pdf_operation)

print("PDF uploaded successfully")

This fails for markdown files

md_operation = client.file_search_stores.upload_to_file_search_store(
    file="/path/to/document.md",
    file_search_store_name="fileSearchStores/YOUR_STORE_ID",
    config={
        'display_name': 'Test Markdown',
        'custom_metadata': [
            {"key": "subject", "string_value": "mathematics"}
        ],
        'mime_type': 'text/markdown'
    }
)

ERROR

# Wait for markdown operation - FAILS HERE
while not md_operation.done:
    time.sleep(2)
    md_operation = client.operations.get(md_operation)  # Throws error

print("Markdown uploaded successfully")

Error Output:
400 Bad Request: {'message': 'Upload has already been terminated.', 'status': 'Bad Request'}

Key Observations:

  1. PDFs work perfectly with the exact same code pattern
  2. Only markdown files consistently fail
  3. The new API documentation (updated 4 days ago) shows upload operations should use: fileSearchStores/{store}/upload/operations/{id}
  4. However, the SDK’s client.operations.get() uses the old endpoint: fileSearchStores/{store}/operations/{id}
  5. I verified the SDK doesn’t have client.file_search_stores.upload.operations namespace yet
  6. this code worked well before (like 2-3 weeks back

WAIT, NOW IT WORKS!!!

i think there was something wrong in the backend and now its fixed! thanks.

I've been facing the same issue since its release. It happens with some PDF files, not all.

File: some PDFs, not all

operation = self.client.file_search_stores.upload_to_file_search_store(
    file=file_obj,
    file_search_store_name=f"fileSearchStores/{settings.gemini_file_store_id}",
    config=upload_config
)

The process stalls for a while then returns:

400 Bad Request: {'message': 'Upload has already been terminated.', 'status': 'Bad Request'}

are you fix this prob?
facing !