N8n AxiosError: Request failed with status code 400 when request huggingface api

Describe the problem/error/question

try to use http request to use huggingface api (https://router.huggingface.co/hf-inference/models/black-forest-labs/FLUX.1-schnell), and get this error.

What is the error message (if any)?

“400 - “{"error":"\n Accept type \"application/json,text/html,application/xhtml+xml,application/xml,text/;q=0.9, image/;q=0.8, /;q=0.7\" not supported.\n Supported accept types are:\n application/json, application/json; charset=utf-8, text/csv, text/plain, image/png, image/jpeg, image/jpg, image/tiff, image/bmp, image/gif, image/webp, image/x-image, audio/x-flac, audio/flac, audio/mpeg, audio/x-mpeg-3, audio/wave, audio/wav, audio/x-wav, audio/ogg, audio/x-audio, audio/webm, audio/webm;codecs=opus, audio/AMR, audio/amr, audio/AMR-WB, audio/AMR-WB+, audio/m4a, audio/x-m4a\n "}””

Please share your workflow

{
“nodes”: [
{
“parameters”: {
“method”: “POST”,
“url”: “https://router.huggingface.co/hf-inference/models/black-forest-labs/FLUX.1-schnell”,
“authentication”: “genericCredentialType”,
“genericAuthType”: “httpHeaderAuth”,
“sendBody”: true,
“bodyParameters”: {
“parameters”: [
{
“name”: “inputs”,
“value”: “Astronaut riding a horse”
}
]
},
“options”: {}
},
“id”: “a9a3f017-4140-4c4c-a5a2-56abfe39da74”,
“name”: “hugginface inference api”,
“type”: “n8n-nodes-base.httpRequest”,
“position”: [
1060,
240
],
“notesInFlow”: true,
“typeVersion”: 4.2,
“credentials”: {
“httpHeaderAuth”: {
“id”: “Vay4JlcEj6OGa4gF”,
“name”: “Header Auth account”
},
“huggingFaceApi”: {
“id”: “mIzGRGnIoHmsInSi”,
“name”: “HuggingFaceApi account”
},
“httpBearerAuth”: {
“id”: “9i3KfM9hPu8rt1Z4”,
“name”: “Bearer Auth account”
}
},
“onError”: “continueErrorOutput”,
“notes”: " "
}
],
“connections”: {},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “0235c51fbef4a13fab52a7af4870495ff00ffd39fb02ea7632edf818ac8c962e”
}
}

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Hi there, the error seems to be because of the body you are sending, can you give me screenshot of the configuration of the http node?

yes, here is the screenshot


try toggling the send headers and do this

and tested use python code to do the request, it works

Try this:
Add Options > Response > Enable Never Error

Why?

n8n (maybe) can’t handle optional response type, like what I quote

You can try from me or from Fahmi. Choose which one make your request is working.

@fahmiiireza @cutecatcode
I tried both of your solution, both return this error

but when I try this, I got a success result

@cutecatcode @fahmiiireza
as the output of the api is an image, how to properly show the image here?

You can convert it into binary file, I suggest you need to use ‘Convert to file’ Node.

Can you show data of the response ? Is it a base64?

If it is.then yeah. Use a. Convert node from base64 to file, and you should get your image, make sure to pinpoint the right field from the json that contains the base64 string

@fahmiiireza @cutecatcode thanks to both of your. It works now

by the way, the guidance of n8n need to improve…

Yes, the guidance :smiley:

Sure thing men, if you can mark my answer as the solution, that would be very appreciated thank you

@fahmiiireza @cutecatcode well, the sad thing is, when I change the value of the Body to expression but not fixed text, it returns error.

I’m on debugging rn, using my HF and self-host n8n. Wait until I got new thing

@Zhisheng_Jiang I’ve created a workflow that maybe you can refer to it.

Also, if it helps you more, feel free to mark my msg as solution:)

1 Like

thank you so much, I’ve marked your answer as solution.

Thanks mate!