Adapters
Grok Adapter
The Grok adapter connects to xAI's API for Grok models. xAI exposes an OpenAI-compatible endpoint, so this adapter reuses the official openai npm package with a custom baseURL — no extra dependency required.
Installation
Code
npm install tekimax-tsUsage
Code
import { Tekimax, GrokProvider } from 'tekimax-ts';
const client = new Tekimax({
provider: new GrokProvider({
apiKey: process.env.XAI_API_KEY!,
})
});
const result = await client.text.chat.completions.create({
model: 'grok-beta',
messages: [{ role: 'user', content: 'What is the meaning of life?' }]
});
console.log(result.message.content);Streaming
Code
const stream = client.text.chat.completions.createStream({
model: 'grok-beta',
messages: [{ role: 'user', content: 'Explain quantum mechanics simply' }]
});
for await (const chunk of stream) {
process.stdout.write(chunk.delta);
}Tool Calling
Tool calling works identically to OpenAI since xAI mirrors the same API contract.
Code
const result = await client.text.chat.completions.create({
model: 'grok-beta',
messages: [{ role: 'user', content: 'What time is it in London?' }],
tools: [{
type: 'function',
function: {
name: 'get_time',
description: 'Get current time for a timezone',
parameters: { type: 'object', properties: { timezone: { type: 'string' } } }
}
}]
});
console.log(result.message.toolCalls);Notes
- Why reuse the
openaipackage? xAI's API is fully OpenAI-compatible. Instead of writing and maintaining a separate HTTP client, we setbaseURL: 'https://api.x.ai/v1'on the sameopenaiSDK. This means Grok automatically inherits OpenAI SDK features like automatic retries and streaming. - Text-only: Grok does not currently support image generation, TTS, or vision. Calling
client.images.generate()will throw a capability error. - Model Names: Use
grok-betaor check xAI's documentation for the latest available model identifiers.
