Skip to main content
Better Data provides first-class support for integration with xAI’s Grok model, allowing you to bring conversational commerce directly to millions of users on X.

How it Works

Grok supports tool calling via the xAI API, which is compatible with the OpenAI format but optimized for the X ecosystem. The LLM Gateway provides a dedicated adapter to handle these specific requirements.

Implementation

1. Setup the Grok Adapter

import { GrokAdapter } from '@betterdata/commerce-gateway/grok';

const adapter = new GrokAdapter({
  apiKey: process.env.XAI_API_KEY,
  backends: { products: myBackend },
  tools: ['search_products', 'check_inventory'],
});

2. Execute with xAI API

const response = await fetch('https://api.x.ai/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.XAI_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'grok-1',
    messages: [...],
    tools: adapter.getGrokTools(),
  }),
});

X Features

Shoppable Tweets

When the gateway is used in the context of X, it can automatically include metadata that allows X to render “Shoppable Cards” or “X Shop” links directly in the conversation.

Real-time Pulse

Grok can leverage real-time data from X. The LLM Gateway can complement this by providing real-time inventory and pricing, ensuring that “trending” products are actually available for purchase.

Next Steps

Explore the Production Guide to learn how to monitor your Grok integration and handle high traffic from X.