Gemini API returned truncated JSON response for a paid request

Environment:

  • OS: Windows
  • Python: 3.11.14
  • SDK: google-genai==2.0.0
  • Also installed: google-generativeai==0.8.6
  • Model: gemini-3.5-flash
  • API key: configured via GEMINI_API_KEY, not included for security
  • Request timeout env: GEMINI_REQUEST_TIMEOUT=300
  • File upload timeout env: GEMINI_FILE_UPLOAD_TIMEOUT=120
  • Log level: INFO

Project / Billing:

  • Google Cloud Project ID: gen-lang-client-07019713..
  • Billing Account ID: 01A953-5ABBB7-BDDC..

API usage:

  • Endpoint: models.generate_content
  • SDK path: google-genai async client
  • File input: Files API upload, then generate_content with uploaded prompt/labels/data files
  • response_mime_type: application/json
  • max_output_tokens: 65536
  • Non-streaming call: response.text is read after the SDK returns

Local command:
C:; cd ‘C:\source_code\AuditMind’; & ‘c:\Tools\miniconda3\envs\trading_env\python.exe’ ‘c:\Users\HeisenbergYang.antigravity-ide\extensions\ms-python.debugpy-2026.6.0-win32-x64\bundled\libs\debugpy\launcher’
‘63022’ ‘–’ ‘C:\source_code\AuditMind/main.py’ ‘–journal’ ‘C:\source_code\AuditMind/ds/03序时账.csv’ ‘–balance’ ‘C:\source_code\AuditMind/ds/03余额表.csv’ ‘–output’ ‘C:\source_code\AuditMind/output’

Observed files:

  • Request: C:\source_code\AuditMind\output\03\debug\stage2_chunk_0003_request.json
  • Raw response: C:\source_code\AuditMind\output\03\debug\stage2_chunk_0003_response.json
  • Parsed recovery: C:\source_code\AuditMind\output\03\debug\stage2_chunk_0003_parsed.json

Timestamps:

  • Request file written: 2026-06-19 09:17:45 Asia/Shanghai
  • Response file written: 2026-06-19 09:26:01 Asia/Shanghai

Input:

  • stage2_chunk_0003_request.json size: 111,283 bytes
  • Input rows: 500

Actual response:

  • stage2_chunk_0003_response.json size: 5,984 bytes
  • Response is not valid JSON
  • It is truncated in the middle of a row:
    [2072, null, null,
  • json.loads / ConvertFrom-Json fails
  • Only 163 out of 500 expected rows could be recovered

Expected behavior:
The API should either:

  1. return complete valid JSON because response_mime_type=application/json was requested, or
  2. fail the request with an explicit error / finish_reason such as MAX_TOKENS, SAFETY, RECITATION, backend error, etc.

Business impact:
This is a paid Gemini API request. The request consumed billable API usage but returned an unusable partial JSON response. Please investigate and advise whether the charge can be credited/refunded.

Attachments:

  • Sanitized stage2_chunk_0003_request.json
  • Raw stage2_chunk_0003_response.json
  • stage2_chunk_0003_parsed.json showing only 163 recovered rows
  • Console logs if available, especially finish_reason and token usage