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
Workflows from the Neura Market marketplace related to this Grok resource