Help with Replicate APIs

I need help with Replicate’s - Image Restoration. I have setup the API and it works well (for the POST part)

However, I am stuck trying to get the output (the processed image). I need help deciphering the output schema - is the output sent as an URL /file/image and how can I save it to my database



I am not familiar with Replicate’s, but I encountered similar APIs before.
A simple solution that worked for me is a GET api call to fetch the data (or the file) from the UR.,
So you just need to create a GET API call (and use the URL you received from Replicate’s as the destination).


This isn’t the Replicate API, but here’s a video I made with how to use the Computerender API (which also uses Stable Diffusion): Build your own AI Generation App using DALLE-2 and Bubble in 20 minutes - YouTube

Agree with @eldad1 looks like you just need to make another GET call to retrieve the image (try picking “file” as the response type), and you would feed it the URL from the POST API response

Thank you for sharing this. I had used OpenAPI before, but had always been saving each of the outputs in the database. After watching your video, I discovered how to use custom states to store/view the results. Neat tip.

Thank you for the response. I tried using the GET call, but it wasn’t clear where I should provide the input. Let me play around with the settings some more…

Screen Shot 2022-12-01 at 8.06.33 AM

Ok. Will try it again

They idea would that after you do a POST call with the JSON body has you have in the second image, you retrieve the image URL (let’s say results.url.get) and you put the image URL as the destination of a new GET call

Hey. did you ever work this out? I wonder, if in order to access the data you need to create a webhook as described here that notifies you when the output has been completed

  • webhook_completed: A webhook that is called when the prediction has completed. It will be a POST request where the request body is the same as the response body of the get prediction endpoint. If there are network problems, we will retry the webhook a few times, so make sure it can be safely called more than once.

I tried using a GET call to get the output, but it retrieves a list of all the predictions in my account. I tried to filter the desired result based on id/input value and it didn’t seem to work. Something is still off.
Based on your feedback, it appears I need to send the {prediction_id} in the GET call so that it returns the generated image for the specific input.
I will also try the webhook_completed recommendation.

No, this didn’t work. I can share the app if you’d like to take a look.
I know the Post call worked as I can see the output in Replicate dashboard. Its getting the output link that’s not working for me.

I am actually trying to solve a similar problem with the API and I have not worked it out either.

Basically, if you use the Get Prediction API call to collect the image and put it in the database, it will not put it into the database because the image is still ‘processing’ (you can check this by looking at what the status returns - it will only return a url for the image if the status has ‘succeeded’).

As such you either need to create a pause between Create Prediction and Get Prediction to give the model enough time to generate the image OR what I am trying to do but failing at is to call a webhook whereby alerts you to when the image has been processed successfully.

Yes, we are having the same issue. I spent all morning trying to get this working and couldn’t. When the GET API call is initiated the status always returns “starting” and hence it doesn’t find an output file. My initial GET calls was pulling all the predictions as a list, but was able to figure out how to initiate the call for a specific prediction.

I discovered about webhook after reading your post, but couldn’t figure out a way to setup the webhook on Replicate. I moved onto another app I am working on, as this was consuming too much time. After pixel pushing, I think this is the most frustrating part of app development - the output is right there - you can see it and you want to grab it, but can’t :).

How are you failing on the webhook call?

I’m stuck too, but will post here if I have any success. I wish the replicate documentation was a bit more detailed

Likewise, I will update if I find a solution.
Since the issue is related to Replicate, its best to post on their forum

Hi mate,

Ive got it working now:

  1. Create a backend workflow

  1. Detect data and copy the URL webhook

  1. Set up the "Create a Prediction: API (I am using stable-diffusion but it will be the same for the model you are trying to access). Make sure to include the webhook_completed parameter and add the URL webhook you copied earlier.

Your input will be different from mine, but the main thing is to add the URL webhook like the screenshot.

  1. In many 3rd party apps (like Stripe) you can initialise the webhook directly from the 3rd party app - unfortunately Replicate does not have this feature. Therefore you can initalise the webhook by sending the POST request through POSTMAN. Simply recreate the “Create a Prediction” POST request in POSTMAN. (Make sure to add your API key and Content-Type in the header)

  1. Make sure the backend workflow is “Detecting Request Data” and then hit send on the POST request in POSTMAN. It should initalize in the Bubble app and you will see the the response parameters available in Bubble.

  1. After the webhook is initalised, go back into your “Create a Prediction” API and remove the word “initialize”

  1. In order to ensure you are getting the results only after the model has successfully ran, set a condition so that you only get the POST request when the model has “succeeded”

  1. Finally you can then create “a thing” based on the parameters that have been returned by the POST request. In the case of replicate it seems all the images are passed through the “output” parameter as a URL

You will note, that you never need to use the “Get a Prediction” call, as retrieving the output of the model is already built into the “Create a Prediction” API call by virtue of the webhook.

Sorry if some of the language is imprecise, but hopefully you get the gist from the screenshots.

Hope that helps! Good luck!

Thank you for the detailed explanation…sincerely appreciate it. I was trying to avoid using another service was to avoid to the flow, but looks like I may not have an option. I had read about the option of adding a delay after the call was initiated using the “Add a Pause before next action” and varied the delay time from 1s to 10s and the status remains at “starting” :(.
I tried to emulate your setup, but couldn’t get past the first step - where you provide the constraint “Only when: Request Data’s status is succeeded”. I can’t select the “status” option as nothing gets displayed. Not a great day with bubble today…
With that said, I discovered “Database trigger event”, will explore that.
Changing topics, can stability-diffusion restore old images. I am basically trying to restore old photos and am using the gfpgan model. Of the few models I tried, this works well.

you can only add that condition after you have initialised the webhook ( I must have screenshotted the finished result)

(Request Data comes from the webhook so it needs to be initliased first) - only add that condition in step 7)

so this is how i made it work: i have 2 api calls, one for generate image and one for retrieve it. when the button is clicked we generate the image and display data in a group. after that we make a workflow: to this every 5 seconds - retrieve the image - get the id from the group we displayed data in and display the new data in another group. just add an image in that group and for the dynamic source: Parent group’s Retrieve Image’s output:first item. it may not be a better one but its working and you dont have to make the make a pause before next action workflow. Also if you need some sort of letting people know that is loading just add a rotating icon in the same group as the image and display it when parent group output is emty

I ended up using this method. all good until i had to associate the generated images to a user. do you have a method to pass an authentification so that the backend workflow recognises the current user?