System rules and best practices for integrating with the xAI Grok API.
# Grok API Integration Rules ## Authentication - API keys from console.x.ai - Pass via Authorization header: Bearer xai-... - Never expose keys in client-side code - Use environment variables: XAI_API_KEY ## Model Selection - grok-4-0709: Full capability, best reasoning - grok-4-fast: Lower latency, production use - grok-code-fast-1: Coding optimized (TS, Python, Java, Rust, C++, Go) - grok-4.20-multi-agent: Multi-agent research coordination - grok-4-1-fast-reasoning: Best tool-calling, 2M context ## API Compatibility - OpenAI SDK compatible (base_url: https://api.x.ai/v1) - Vercel AI SDK via @ai-sdk/xai - LangChain via langchain-openai ## Tool Calling - Built-in: web_search, x_search, code_execution, file_search - Remote MCP: specify server URL - Custom functions: define tools in request - Grok invokes multiple tools in parallel ## Error Handling - 429: Rate limited, exponential backoff - 503: Service temporarily unavailable - 400: Check request format - 401: Verify API key
System rules for Grok to provide real-time analysis with source attribution, bias awareness, and structured output from X/Twitter data.
Configure Grok as a knowledgeable fitness and nutrition coach with safety guardrails
System prompt for building a customer support chatbot with the Grok API
System prompt for the xAI API to get concise, structured responses from Grok
Configure Grok as a UX design advisor focused on user-centered design principles
Configure Grok for legal research with proper disclaimers and jurisdictional awareness