Im making a live cartoon using ai in roblox but there is a problem

im tryin to make a code where npc talks to another and for some reason i get an error about http 400 bad request. This code uses alot of http

-- This is a simplified example script for two NPCs talking to each other using the OpenAI API.
local HttpService = game:GetService("HttpService")

-- Replace 'YOUR_API_KEY' with your actual OpenAI API key
local apiKey = "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"

local npc1 = game.Workspace["cool guy"]
local npc2 = game.Workspace["mad guy"]

-- Define the conversation
local conversation = {
	{
		role = "system",
		content = "NPC conversation started."
	},
	{
		role = "user",
		content = "Hello NPC2, how are you?"
	}
}

-- Convert the conversation to JSON
local conversationJSON = HttpService:JSONEncode(conversation)

-- Make API request to OpenAI
local apiUrl = "https://api.openai.com/v1/chat/completions"
local requestData = HttpService:JSONEncode({
	messages = conversation,
	max_tokens = 50
})
print("Request Data:", requestData)
local headers = {
	Authorization = "Bearer " .. apiKey
}
local response = HttpService:PostAsync(apiUrl, requestData, Enum.HttpContentType.ApplicationJson, true, headers)


local jsonResponse = HttpService:JSONDecode(response)

-- Get the AI-generated response
local aiResponse = jsonResponse.choices[1].message.content

-- Display the AI response above NPC1
local aiResponseBillboard = Instance.new("BillboardGui")
aiResponseBillboard.Adornee = npc1
aiResponseBillboard.Size = UDim2.new(0, 200, 0, 50)
aiResponseBillboard.StudsOffset = Vector3.new(0, 3, 0)
aiResponseBillboard.AlwaysOnTop = true

local responseText = Instance.new("TextLabel")
responseText.Parent = aiResponseBillboard
responseText.Size = UDim2.new(1, 0, 1, 0)
responseText.Text = aiResponse
3 Likes

This seems like what you’re looking for.

even tho i used that its not helping for some reason
what im looking for is to make a ai sitcom in roblox
not a roblox built chat gpt