Error when passing downloaded Drive image to LLM Chain

Describe the problem/error/question

Hi, I’m trying to set up a workflow where scanned receipts will be parsed by an LLM and then the data stored for later reporting. I’m using integration with Google Drive and I have a trigger node followed by a download file node that feeds into the Basic LLM Chain node.

Everything works until the LLM Chain node where I receive an error.

What is the error message (if any)?

Bad request - please check your parameters

messages.0.content.0.image.source.base64.data: The image specified was not valid

Please share your workflow

Share the output returned by the last node

{
  "errorMessage": "Bad request - please check your parameters",
  "errorDescription": "messages.0.content.0.image.source.base64.data: The image specified was not valid",
  "errorDetails": {
    "rawErrorMessage": [
      "400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.0.image.source.base64.data: The image specified was not valid\"}}"
    ],
    "httpCode": "400"
  },
  "n8nDetails": {
    "nodeName": "Anthropic Chat Model",
    "nodeType": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
    "nodeVersion": 1.2,
    "time": "27/11/2024, 16:51:07",
    "n8nVersion": "1.68.0 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "NodeApiError: Bad request - please check your parameters",
      "    at Object.onFailedAttempt (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/dist/nodes/llms/n8nLlmFailedAttemptHandler.js:13:30)",
      "    at RetryOperation._fn (/usr/local/lib/node_modules/n8n/node_modules/p-retry/index.js:67:20)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)"
    ]
  }
}

Information on your n8n setup

  • n8n version: 1.68.0 (Self Hosted)
  • Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker on DigitalOcean
  • Operating system: Ubuntu 22.04

I found the input to Claude, extracted the base64 representation of the image, converted it back into an image and found the original image.

{
  "messages": [
    "Human: [\n  {\n    \"type\": \"image_url\",\n    \"image_url\": {\n      \"url\": \"data:image/jpeg;base64,<lots of base64 stuff>\"\n    }\n  },\n  {\n    \"text\": \"The following is an image of a grocery store invoice. Please parse the image and tell me the details.\",\n    \"type\": \"text\"\n  }\n]"
  ],
  "estimatedTokens": 1264299,
  "options": {
    "anthropic_api_key": {
      "lc": 1,
      "type": "secret",
      "id": [
        "ANTHROPIC_API_KEY"
      ]
    },
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 2048,
    "temperature": 1,
    "top_k": -1,
    "top_p": -1,
    "api_key": {
      "lc": 1,
      "type": "secret",
      "id": [
        "ANTHROPIC_API_KEY"
      ]
    }
  }
}

I removed it from the snippet above because it’s a lot.

OK, so the original image was a 1.4 MB png. I converted it to a smaller jpeg and now it works.