HTTP 400 (Bad request) only in-game

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

An code that uses ChatGPT api to give responses

  1. What is the issue? Include screenshots / videos if possible!

When i try in studio, it works perfectly
But when i try in-game, it gives me the error HTTP 400 (Bad request)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes, but i didnt found any solutions

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function RawAiResponse(Input:string,Tokens:string,Stop:string?)
	local HTTP = game:GetService("HttpService")
	
	local url = "https://api.pawan.krd/v1/completions"

	local key = "my key"

	local headers = {
		["Authorization"] = key,
	}

	local body = HTTP:JSONEncode({
		model = "text-davinci-003";
		prompt = Input;
		temperature = 0.5;
		max_tokens = Tokens or 256;
		stop = Stop or {
			"Human:";
			"IA:"
		};
	})

	local response = HTTP:PostAsync(url, body, Enum.HttpContentType.ApplicationJson, nil, headers)

	local decoded = HTTP:JSONDecode(response)

	return decoded
end


print(RawAiResponse("Hello ChatGPT, AI:"))

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Are you sure that the method you send to the API is a Post ?

Yes, and anyways it works on studio perfectly so that is not the problem exactly.

Try to change
image
these into strings

1 Like

image

Still the same error