59 lines
1.1 KiB
Markdown
59 lines
1.1 KiB
Markdown
# 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](https://x.ai).
|
|
|
|
Create a client instance:
|
|
|
|
```luau
|
|
local xai = require("./src/init")
|
|
|
|
local client = xai.create("your-api-key-here")
|
|
```
|
|
|
|
Make a chat completion request:
|
|
|
|
```luau
|
|
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:
|
|
|
|
```luau
|
|
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. |