When using function calling, Gemini API sends a text response along with function call

When using function calling, Most of the time gemini API send the function call only. But sometimes, it sends text first and then call the function. I don’t want this behaviour. When invoking a function, I want the Gemini to send me function_name and parameters only.

How can I achieve this behaviour?

NOTE: I’m using StreamingResponse. Hence, I just can’t simply filter out text response. Current implementation of my app assumes that if we receive a text then it’s a response from Gemini and not a function call.

1 Like

You can request it via system instructions, but to be 100% safe why not just filter it out from the response? It’s simple enough to get only the function call from the parts array.

I’m using StreamingResponse. Please view the updated description of original problem.

Tried using system instruction but didn’t get the results as expected.

I’ve been having this same problem, but I’m not using streaming. I’m just calling models.generateContent

I’m using the node GoogleGenAI from @google/genai.
Every model that I’ve tried so far has this problem.

This used to work last week. The past few days it’s gotten worse, so much so that today it’s failed to call a function 100% of the time.

I’m about to jump ship from Google. :frowning:

Agreed, and once I also jump ship there WILL be NO coming back after I spend the next week transferring to another provider. Get your together Google.

Same issue here, I’m not using StreamingResponse but models.generateContent.

Used to work no problem, then text only is returned. Fine we can handle it somehow, but it’s so unpredictable and not sure how it will change in the next iteration of the model.

Reported it here: Very frustrating experience with Gemini 2.5 function calling performance
Like/comment so it gets visibility and maybe someone will take care of this.

Difficult to trust this API despite being on paper good.

Hi @Naman_Vyas, I have tried with a sample code of using the function calling with both steaming and generate_content method the model was first calling the function all the time i have tried. Could you please let us know if you are still facing the issue, if yes please provide the standalone code you are using. Thank You.