# Grok, the xAI API and Grok bots

Web page: https://academy.memberpress.ai/courses/ai-tool-guides/l4/

Lesson 4 of 4 in [AI Tool Guides: ChatGPT, Codex, Cursor and Grok](https://academy.memberpress.ai/courses/ai-tool-guides/), 12 min.

**What it is**

Grok is xAI's assistant, at grok.com and in the iOS and Android apps, with chat, voice, image and video generation, file uploads and connectors. It's free to start, with paid SuperGrok plans. Developers reach the same models through the xAI API.

**When to pick it**

When you want Grok's models, or you're building on the API and want to use the OpenAI SDK you already know.

**Setup in the app**

1. Sign in at grok.com or in the app.
2. Attach files with the + next to the message box.
3. To link your X account: Settings, Account, Connect your X Account.

**Setup for the API**

1. Create an account at console.x.ai, add credits, and create a key on the API Keys page. Keep it in an environment variable, `XAI_API_KEY`.
2. Point the OpenAI SDK at xAI:

```python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1")
reply = client.responses.create(model="grok-4.7", input="Explain MCP in two sentences.")
print(reply.output_text)
```

xAI's models page lists `grok-4.7` as its most capable model today; check it before you pick one.

**A first real task**

Run the script above, then change the question to one about your own business and compare the answer with what you'd write.

**Connect it to your site or data**

- **Function calling:** describe your own functions with a name, a description and JSON Schema parameters. The model asks for a call, your code runs it and sends back the result.
- **Remote MCP:** pass an MCP server as a tool, and Grok calls it for you:

```python
tools=[{"type": "mcp", "server_url": "https://academy.memberpress.ai/mcp", "server_label": "academy"}]
```

**About Grok bots**

Grok Bot is xAI's own product: you set up a bot by messaging it, and on X you mention `@bot` in a post or reply to give it a task. It needs an X account connected to Grok, and isn't in every region. xAI's docs don't describe building your own reply bot for X. To build your own bot, use the API: the script above, plus function calling or remote MCP for your data.

Checked against xAI's docs on 2026-10-14: [Grok overview](https://docs.x.ai/grok/overview), [Grok FAQ](https://docs.x.ai/grok/faq), [API overview](https://docs.x.ai/docs/overview), [quickstart](https://docs.x.ai/developers/quickstart), [models](https://docs.x.ai/developers/models), [function calling](https://docs.x.ai/developers/tools/function-calling), [remote MCP](https://docs.x.ai/developers/tools/remote-mcp), [Grok Bot](https://docs.x.ai/grok-bot/overview).

## Try these prompts

- Write a short Python script that asks Grok one question through the xAI API using the OpenAI SDK, reading the key from XAI_API_KEY.
- I want a bot that answers questions about my site using my MCP server. Sketch it with the xAI API and remote MCP tools.
