Skip to content

certain GenerateContentConfig params are incompatible with current client API #1398

Description

@punamateo

I am trying to call the completions API with the following generation config, but I am getting a Pydantic error saying that the config params response_mime_type, system_instruction and response_schema are invalid, which is inconsistent with the documentation as of today and the code in the lib itself:

class GenerateContentConfig(_common.BaseModel):

Using API v1, but same error occurred using v1alpha.

To me, it's unclear whether the error is in the lib or in the API that is still updating, or even the model used, hence the need to submit the issue here.

My error:

Setting all components as failed. Reason: Gemini API request failed: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field.\\nInvalid JSON payload received. Unknown name \"responseMimeType\" at \\'generation_config\\': Cannot find field.\\nInvalid JSON payload received. Unknown name \"responseSchema\" at \\'generation_config\\': Cannot find field.', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'description': 'Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field.'}, {'field': 'generation_config', 'description': 'Invalid JSON payload received. Unknown name \"responseMimeType\" at \\'generation_config\\': Cannot find field.'}, {'field': 'generation_config', 'description': 'Invalid JSON payload received. Unknown name \"responseSchema\" at \\'generation_config\\': Cannot find field.'}]}]}}

Environment details

  • Programming language: Python
  • OS: Linux
  • Language runtime version:3.11
  • Package version: 1.32.0

Steps to reproduce

  1. Initialize response_schema and google-genai client
        self.client = genai.Client(api_key=self.api_key,http_options=HttpOptions(api_version='v1')) if self.api_key else None # Using API version v1

            response_schema = {
                "type": "object",
                "properties": {
                    "screens": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "screen_name": {"type": "string"},
                                "sub_prompt": {"type": "string"}
                            },
                            "required": ["screen_name", "sub_prompt"]
                        }
                    }
                },
                "required": ["screens"]
            }
  1. Set GenerationConfig
         generation_config = GenerateContentConfig(
                temperature=1,
                max_output_tokens=10000,
                response_mime_type="application/json",
                system_instruction=formatted_messages["system_instruction"],
                safety_settings=safety_settings,
                response_schema=response_schema
            )
  1. Call the generate_content function with gemini 2.5-pro
            response = self.client.models.generate_content(
                model="models/gemini-2.5-pro",
                contents=formatted_messages["contents"],
                config=generation_config
            )

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.status:awaiting user responsestatus:staletype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions