OpenAI API - Error 400 when dynamically fetching image URL from the database

Hi Bubble community,

I’m having an issue integrating OpenAI 4o API in my Bubble app. The API call works perfectly fine when I manually input a static image URL, but when I try to dynamically pull the URL from my database, I get the following error:

{
“statusCode”: 400,
“message”: "The service OpenAI_Vision - OpenAI_Vision just returned an error (HTTP 400). Please consult their documentation to ensure your call is setup properly. Raw error:
{
"error": {
"message": "Failed to download image from null. Image URL is invalid.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_image_url"
}
}
}

From what I understand, the error means the API is receiving an invalid or null image URL when it’s dynamically fetched from my database. However, the same URL works fine when manually inputted.

How my data is structured:

  • I have a database entry where the image URL is stored in a field called img.
  • The field contains a full valid URL like this:
    https://upload.wikimedia.org/wikipedia/commons/2/2c/USDA_dinner_cropped.jpg
  • I retrieve this image URL dynamically in my API workflow like this:
    Search for testowy_types:first item's img

What I have tried so far:

:check_mark: Checked that the URL stored in the database is correct* by displaying it in a text element – it appears exactly as expected.
:check_mark: Tested sending a manually inputted URL to the API – this works fine.
:check_mark: Used trimmed values in case there were extra spaces:

Search for testowy_types:first item’s img:trimmed

:check_mark: Added a condition in workflow to ensure the URL is not empty:

Only when Search for testowy_types:first item’s img is not empty
`

:check_mark: Debug mode check: The URL appears correctly in debug mode before sending to API.

Possible issue?

  • Could Bubble be formatting the URL incorrectly when sending it via API?
  • Do I need to encode the URL in some way before sending it?
  • Is there a known issue with dynamically retrieving and passing URLs to APIs in Bubble?

Has anyone else faced a similar problem? Any ideas on how to fix this?

Thanks in advance!