Extracts the output text of a Gemini API response.
Thinking parts and function calls are skipped, so only the text generated for the caller is returned. A response
without output text is rejected as an empty generation. The error names the finish reason, so a generation the model
withheld, for instance for RECITATION, can be told apart from a malformed payload.
Parameters
response: GenerateContentResponse
The response of a generateContent request
Returns string
The trimmed output text of response, joining the text of multiple parts with blank lines
Throws
Error If response carries no output text, naming the finish reason of the response
Extracts the output text of a Gemini API response.
Thinking parts and function calls are skipped, so only the text generated for the caller is returned. A response without output text is rejected as an empty generation. The error names the finish reason, so a generation the model withheld, for instance for
RECITATION, can be told apart from a malformed payload.