Tekimax LogoSDK
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-ts

Usage

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 openai package? xAI's API is fully OpenAI-compatible. Instead of writing and maintaining a separate HTTP client, we set baseURL: 'https://api.x.ai/v1' on the same openai SDK. 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-beta or check xAI's documentation for the latest available model identifiers.

On this page