Discussions
key is correct still it's showing apikey is unauthorized
about 2 months ago by Aayush Kumar
const imgGen = async () => {
if (inputRef.current.value === "") {
return 0;
}
try {
const res = await fetch("https://api.monsterapi.ai/v1/generate/txt2img", {
method: "POST",
mode: 'no-cors',
headers: {
'Content-Type': 'multipart/form-data',
Accept: 'application/json',
Authorization: Bearer ${process.env}
},
body: JSON.stringify({
prompt: ${inputRef.current.value}
,
samples:1,
aspect_ratio: "portrait"
}),
});
if (!res.ok) {
throw new Error(HTTP error! status: ${res.status}
);
}
let data = await res.json();
console.log(data);
} catch (error) {
console.error('Error fetching image:', error);
}
};