Piapi Text-to-Image API node failing with bad request

Hi there, my Piapi.ai text-to-image HTTP Request always fails, even though the Piapi.ai task history shows that the task has been completed. I’m suspecting that it’s some kind of bug in the n8n Http request or that something isn’t configured correctly, where it’s not noticing the task being completed.

I’ve checked with the Piapi API team and they’ve confirmed that everything is set up correctly, so it only leads me to think that there might be some debugging to do in n8n.

Is anyone able to help me figure out what I’m doing wrong here?

Thank you in advance!

Hi @sj38

Could you please try using JSON.stringify() like this:

"prompt": {{ JSON.stringify( $json.message.content ) }}

If the issue still exists, please share the complete error message.

I tried both

“text”: “{{ JSON.stringify( $json.message.content ) }}”,

and

“prompt”: “{{ JSON.stringify( $json.message.content ) }}”,

and still ran into this error

{
“errorMessage”: “Bad request - please check your parameters [item 0]”,
“errorDescription”: “invalid request”,
“errorDetails”: {
“rawErrorMessage”: [
“400 - "{\"code\":400,\"data\":{\"task_id\":\"\",\"model\":\"\",\"task_type\":\"\",\"status\":\"\",\"config\":{\"service_mode\":\"\",\"webhook_config\":{\"endpoint\":\"\",\"secret\":\"\"}},\"input\":null,\"output\":null,\"meta\":null,\"detail\":null,\"logs\":null,\"error\":{\"code\":0,\"raw_message\":\"\",\"message\":\"\",\"detail\":null}},\"message\":\"invalid request\"}"”
],
“httpCode”: “400”
},
“n8nDetails”: {
“nodeName”: “Text-to-image”,
“nodeType”: “n8n-nodes-base.httpRequest”,
“nodeVersion”: 4.2,
“itemIndex”: 0,
“time”: “5/21/2025, 3:18:28 PM”,
“n8nVersion”: “1.90.2 (Cloud)”,
“binaryDataMode”: “filesystem”,
“stackTrace”: [
“NodeApiError: Bad request - please check your parameters”,
" at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:607:21)“,
" at processTicksAndRejections (node:internal/process/task_queues:95:5)”,
" at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:681:27)“,
" at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:915:51”,
" at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:1246:20"
]
}
}

Any other ideas here, @mohamed3nan ?

Hi @sj38

According to the API documentation you’re using,

Please try the following JSON body:

{
  "model": "Qubico/flux1-dev",
  "task_type": "txt2img",
  "input": {
    "prompt": {{ JSON.stringify( $json.message.content ) }},
    "width": 1024,
    "height": 1024
  }
}
1 Like

only thing now is what if I don’t want that size of image and prefer it to be 1080 x 1920? I tried to put that in the JSON body, but it’s giving the same error

Hi @sj38

According to the API documentation

width*height cannot exceed 1048576

So 1080 x 1920 = 2,073,600

I think this is why it’s not working…

1 Like

INTERESTING, THAT DID WORK

Glad it worked @sj38

please mark the reply as the solution solution :white_check_mark: :pray:t2:

1 Like