How to Post to Twitter (X)
from Grok
Grok can read X natively, but it does not post to your account on its own. You give it a posting tool: a tweet tool in the Grok API, or the OpenTweet MCP server. Copy-ready Python below. No X developer account needed.
Last updated: July 2026
7-day free trial. Cancel anytime.
Can Grok post to X on its own?
No. Grok, from xAI, reads and reasons over X natively because it is built into the platform, but it does not have the ability to publish a post to your account on its own. To make Grok post, you give it a tool, and the tool does the actual posting.
OpenTweet is a Twitter/X scheduler and posting API that holds your X connection, so the tool Grok calls only ever talks to OpenTweet. There are two ways to wire it up, and you pick one:
- Path A, the Grok API: in your own code, define a tweet tool using Grok function calling. Your handler POSTs to OpenTweet.
- Path B, MCP: connect the OpenTweet MCP server so any MCP-capable Grok agent gets a tweet tool with no tool code to write.
Where Grok is genuinely strong
Grok is excellent at reading X in real time, so a good pattern is to let Grok read and decide what to say, then hand the final text to the posting tool. The reading is native to Grok, the posting is the tool you add.Step-by-step: give Grok a posting tool
Get your OpenTweet API key
Sign in to OpenTweet and create an ot_ key at /developer. Connect your X account once. Keep the key in an environment variable, never in the prompt.
export OPENTWEET_API_KEY="ot_your_key"
export XAI_API_KEY="xai-your_key" # from the xAI consolePath A: define a tweet tool in the Grok API
The xAI Grok API is OpenAI-compatible, so you use the openai client with base_url="https://api.x.ai/v1". Declare a post_tweet tool. When Grok calls it, your handler POSTs to OpenTweet and returns the result.
import os, json, requests
from openai import OpenAI
# Grok API is OpenAI-compatible
grok = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1")
OPENTWEET = "https://opentweet.io/api/v1/posts"
HEADERS = {"Authorization": f"Bearer {os.environ['OPENTWEET_API_KEY']}"}
def post_tweet(text: str, scheduled_date: str | None = None) -> dict:
body = {"text": text}
if scheduled_date:
body["scheduled_date"] = scheduled_date # ISO 8601, schedules it
else:
body["publish_now"] = True # publish right away
r = requests.post(OPENTWEET, headers=HEADERS, json=body, timeout=30)
r.raise_for_status()
return r.json()
tools = [{
"type": "function",
"function": {
"name": "post_tweet",
"description": "Post a tweet to the user's connected X account.",
"parameters": {
"type": "object",
"properties": {
"text": {"type": "string", "description": "Tweet text, max 280 chars"},
"scheduled_date": {"type": "string", "description": "Optional ISO 8601 time to schedule"},
},
"required": ["text"],
},
},
}]
messages = [{"role": "user", "content": "Post a tweet announcing our v2 launch today."}]
resp = grok.chat.completions.create(model="grok-4", messages=messages, tools=tools)
msg = resp.choices[0].message
if msg.tool_calls:
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
result = post_tweet(**args)
messages.append(msg)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
# Let Grok confirm to the user
final = grok.chat.completions.create(model="grok-4", messages=messages, tools=tools)
print(final.choices[0].message.content)Path B: connect the OpenTweet MCP server
If your Grok agent is MCP-capable, skip the tool code. Add the hosted MCP endpoint to its connectors and it gets 36 X tools, including posting and scheduling. Setup is one URL.
mcp.opentweet.io/mcpIn an MCP config file, that is a Streamable HTTP server entry. Authenticate with your ot_ key as configured by the client, and the agent can call the tweet tool directly.
{
"mcpServers": {
"opentweet": {
"type": "http",
"url": "https://mcp.opentweet.io/mcp",
"headers": { "Authorization": "Bearer ot_your_key" }
}
}
}What does it cost, and why no X developer account?
OpenTweet is a flat monthly fee with no per-post charge. Building the tool against the X API directly means a developer app and pay-per-use billing on every post.
| Factor | Grok tool + OpenTweet | Grok tool + X API directly |
|---|---|---|
| Price | Flat $11.99/mo (Pro) | X API billing, tiered per project |
| Per-post fee | $0 per post | ~$0.015 per post, ~$0.20 with a link |
| X developer account | Not needed | Required, with billing enrollment |
| Auth in your tool | One ot_ Bearer key | OAuth2 user token, refreshed by you |
| Scheduling | Included via scheduled_date | Not supported by the X API |
| MCP option | Yes, mcp.opentweet.io/mcp | X ships api.x.com/mcp, still pay-per-use |
Grok API cost is separate
The $11.99/mo OpenTweet fee covers posting and scheduling. Your xAI Grok API usage is billed separately by xAI for the model tokens. The posting tool itself adds no per-post fee.
Keep a human in the loop for autonomy
For an autonomous Grok agent, have the tool save a draft or schedule instead of publishing now, then review in the OpenTweet dashboard. Set scheduled_date instead of publish_now to keep control.
Frequently asked questions
Can Grok post a tweet to my account by itself?
No. Grok (xAI) can read and reason over X natively, but it does not post to your account on its own. To have Grok post, you give it a posting tool: either a function-calling tool in the Grok API whose handler calls a posting API, or an MCP server that exposes a tweet tool. OpenTweet provides both paths.
How do I give Grok a tweet tool with function calling?
Use the xAI Grok API through the OpenAI-compatible client, set base_url to https://api.x.ai/v1, and declare a post_tweet tool in the tools list. When Grok emits a tool call, your code POSTs to https://opentweet.io/api/v1/posts with the ot_ Bearer key and text, then returns the result to Grok so it can confirm.
Do I need an X developer account to make Grok post?
No. OpenTweet holds the X connection, so the tool only calls the OpenTweet API with your ot_ key. You never create an X developer app or enroll in X API billing. If you built the tool against the X API directly instead, you would need a developer app, OAuth, and pay-per-use billing.
What is the difference between the API path and the MCP path?
The API path is for your own code that calls the Grok API and handles tool calls, giving you full control over the loop. The MCP path is for an MCP-capable Grok agent: you paste mcp.opentweet.io/mcp into its connectors and it gets 36 X tools with no tool code to write or maintain.
How much does it cost to post to X from Grok?
OpenTweet is a flat $11.99/mo on the Pro plan, which includes the REST API and MCP access with no per-post fee. That is separate from any xAI Grok API usage cost. Posting through the X API directly instead adds about $0.015 per post, or about $0.20 per post if the tweet contains a link.
Keep exploring
OpenTweet vs the X API
Post, schedule, and automate X without a developer account or the $200/mo minimum.
X DM outreach, human-approved
Find and qualify leads, AI-draft DMs, approve each one, and drip-send from your own account via API or MCP.
Post to X without an API
The clean, account-safe way to post to X from your code or an AI agent.
Twitter MCP Server
Give Claude, Cursor, and OpenClaw the ability to post to X. 36 tools included.
Developer docs
Quickstart, API keys, MCP setup, and the REST reference for posting to X from code or an agent.
XMCP vs OpenTweet
X's official MCP server bills per API call and cannot schedule. Compare it with the flat-fee hosted MCP.
MCP for AI agents
Connect your AI client to X in under two minutes, no X developer account.
Developer API and keys
REST endpoints, one bearer key, and usage tracking. Build on OpenTweet.
OpenTweet for AI agents
The posting layer for autonomous agents and automations that live on X.
Build an AI Twitter persona
Give your AI agent its own X account. Setup, cadence, and the rules that keep it safe.
Best MCP servers for social media
The 2026 ranked list. How the hosted OpenTweet MCP compares with the official X MCP and others.
Cheapest way to post to X via code
Flat fee vs pay-per-use. Why the $0.20 per-link fee flips the math past ~60 posts a month.
Give Grok a tweet tool today
Get your ot_ API key and let Grok post to X over the REST API or MCP. No X developer account, no per-post fees.
Get your API key7-day free trial. Cancel anytime.