Twitter (X) Reply API — A Programmatic Tutorial
- POST /2/tweets with
in_reply_to_tweet_id= target tweet ID - Official route requires OAuth user-context (X account you have auth on)
- Priced $0.015 per reply ($0.200 if it contains a URL) per docs.x.com/x-api/getting-started/pricing
- Second route: TwitterAPI.io
POST /twitter/create_tweet_v2withreply_to_tweet_id, $0.0006 per reply plus one $0.10 login per session, through your own account session - Pace 1-2 seconds between replies to avoid rate-limit / spam-detection
Replying via API to Twitter (X) posts is one of the most common write-side workflows — customer support bots, AI reply agents, automated engagement, threaded conversation flows. This tutorial walks the exact call + auth requirements + rate-limit pacing.
Pricing references URL-cited to X's docs.
$0.015, or $0.200 with a URL, on the official X API (Post: Create, docs.x.com 2026); $0.0006 per create_tweet_v2 reply on TwitterAPI.io, plus a $0.10 login per session
The reply mechanic — one field difference from a regular tweet
A reply on X is technically a tweet with in_reply_to_tweet_id populated. That single field tells X's system to thread the new tweet under the target, apply reply-specific rendering, and route notification to the target's author.
Everything else about the tweet is the same as a regular POST — text (280 char limit), optional media attachments, mentions, hashtags, reply_settings for who can reply back.
The X official POST call
Endpoint: POST /2/tweets. Auth: OAuth 1.0a user-context (an X account you have the 4-key credential set for). Body: JSON with text + reply.in_reply_to_tweet_id.
Pricing per docs.x.com/x-api/getting-started/pricing: $0.015 per post created, $0.200 if the post contains a URL.
# pip install tweepy
import tweepy
client = tweepy.Client(
consumer_key="...", consumer_secret="...",
access_token="...", access_token_secret="...",
)
def reply_to(target_tweet_id: str, text: str):
resp = client.create_tweet(
text=text,
in_reply_to_tweet_id=target_tweet_id,
)
return resp.data
# Reply to a specific tweet
result = reply_to("1234567890", "Thanks for the question — full answer on our blog: https://...")
print(f"reply posted, id: {result['id']}")Second route — TwitterAPI.io /twitter/create_tweet_v2 with reply_to_tweet_id
Write actions on TwitterAPI.io run through an authenticated session: you log the account in once with POST /twitter/user_login_v2 ($0.10 per login), passing your X username, email, password and a proxy you supply (a residential or ISP proxy works best), and it returns login_cookies. Store the returned login_cookies and reuse them until the session ends; do not log in on every run. Each post, delete, like, retweet, follow or unfollow is then one call at $0.0006 that takes login_cookies and the same proxy. The call acts as that X account, so X's rules apply to it and X can rate-limit, lock or suspend the account; keep a human pace. The session can stop working and require a new login. The proxy is required on every write call. Billing is per call that returns HTTP 200, and that includes some refusals from X, which come back as HTTP 200 with status: error. Reads are different: they need only an API key and no X account at all.
POST /twitter/create_tweet_v2 takes a JSON body with three required fields: login_cookies, tweet_text and proxy, plus your key in the X-API-Key header. Setting the optional reply_to_tweet_id field to the target post's ID makes the new post a reply. The API reference lists tweet_id in the response next to status (success or error). The target ID can come from a read call such as GET /twitter/user/mentions, which needs only the API key.
Price, side by side: $0.015 per reply on the official API (Post: Create) vs $0.0006 here (0.015 / 0.0006 = 25x), plus the $0.10 login, which is one per session and not one per reply. For 50 replies that is 50 × $0.015 = $0.75 official vs 50 × $0.0006 + $0.10 = $0.13 here. A reply that contains a URL is $0.200 on the official rate card. For a single reply on a fresh login the official side is cheaper: $0.015 there vs $0.0006 + $0.10 = $0.1006 here. The two totals cross at 7 replies per login.
A direct message is a separate endpoint, POST /twitter/send_dm_to_user ($0.0006 per call; body login_cookies, user_id, text, proxy). It acts as the same account under the same conditions as a reply, and it only reaches people who accept DMs.
import os, requests
BASE = "https://api.twitterapi.io"
HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
PROXY = os.environ["X_PROXY"] # a proxy you supply: http://username:password@ip:port
def login() -> str:
"""Log the account in once ($0.10) and return login_cookies. Store and reuse it."""
body = {
"user_name": os.environ["X_USERNAME"],
"email": os.environ["X_EMAIL"],
"password": os.environ["X_PASSWORD"],
"proxy": PROXY,
}
if os.environ.get("X_TOTP_SECRET"):
body["totp_secret"] = os.environ["X_TOTP_SECRET"]
r = requests.post(f"{BASE}/twitter/user_login_v2",
headers=HEADERS, json=body, timeout=120)
r.raise_for_status()
data = r.json()
if data.get("status") != "success":
raise RuntimeError(f"login failed: {data.get('message')}")
return data["login_cookies"]
def reply_to(login_cookies: str, target_tweet_id: str, text: str) -> dict:
"""Reply to one post through the logged-in session."""
if len(text) > 280:
raise ValueError(f"reply too long: {len(text)} > 280")
r = requests.post(
f"{BASE}/twitter/create_tweet_v2",
headers=HEADERS,
json={
"login_cookies": login_cookies,
"tweet_text": text,
"reply_to_tweet_id": target_tweet_id,
"proxy": PROXY,
},
timeout=60,
)
r.raise_for_status()
return r.json() # carries "status": "success" or "error"
cookies = os.environ.get("X_LOGIN_COOKIES") or login() # store and reuse the value
result = reply_to(cookies, "1234567890", "Thanks for the question, the answer is in our docs.")
print(result.get("status"), result.get("message"))
reply_settings — who can reply to your reply
X's tweet-object supports reply_settings controlling who can reply. Values: everyone (default), mentionedUsers (only accounts you mention), following (only accounts you follow).
For a customer-support bot, everyone is right — you want customers to reply. For a curated thread, mentionedUsers limits noise. For AI reply agents, everyone again — you want the conversation open. On the reading side, these same settings (plus hidden replies, spam filtering and mutes) are why some people can't see every reply under a post; how to see comments on X explains each case.
# Restricting replies to mentioned users only
resp = client.create_tweet(
text="Curated thread → @user1 @user2 join the conversation",
in_reply_to_tweet_id="1234567890",
reply_settings="mentionedUsers",
)Rate-limit pacing for bulk replies
X publishes per-user rate limits at docs.x.com/x-api/fundamentals/rate-limits. For reply-bot workloads, pace 1-2 seconds between calls. Bursting risks 429 rate-limit responses + triggers X's spam detection.
Beyond rate-limit: content variation. Replying with near-identical text across many targets gets flagged as spam even at safe pacing. Vary your replies meaningfully (per-target context, template variation).
import time, random
def bulk_reply_paced(pairs):
"""pairs = list of (target_tweet_id, reply_text)"""
for target_id, text in pairs:
try:
client.create_tweet(text=text, in_reply_to_tweet_id=target_id)
except tweepy.TooManyRequests:
print(" rate-limited, sleeping 60s...")
time.sleep(60)
continue
# 1.5s pace + random jitter
time.sleep(1.5 + random.uniform(0.1, 0.5))
bulk_reply_paced([
("1234567890", "Great point — added to our roadmap"),
("1234567891", "Different angle worth exploring: ..."),
])Common reply workloads
Customer-support auto-reply: monitor mentions of your handle + reply with FAQ answers or route to a human. Rate-limited to ~30-100/day per account.
AI reply agent: LLM reads the target tweet + generates a contextual reply. Cost: LLM API + $0.015 per posted reply ($0.200 if the reply contains a URL).
Community-engagement bot: reply to topic-matching tweets with helpful resources. Careful — this is where spam-detection risk lives.
Threaded content series: post the first tweet, then chain replies to build a thread. Same call, in_reply_to_tweet_id points to your own previous tweet.
Cross-reference reply: reply to a viral tweet with a related resource or contribution. Manual triggering + programmatic posting is cleaner than fully-automated content routing.
Side-by-side — 3 reply-related endpoints
All three use the same endpoint on each route; the in_reply_to_tweet_id field (reply_to_tweet_id on TwitterAPI.io) determines which behavior.
What NOT to do
Mass identical replies: X's spam detection catches identical or near-identical replies posted across many targets. Vary meaningfully.
Reply-bombing: replying to every tweet from a target account gets you rate-limited + potentially suspended.
Political manipulation: automated replies pushing political / commercial agendas are explicitly against X's civic-integrity + platform-manipulation policies. Suspension likely + you lose the account entirely.
Fake-persona reply farms: coordinated inauthentic behavior (multiple accounts posting coordinated replies) violates X's authenticity policy. Multi-account suspension likely.
# Practical example: AI reply agent — monitor mentions + LLM-generate reply + post.
import os, time, random
import tweepy
# from your llm client import client as llm_client
x_client = tweepy.Client(
consumer_key=os.environ["X_CONSUMER_KEY"],
consumer_secret=os.environ["X_CONSUMER_SECRET"],
access_token=os.environ["X_USER_TOKEN"],
access_token_secret=os.environ["X_USER_SECRET"],
)
def generate_reply(target_text: str) -> str:
"""Illustrative — call your LLM of choice with a reply-generation prompt."""
return f"Interesting take — worth considering that {target_text[:60]}..."
def process_mention(mention):
target_id = mention["id"]
target_text = mention["text"]
reply_text = generate_reply(target_text)
if len(reply_text) > 280:
reply_text = reply_text[:277] + "..."
try:
resp = x_client.create_tweet(text=reply_text, in_reply_to_tweet_id=target_id)
print(f"replied to {target_id}: {resp.data['id']}")
except tweepy.TooManyRequests:
time.sleep(60)
# Poll mentions loop (illustrative)
mentions = [] # populated from twitterapi.io mentions endpoint or X official
for m in mentions:
process_mention(m)
time.sleep(1.5 + random.uniform(0.1, 0.5))
# Cost per docs.x.com pricing:
# ~50 replies/day × $0.015 = $0.75/day = ~$22.50/month for the reply-write cost
# LLM cost + mention-read cost separate. On the read side (mention monitoring via twitterapi.io) cost stays ~33× below X official self-serve read pricing per docs.x.com — that's where the cost delta lives for reply workloadsResearching this?Free starter credits cover end-to-end testing — Google sign-in, no card. Get a key.
Questions readers ask
Can I reply from twitterapi.io?
Yes. POST /twitter/create_tweet_v2 with reply_to_tweet_id posts a reply for $0.0006 per call, against $0.015 on the official API (Post: Create). It needs login_cookies from one POST /twitter/user_login_v2 login ($0.10, one per session) and a proxy you supply. The reply is made as your own X account, so the conditions in the second-route section above apply. The read side (mentions monitoring, target-tweet lookup) needs only an API key.
How do I get the tweet ID I want to reply to?
The tweet URL contains it: https://x.com/user/status/<tweet_id>. The ID is the numeric string. Programmatically: from /twitter/user/mentions or /twitter/tweet/advanced_search responses, use the id field.
Can I attach media to a reply?
Yes — same media_ids parameter as a regular tweet. Upload media first via the media upload endpoint, then include the returned IDs in the reply POST.
What if my reply is over 280 chars?
The POST fails. Truncate client-side before sending. Some AI reply agents run the generated text through a length-check + retry with a shorter prompt if over.
Can I edit a reply after posting?
No native edit for replies via API. If you need to correct, delete the reply and post a fresh one. Delete: client.delete_tweet(id=<reply_id>).
How do I detect if my reply was flagged / hidden by the target author?
Authors can hide specific replies. Detection via API: check the reply status endpoint. Hidden replies remain in the API response but with a flag. Poll periodically if the flag matters for your workflow.
Continue
- X API — pricing (docs.x.com, 2026 verified)
- X — Post and delete posts quickstart
- Tweepy documentation
- twitterapi.io — pricing
- Twitter (X) API — cluster hub
- How to make a Twitter (X) thread via API
- Twitter (X) templates — API bulk post
- Twitter (X) scheduling tool API integration
- Rate limit exceeded on Twitter (X) — fixes
- twitterapi.io pricing
- How to see comments (replies) on X, and why some are missing
- 01Zapier Pricing in 2026: Plans, Tasks per Month, Overage and a Worked Twitter (X) Zap Bill
- 02LlamaIndex vs LangChain: Which to Use, With the Same Twitter (X) RAG Pipeline Built in Both
- 03Agentic Payments: How AI Agents Pay, and Which Protocol Does What
- 04Kiro Pricing in 2026: Plans, Credits, Model Multipliers and Worked Monthly Bills
- 05Cline vs Cursor in 2026: Cost, Models, Plan/Act and MCP Compared
- 06Count Tweets — Twitter (X) API Programmatic Guide
- 07How to Make a Twitter (X) Thread via API — Developer Tutorial
- 08Twitter (X) API — Search Hashtags Tutorial
Writing about something you built with TwitterAPI.io? Our community rewards program pays API credits for honest tutorials, build logs and videos.
Stop reading. Start building.
Starter credits cover real testing on real data. Google sign-in, no card, no application queue.
Get an API keyAlready building with TwitterAPI.io? Publish an honest tutorial or build log about it and earn up to $200 a month in API credits.