How to stream and wait for the final response object with the new genai SDK

gemini-2.5-pro, although being a superb coder, cannot help with it, since the new ts/js sdk is after its training cutoff.

this is possible with openai/anthropic api:

and even possible with gemini model via openai compatible api.

even possible with the generativeai api?

(with full respect and the recognition that the new api is still being built in public)

Hi @Sirui_Lu ,

Apologies for the late response. If you want to generate a non-streaming response, you can use the ai.models.generateContent API. You can check the following example. Thank you!

yes but somehow that is less stable and results in more time out than the streaming version…
now I aggregated the response object myself, which is messy.
both openai/anthropic has this waitForFinalResponseObject.

1 Like