Function Calling - Stream Model

I am using Gemini’s1.5 streaming interface with Function Calling, the request is as follows:

{
    "contents" : [
        {
            "role" : "user",
            "parts" : [
                {
                    "text" : "What is the weather like in London"
                }
            ]
        }
    ],
    "tools" : [
        {
            "function_declarations" : [
                {
                    "name" : "get_current_weather",
                    "description" : "Get the current weather in a given location",
                    "parameters" : {
                        "type" : "object",
                        "properties" : {
                            "location" : {
                                "type" : "string",
                                "description" : "The city and state, e.g. San Francisco, CA"
                            },
                            "unit" : {
                                "type" : "string",
                                "enum" : [
                                    "celsius",
                                    "fahrenheit"
                                ]
                            }
                        },
                        "required" : [
                            "location"
                        ]
                    }
                }
            ]
        }
    ],
    "generationConfig" : {
        "maxOutputTokens" : 1024
    }
}

URI: /v1beta/models/gemini-1.5-pro:streamGenerateContent

The response result is throwing an error:

[{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}
]
type or paste code here

It works fine with the non-streaming interface, is there something misconfigured somewhere?

Isn’t a stream supposed to contain ?alt=sse in URI?

Good thought! But…

alt=sse is one possible output format for streaming. (Generally a better one, but not the only one.)
If you don’t specify that, you’ll get a streamed JSON object.

Possibly related: Bug - seeing Request contains an invalid argument when using tool calling

Thanks for the heads-up! I actually didn’t add ?alt=sse , and I didn’t make any code changes either, but it’s working fine now. I think this was a bug with Gemini, and it looks like they’ve fixed it. That detail is really helpful!

Thanks for your feedback! I thought it was a bug, and after waiting a bit, everything’s working fine now without me changing any code. Looks like Gemini has fixed the issue—great news!