b1414c32d12ceeaa664eccd288944935cba16d1d
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:completions({
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.completions("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%