Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imagen 3.0 on Vertex sometimes drops error #4302

Open
kstraszewski opened this issue Jan 7, 2025 · 1 comment
Open

Imagen 3.0 on Vertex sometimes drops error #4302

kstraszewski opened this issue Jan 7, 2025 · 1 comment
Labels
ai/provider bug Something isn't working

Comments

@kstraszewski
Copy link

kstraszewski commented Jan 7, 2025

Description

Im getting this error one in 4-5 calls. Model in general works, but sometimes AI-SDK vertex return errror:

APICallError [AI_APICallError]: Invalid JSON response
    at file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:534:11
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    ... 4 lines matching cause stack trace ...
    at async generateImage (file:///var/task/chunks/nitro/nitro.mjs:5841:20)
    at async Object.execute (file:///var/task/chunks/routes/api/chat.post.mjs:28:24)
    at async file:///var/task/node_modules/ai/dist/index.mjs:470:22 {
  cause: _TypeValidationError [AI_TypeValidationError]: Type validation failed: Value: {}.
  Error message: [
    {
      "code": "invalid_type",
      "expected": "array",
      "received": "undefined",
      "path": [
        "predictions"
      ],
      "message": "Required"
    }
  ]
      at _TypeValidationError.wrap (file:///var/task/node_modules/@ai-sdk/provider/dist/index.mjs:324:86)
      at safeValidateTypes (file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:234:34)
      at safeParseJSON (file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:274:12)
      ... 5 lines matching cause stack trace ...
      at async generateImage (file:///var/task/node_modules/ai/dist/index.mjs:818:22)
      at async generateImage (file:///var/task/chunks/nitro/nitro.mjs:5841:20) {
    cause: ZodError: [
      {
        "code": "invalid_type",
        "expected": "array",
        "received": "undefined",
        "path": [
          "predictions"
        ],
        "message": "Required"
      }
    ]
        at get error (file:///var/task/node_modules/zod/lib/index.mjs:587:31)
        at Object.validate (file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:204:101)
        at safeValidateTypes (file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:228:31)
        at safeParseJSON (file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:274:12)
        at file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:528:24
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async postToApi (file:///var/task/node_modules/@ai-sdk/provider-utils/dist/index.mjs:367:14)
        at async GoogleVertexImageModel.doGenerate (file:///var/task/node_modules/@ai-sdk/google-vertex/dist/index.mjs:177:33)
        at async _retryWithExponentialBackoff (file:///var/task/node_modules/ai/dist/index.mjs:271:12)
        at async generateImage (file:///var/task/node_modules/ai/dist/index.mjs:818:22) {
      issues: [Array],
      addIssue: [Function (anonymous)],
      addIssues: [Function (anonymous)],
      errors: [Array]
    },
    value: {},
    [Symbol(vercel.ai.error)]: true,
    [Symbol(vercel.ai.error.AI_TypeValidationError)]: true
  },
  url: 'https://europe-central2-aiplatform.googleapis.com/v1/projects/carbide-bonsai-359620/locations/europe-central2/publishers/google/models/imagen-3.0-generate-001:predict',
  requestBodyValues: { instances: [ [Object] ], parameters: { sampleCount: 2 } },
  statusCode: 200,
  responseHeaders: {
    'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
    'content-encoding': 'gzip',
    'content-type': 'application/json; charset=UTF-8',
    date: 'Tue, 07 Jan 2025 13:20:11 GMT',
    server: 'scaffolding on HTTPServer2',
    'transfer-encoding': 'chunked',
    vary: 'Origin, X-Origin, Referer',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'SAMEORIGIN',
    'x-xss-protection': '0'
  },
  responseBody: '{}\n',
  isRetryable: false,
  data: undefined,
  [Symbol(vercel.ai.error)]: true,
  [Symbol(vercel.ai.error.AI_APICallError)]: true
}

Code example

const response = await experimental_generateImage({
model: vertex.image('imagen-3.0-generate-001'),
prompt,
n: 2,
})

AI provider

"ai": "4.0.27", "@ai-sdk/amazon-bedrock": "1.0.6", "@ai-sdk/anthropic": "1.0.6", "@ai-sdk/google": "1.0.12", "@ai-sdk/google-vertex": "2.0.13", "@ai-sdk/openai": "1.0.13", "@ai-sdk/vue": "1.0.7",

Additional context

No response

@kstraszewski kstraszewski added the bug Something isn't working label Jan 7, 2025
@wx0165927473
Copy link

wx0165927473 commented Jan 28, 2025

I have the same error. Wondering if any updates?

My error msg:

⨯ Error [AI_APICallError]: Invalid JSON response
> 81 |   const { image } = await generateImage({
     |                    ^
  82 |     model: vertex.image('imagen-3.0-fast-generate-001'),
  83 |     prompt: 'a prompt',
  84 |     providerOptions: { vertex: { addWatermark: false } } {
  url: 'xxx/locations/us-central1/publishers/google/models/imagen-3.0-fast-generate-001:predict',
  requestBodyValues: [Object],
  statusCode: 200,
  responseHeaders: [Object],
  responseBody: '{}\n',
  isRetryable: false,
  data: undefined,
  [cause]: Error [AI_TypeValidationError]: Type validation failed: Value: {}.
  Error message: [
    {
      "code": "invalid_type",
      "expected": "array",
      "received": "undefined",
      "path": [
        "predictions"
      ],
      "message": "Required"
    }
  ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/provider bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants