AI Model Wiki

    Skip to main content
    6 min read
    Lesson 5 of 7

    Grok for Developers

    From the course Grok Mastery: xAI's Real-Time AI

    The xAI API gives developers full access to Grok's capabilities for building applications.

    xAI API Overview

    The API is available at api.x.ai and provides:

    • Chat completions — Standard conversational AI endpoint
    • Function calling — Let Grok use tools and external services
    • Vision — Send images for analysis
    • Streaming — Real-time token-by-token responses

    API Pricing

    xAI offers competitive pricing:

    • Grok-3 mini (fast) — Budget-friendly for high-volume tasks
    • Grok-3 mini — Balanced performance and cost
    • Grok-3 — Full flagship model

    Code Example

    from openai import OpenAI
    
    client = OpenAI(
        api_key="your-xai-api-key",
        base_url="https://api.x.ai/v1"
    )
    
    response = client.chat.completions.create(
        model="grok-3-mini-fast",
        messages=[
            {"role": "system", "content": "You are a helpful coding assistant"},
            {"role": "user", "content": "Write a Python function to merge two sorted lists"}
        ]
    )
    print(response.choices[0].message.content)
    

    OpenAI-Compatible API

    The xAI API uses the same format as OpenAI's API, making migration easy. If you have existing code using OpenAI, you only need to change the base URL and API key.

    Best Use Cases for the API

    • Real-time data analysis pipelines
    • Social media monitoring tools
    • Content generation at scale
    • Customer support chatbots
    • Research and fact-checking applications

    Key Takeaways

    • •The xAI API at api.x.ai provides chat, vision, function calling, and streaming
    • •API is OpenAI-compatible — easy migration from existing OpenAI code
    • •Multiple model tiers from budget-friendly mini to full Grok-3
    • •Great for real-time data analysis, social monitoring, and content generation
    0 of 7 lessons marked complete

    Progress is kept in this browser only.