n8n API Call Issue: Claude AI Returns Array Format Error - JSON Structure Problem

I’m having trouble making API calls to Claude AI through n8n and keep getting validation errors.

The Issue:

  • Making requests to Claude’s chat API endpoint
  • Keep getting 400 response: “messages: Input should be a valid list”
  • The API expects a proper JSON array but n8n seems to convert it to text

What I’ve Tested:

  1. JSON mode with field configuration:

    conversations: [{"role": "user", "content": "hello"}]
    

    Still sends as text instead of array

  2. Raw JSON approach:

    {
      "model": "claude-3-5-sonnet-20241022",
      "conversations": [{"role": "user", "content": "hello"}]
    }
    

    Same validation error occurs

  3. Expression format:

    ={{ [{"role": "user", "content": "hello"}] }}
    

    Shows [object Object] in the output

Setup Info:

  • Using n8n cloud version
  • HTTP Request node
  • Auth working fine (tested other endpoints)
  • Headers: application/json, anthropic-version: 2023-06-01

Does anyone know how to properly format JSON arrays in n8n HTTP requests? Is there a specific way to ensure arrays don’t get stringified?

Any help with Claude API integration would be great!

Had this exact issue with Claude through n8n last month. The problem is n8n’s HTTP Request node screws up object serialization when you mix field config with raw JSON. I switched entirely to raw JSON body and made sure the parameter name matched Claude’s API spec exactly. You mentioned “conversations” but Claude’s API wants “messages” instead. Try this in raw JSON body: { “model”: “claude-3-5-sonnet-20241022”, “messages”: [{ “role”: “user”, “content”: “hello” }], “max_tokens”: 1024 } Don’t mix body config methods - use all fields OR raw JSON, never both. Claude’s API requires max_tokens too, which might be causing validation errors. Once I fixed the parameter name and stuck with pure raw JSON, arrays passed through fine without getting stringified.

Had the exact same issue with Claude and n8n! The problem is n8n’s auto type conversion messing with your request. Here’s what fixed it for me: stick a Function node right before your HTTP request and build the entire payload there as a JavaScript object. Skip trying to format everything in the HTTP node - n8n will just butcher it. Also check your anthropic-version header. I use 2023-06-01 since it’s less picky about array formatting, but make sure your request body matches what that version wants. The Function node trick saved me tons of headaches with nested objects getting scrambled.

Yeah, this array serialization problem is super common with n8n’s HTTP Request node. I’ve hit the same wall when working with APIs that need proper JSON arrays. The issue is how n8n handles data types behind the scenes. When you use expressions like ={{ [object] }}, n8n usually converts complex objects to strings during serialization. Here’s what worked for me: set the body type to ‘Raw/JSON’ and make sure you explicitly set the Content-Type header to ‘application/json’. Also, check your expressions in the node’s output preview before running anything. n8n’s expression engine gets weird with nested objects, especially when you mix static values with dynamic expressions. My go-to fix is building the message array in a Code node first using JavaScript, then just reference that data in your HTTP request. You get way more control over the exact JSON structure going to Claude’s API.