Guides
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.
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.
1import { GrokAdapter } from '@commercegateway/commerce-gateway/grok';2 3const adapter = new GrokAdapter({4 apiKey: process.env.XAI_API_KEY,5 backends: { products: myBackend },6 tools: ['search_products', 'check_inventory'],7});1const response = await fetch('https://api.x.ai/v1/chat/completions', {2 method: 'POST',3 headers: {4 'Authorization': `Bearer ${process.env.XAI_API_KEY}`,5 'Content-Type': 'application/json',6 },7 body: JSON.stringify({8 model: 'grok-1',9 messages: [...],10 tools: adapter.getGrokTools(),11 }),12});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.
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.
Explore the Production Guide to learn how to monitor your Grok integration and handle high traffic from X.
