Skip to content

AI_TypeValidationError when using gemini-2.0-flash-exp model with @ai-sdk/google-vertex (image response) #6109

@sulemankhann

Description

@sulemankhann

Description

I'm running into a TypeValidationError when using the gemini-2.0-flash-exp model via @ai-sdk/google-vertex. This model is multimodal and returns both text and image responses. The issue occurs only when the model responds with an image (in base64); text-only responses work fine.

This setup was working correctly just a few days ago, and I haven't changed anything in my code or dependencies since then.

Package versions:

"@ai-sdk/google-vertex": "^2.2.18",
"ai": "^4.3.13"

Error details:

`_err _TypeValidationError [AI_TypeValidationError]: Type validation failed: Value: {"candidates":[{"content":{"role":"model","parts":[{"inlineData":{"mimeType":"image/png","data":"iVBORw0KGgoAAAANSUhEUgAABAAAAAIxCAIAAABciV3mAAAAiXpUWHRSYXcgcHJvZmlsZSB0eXBlIGlwdGMAAAiZTY...."

 cause: ZodError: [
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        0,
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        0,
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        1,
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        1,
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        2,
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        2,
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        3,
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "candidates",
        0,
        "safetyRatings",
        3,
      ],
      "message": "Required"
    }
  ]

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelprovider/google-vertexIssues related to the @ai-sdk/google-vertex providersupport

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions