DEV Community

Korvus
Korvus

Posted on

Calling a ChatGPT-style API from a Roblox game (server-side)

You can give a Roblox game real generated text — dialogue, quests, item names — with a single HTTP request. The catch is where you make it.

HttpService, from the server only

local HttpService = game:GetService("HttpService")

local ok, res = pcall(function()
    return HttpService:PostAsync(ENDPOINT, HttpService:JSONEncode({
        system = "You are a wise shopkeeper. One sentence.",
        text = "what do you sell?",
    }), Enum.HttpContentType.ApplicationJson, false, { Authorization = "Bearer " .. KEY })
end)
Enter fullscreen mode Exit fullscreen mode

Turn on Game Settings → Security → Allow HTTP Requests first, or every call fails.

The limits you will hit

  • 500 requests/min per server. Cache repeated prompts so you don't burn the budget.
  • No SSE streaming in live games. Streaming only works in Studio; live servers are request/response.
  • Moderation. Anything player-facing must be filtered, or your game risks removal.

A shortcut

The Cortex kit wraps all of this — one key, caching, retries, and moderation on by default, billed in Robux instead of a credit card. But the pattern above works with any backend. Open source: https://github.com/cortex-rbx/roblox-ai-kit

Top comments (0)