Steps :
-Go to your game’s security settings and switch Allow HTTP Requests to on
-Replace the apiKey
with your Gemini API key; Get your Gemini API key here (must be 18+ and be in availible countries, you’ll be redirected here if you’re not eligible)
-Change prompt
string to your prompt
-Do whatever you want with msgfinal
as it’s what Gemini retuened
Recommendation :
-I recommend filtering the results using TextService:FilterStringAsync() as you can’t guarantee the results are up to ROBLOX TOS standards.
-Get trustworthy developers as you have to trust your developers with your Gemini API key.
Code down below :
local HttpService = game:GetService("HttpService")
local apiKey = "insert ur api key here"
local url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key="..apiKey
local prompt = "insert ur prompt here"
local requestBody = HttpService:JSONEncode({
contents = {
{
parts = {
{ text = prompt }
}
}
}
})
local success, response = pcall(function()
return HttpService:PostAsync(url, requestBody, Enum.HttpContentType.ApplicationJson, false)
end)
-- Handle the response
if success then
local decodedResponse = HttpService:JSONDecode(response)
local msgfinal
for index,text in pairs(decodedResponse["candidates"][1]["content"]["parts"][1]) do
msgfinal = text
end
print(msgfinal)
else
print("error: "..response)
end