Is response parameter supported in Google AI?

Hi,

I got following error when trying the function call with gemini 2 Python SDK:

“response parameter is not supported in Google AI.”

Here is the code that defines the function call

my_func_call = types.FunctionDeclaration(
    name="test_func",
    description="Test func ...",
    parameters={ ...
    },
    response={
        "type": "OBJECT",
        "properties": { ...           },
        },
    },
)

The SDK definition of types.FunctionDeclaration is

class FunctionDeclaration(_common.BaseModel):
  """Defines a function that the model can generate JSON inputs for.

  The inputs are based on `OpenAPI 3.0 specifications
  <https://spec.openapis.org/oas/v3.0.3>`_.
  """

  response: Optional[Schema] = Field(
      default=None,
      description="""Describes the output from the function in the OpenAPI JSON Schema
      Object format.""",
  ) 
....
  )

The invocation code is:

resp = client.models.generate_content(
            model="gemini-2.0-flash-exp",
            contents=prompt,
            config=types.GenerateContentConfig(
                tools=[my_func_call],
            ),
        )

Does anyone have success with defining response schema for a function call in the new 2.0 API?

Thanks

Hi @hsun , Welcome to the forum.

Google AI API does not support response parameter. You should use Vertex AI API instead. Below is an example code for reference:

from google import genai
from google.genai import types

client = genai.Client(
    vertexai=True, project='your-project-id', location='us-central1'
)

get_current_weather_func = types.FunctionDeclaration(
    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"
            }
        }
    },
   
    response={
        "type": "OBJECT",
        "properties": {
            "weather": {
                "type": "STRING",
                "description": "The weather in the city"
            },
        },
    },
)

weather_tool = types.Tool(
    function_declarations=[get_current_weather_func],
)

response = client.models.generate_content(
    model=MODEL_ID,
    contents="What is the weather like in Boston?",
    config=types.GenerateContentConfig(
        tools=[weather_tool],
        temperature=0,
        ),
)

response

Thanks