Http request that Generates Random Bug pictures / Imaging API

Hey developers! This might sound weird, but I am wondering if there is some sort of Http request that returns a picture of a random bug / insect. I do not need it to be used in rbxassetid://. This might be the most random request but I tried looking for any but I have failed to find any that would work. Another solution I am willing to work with is if there is any free generative AI imaging Text-to-image API however, all I need is something that returns an image of a bugs / insects…

Any help is much appreciated, I have and still am looking for a solution !

2 Likes

so you need a http request that gets a random image of a bug from a database?

i could not find an api either…
just create an array with URLs to images of bugs, like this:

[https://images.unsplash.com/photo-1526773357673-2d4e8116d497?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8aW5zZWN0fGVufDB8fDB8fHww, https://images.unsplash.com/photo-1533048324814-79b0a31982f1?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8NHx8aW5zZWN0fGVufDB8fDB8fHww]

and so-on

1 Like

I mean that is certainly a solution. I would rather, and prefer a generation, or an api to look for them, and or just an api that just has a huge library to pick from already. But I mean if that is not an option I may have to do that. I appreciated your help though!

i might have found what you are looking for

they have lots of photos categorized, so you can just request the “insect” category for example

also i think its free :slight_smile:
edit: they have the “worlds most open collection of images”

1 Like

here is the request URL:

to request images of “insect”:
https://api.unsplash.com/search/photos?query=insect
although you have to supply an OAuth token, or it will return{"errors":["OAuth error: The access token is invalid"]}

1 Like

Sorry for the late reply. I have been trying things for the past 2 hours, trying various solution and handling failures.

By doing something like this, I was able to make it work with just a Access key of an appilication.

For anyone Curious on how I did it, this was my code (With my Access key removed for obvious reasons)

local function GetABugPicture()
	local FailCount = 3 
	local BugImage = nil
	repeat
		
		local BugURL = "https://api.unsplash.com/search/photos?query=insects-and-bugs&page="..math.random(1,300).."&per_page=100&client_id=ACCESSKEYHERE"
		
		local httpResult
		local success, errors = pcall(function()
			httpResult = httpsService:GetAsync(BugURL)
		end)


		if success then

			local Buglist = httpsService:JSONDecode(httpResult)

			if Buglist["total"] >= 1 then 
				BugImage = Buglist["results"][math.random(1, #Buglist["results"])]["urls"]["full"]
			end
		end 


		FailCount -= 1



	until FailCount <= 0 or BugImage ~= nil

	return BugImage
end

print(GetABugPicture())

Thank you so much for your help! I will do appreciate it!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.