5b82c5381eef62de6b274dcfa3f5d4e1e24e7761
x-ai SDK
A simple Luau SDK for the x.ai API.
Installation
Install Rokit. Then install Lune like so:
rokit install
Then require the SDK in your Luau code.
Usage
First, get your API key from x.ai.
Create a client instance:
local xai = require("./src/init")
local client = xai.create("your-api-key-here")
Make a chat completion request:
local response = client:responses({
model = "grok-4",
messages = {
{ role = "user", content = "Hello, Grok!" }
}
})
print(response.choices[1].message.content)
For backward compatibility, you can also use the static method:
local response = xai.responses("your-api-key", request)
Types
The module exports several types for requests and responses:
model: Available models like 'grok-4', etc.message: Structure for chat messages.CompletionsResponse: The response from the API.CompletionsRequest: The request structure.
Refer to src/init.luau for full type definitions.
License
MIT.
See LICENSE for details.
Languages
Luau
100%