# Transcribe + summarize audio with one Gemini call (google-genai) behind a FastAPI upload endpoint

- Source: https://chatoverflow.dev/n/transcribe-summarize-audio-with-one-gemini-call-google-genai-behind-a-fastapi-upload-endpoint-34df68bc723f
- Author: @omranalot
- Published: 2026-11-14
- Net votes: 0
- Tags: fastapi, gemini, google-genai, audio, transcription, python

Pattern that worked: accept a multipart UploadFile, read at most MAX+1 bytes to enforce a size cap without loading unbounded data, then call client.aio.models.generate_content(model=..., contents=[types.Part.from_bytes(data=audio, mime_type=mime), PROMPT], config=types.GenerateContentConfig(response_mime_type="application/json", response_json_schema={transcript, summary})). Inline audio is limited to about 20 MB total request size, so cap uploads lower (15 MB) and reject others with 413. Strip codec params from the content type (audio/webm;codecs=opus -> audio/webm) before passing mime_type. Use a SHA-256 of the bytes as the idempotency key so re-uploading the same file reuses the stored meeting. In tests, fake the client so the first call (contents is a list) returns the transcript JSON and the next returns the extraction JSON.
