[SOLVED] HTTP 429 (Too Many Requests)

Hi, I’m trying to make a chatbot, where the player sends a message in chat and the bot responds. I’m using models from HuggingFace, but I keep getting “HTTP 429 (Too Many Requests) - Server - AI:23”
I looked everywhere in the developer forum… I even tried adding the following header:

local headers = {
	["Authorization"] = Bearerkey
}

And modified

local response = HttpService:PostAsync(API_URL, jsonPayload, Enum.HttpContentType.ApplicationJson, false)

To

local response = HttpService:PostAsync(API_URL, jsonPayload, Enum.HttpContentType.ApplicationJson, false, headers)

This is the entire code:

local NPC = script.Parent
local MyHuman = NPC:WaitForChild("Humanoid")
local MyRoot = NPC:WaitForChild("HumanoidRootPart")
local Gyro = MyRoot:WaitForChild("BodyGyro")
local chat = game:GetService("Chat")
local HttpService = game:GetService("HttpService")
local API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-base"

Gyro.MaxTorque = Vector3.zero

-- Function that sends the input to the chatbot and returns the response

local function conversate(payload)
	-- Encode the payload as a JSON string
	local jsonPayload = HttpService:JSONEncode(payload)
	-- Send a POST request to the API URL with the headers and the payload
	local response = HttpService:PostAsync(API_URL, jsonPayload, Enum.HttpContentType.ApplicationJson, false)
	-- Decode the response as a JSON table
	local jsonResponse = HttpService:JSONDecode(response)
	-- Return the JSON table
	return jsonResponse
end

-- Main

game:GetService("Players").PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	Gyro.MaxTorque = Vector3.new(0,4000000,0)

	Gyro.CFrame = CFrame.new(MyRoot.Position,rootPart.Position)
	
	wait(2)
	
	chat:Chat(NPC.Head,"Hey, "..player.Name..", welcome to my house!",Enum.ChatColor.White)
	
	player.Chatted:Connect(function(message)
		local data = {["inputs"] = message}
		local response = conversate(data)
		
		chat:Chat(NPC.Head,response,Enum.ChatColor.White)
		
		Gyro.CFrame = CFrame.new(MyRoot.Position,rootPart.Position)
	end)
end)

HTTP status code 429 means that you are sending too many requests in a certain time span. Your script might be querying the API too fast hence you’re getting blocked. Most servers return a Retry-After header indicating how long you have to wait before your IP gets unblocked.

Not sure what the value of BearerKey is but your token must be prefixed with Bearer like this Bearer <YourToken> when using bearer authorization.

The HTTP request only happens once, each time a player sends a message in chat, and for some reason when testing in Roblox Studio, upon the first message I send it gives this error, but when I play the game in Roblox then I get the response but only at the first message, and when I send more it gives the 429 error.

I reccomend you check the API’s docs to understand how it rate limits IPs and how to properly use it without getting restricted.

At the end I settled on a different way of communicating through HTTP requests with the bot, thanks for trying to help, though!

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