Gemini generateAnswer API is not working

I am trying generateAnswer API by referring the following documentation page.

It is returning,

{
“error”: {
“code”: 400,
“message”: “* GenerateAnswerRequest.model: unexpected model name format\n”,
“status”: “INVALID_ARGUMENT”
}
}

What am I missing? Any help is appreciated.

Request CURL:

curl --location ‘https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateAnswer
–header ‘Content-Type: application/json’
–header ‘x-goog-api-key: <API_KYE>’
–data ‘{
“contents”: [
{
“role”: “user”,
“parts”: [
{
“text”: “What is temperature outside?”
}
]
}
],
“answerStyle”: “VERBOSE”,
“inlinePassages”: {
“passages”: [
{
“id”: “1”,
“content”: {
“role”: “user”,
“parts”: [
{
“text”: “”
}
]
}
}
]
}
}’

1 Like

Welcome to the forums!

The generateAnswer endpoint to do semantic retrieval question answering isn’t supported with all models. In fact, it is only supported with the AQA model. So the name format is invalid because you’re passing it a model it doesn’t expect.

See this page on semantic retrieval for how to use this method. (You have some other issues - including that you need to use OAuth and not an API key.)

That said - what are you trying to do? There are other systems (including tool/function calling that may be better suited to your needs, and if you’re just trying to generate content, you may want to use that method instead.

1 Like

Thank you so much for your response.

I can use OAuth2. It is more convenient. What will be end point for AQA model? Can you please suggest an example endpoint URL? I need to use it from a service written in non-python, hence REST call. My fallback option will be to write a python microservice. But I know REST will work if I can figure out the write CURL.

Nevermind, this worked beautifully.

https://generativelanguage.googleapis.com/v1beta/models/aqa:generateAnswer

1 Like

API key is working. We prefer OAuth. Can you please tell what IAM role is applicable to the following scope.

‘[https://www.googleapis.com/auth/generative-language.retriever’]

Hi @Anil_Sharma,

I guess this quickstart on OAuth under google gemini docs should help you.

Thanks!

Thank you. Yes, I am able to use OAuth.