I’m trying to create a flow that connect to a Image Generation API, the first request would send the prompt and style. Then it would give an ID. Next I would need to check the state by calling another GET request, it should check if it’s pending or completed.
Lastly, I used a branch if it’s completed, it will output the image URL, if it false, it should repeat the check state function again?
We don’t have a way to Loop Until. My recommendation is to create another flow that starts with a Webhook trigger, this flow will check for the status and call itself (HTTP) if it’s not yet ready. The first flow will generate the image then call this flow only once, because the second one will repeat itself until it’s done.
1st Flow will begin the image request, and it output a Request ID. (At this juncture, I do not know the state yet)
2nd Flow is design to fetch the state from the Request ID, this would have a Branch which check if the image is ready, if it false, it will request itself with the Request ID again. Is this what you meant?
I thought of this way but I didn’t want to have to keep track of the request ID. I’m assuming this method I would have to store each and every request ID right? Because I can’t have it constantly polling the first flow because that would initiate a new generation request. However, I don’t store the request ID, I wouldn’t be able to call the 2nd flow.
Did I understand this correctly? Or is there another alternative way?
You don’t have to store the Request ID anywhere, call the second flow with it (add it to your HTTP request), then when it calls itself also include the Request ID in it again. This way you’ll persist the Request ID in the requests without storing it.
Here’s my Run history, it would call the webhook to generate the image once, and then repeat to check twice for the image state. By the second request usually it is done, sometimes might take 3 or 4 times. Before eventually it get the link output.
What I’m confused about is, on the frontend, I’m only calling the generate image WebHook once. I’m expecting to have it just wait and process a long time, before eventually getting the link.
However that is not the case, it would return 204, No Content Found. Did I mess up my flow?
I would like to clarify a doubt because i’m still not sure how this this work without needing to save the request state.
Theoretically, this is what my implementation i’m going for is.
User request to generate an image, they would enter the prompt for the AI.
It call the image generation flow, it should wait until there an output with the image link.
1st Flow Config:
Request from Image AI by creating task. Get back a Request ID.
Call a second API endpoint to check on task status and return image link
Most likely it will be false because the AI is still processing, so I have a branch that check if the output has a link.
If True, it will return that link, if false, it will try and call the 2nd Flow,
2nd Flow Config:
It fetch the status with the Request ID, if it still pending, it will call itself. Otherwise, it will return the image link.
Confused about this
Is the first flow supposed to keep calling 2nd flow until it get a response?
A workaround I have is just to delay it for 10 seconds, it work for most of the time because the image should be ready by then, but there’s edge cases if the AI is overloaded or something, it would take more than 10 Seconds. I do understand, some of this I could fix it on the frontend, by storing the state from the first request and polling the 2nd flow again. But I do not want to do that. Just wanted to clarify if there a bug with my flow setup or this is just not possible?
I wasn’t under the impression that the first flow will keep waiting for the result to return it, I thought you wanted to send the image somewhere else.
A new suggestion based on your idea is to:
Delay 10 seconds.
Check.
Delay 10 seconds.
Check
Delay 10 seconds.
Check.
It could cover your use case as per your description. What do you think?