> ## Documentation Index
> Fetch the complete documentation index at: https://betterdatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Grok & X Integration

> Build commerce experiences for X (Twitter) using Grok

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

```typescript theme={null}
import { GrokAdapter } from '@commercegateway/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

```typescript theme={null}
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](/guides/production) to learn how to monitor your Grok integration and handle high traffic from X.
