got it working by including a responseType param in the axios request.
Node.js code:
const inputData = {
inputs: prompt,
options: {
wait_for_model: true,
},
}
const response = await axios({
url: `https://api-inference.huggingface.co/models/${model}`,
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.HUGGING_FACE_TOKEN}`,
Accept: 'application/json',
'Content-Type': 'application/json',
},
data: JSON.stringify(inputData),
responseType: 'arraybuffer',
})
const mimeType = response.headers['content-type']
const result = response.data
const base64data = Buffer.from(result).toString('base64')
const img = `data:${mimeType};base64,` + base64data
return img
React code:
<img src={img} />