I'm trying a basic integration of AI into Smart Contracts using Chainlink Functions and I got an error after sending the request, resulting in empty response, even though I've been charged for the API call.
Error during functions execution: Error: {"error":true,"message":"AbortError: The signal has been aborted"}
I'm making a text-to-image call. I thought it could be a timeout execution issue but I do not get how to address it anyway. Any help?
Thanks
This is the source script used to send the request:
const _prompt = args[0];
const postData = {
model:"dall-e-3",
prompt: _prompt,
size:"1024x1024",
n:1,
};
const openAIResponse = await Functions.makeHttpRequest({
url: "https://api.openai.com/v1/images/generations",
method: "POST",
headers: {
Authorization: `Bearer ${secrets.apiKey}`,
"Content-Type": "application/json",
},
data: postData
});
if (openAIResponse.error) {
throw new Error(JSON.stringify(openAIResponse));
}
const result = openAIResponse.data.data[0].url;
console.log(result);
return Functions.encodeString(result);
"The signal has been aborted" is a timeout error on the Functions side. The default value for the
makeHttpRequest
is 3000 ms.At the following docs URL you can see how to manually increase it. In this case, that would be:
Keep in mind that there are general service limits when using Functions, you can check them out in the official documentation as well. At the moment the duration of a single HTTP request must not exceed 9 seconds.