Twitter (X) Follower Count — API Tutorial

By Michael Park•3 min read
TL;DR
  • /twitter/user/info?userName=<handle> returns data.followers for any account
  • twitterapi.io: $0.00018 per lookup
  • X official: $0.010 per lookup
  • Ratio ~55× for regular-polling workloads

Follower count is the single most-queried field on any Twitter (X) account — the basic 'how big is this account' number that fuels dashboards, growth tracking, competitive analysis, and journalism. This tutorial walks the two API paths with runnable code + honest cost math.

Pricing references URL-cited to each provider.

Per-lookup cost

$0.00018 (twitterapi.io) vs $0.010 (X official) — ~55× per cited pricing

01 — Section

The simplest call — one endpoint, one field

Both providers return follower count in a profile-lookup endpoint. The field name differs (data.followers on twitterapi.io, public_metrics.followers_count on X official), but it is the same number. Difference is per-result cost + auth.

For high-frequency polling (daily or hourly across many accounts), the per-call cost multiplied by volume decides which path fits.

02 — Section

Path 1 — twitterapi.io

Auth via X-API-Key header. Signup is email-based; no X account required.

Pricing per twitterapi.io/pricing: $0.00018 per lookup.

python
import os, requests

HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
BASE = "https://api.twitterapi.io"

def follower_count(handle: str) -> int:
    r = requests.get(
        f"{BASE}/twitter/user/info",
        headers=HEADERS, params={"userName": handle}, timeout=10,
    )
    r.raise_for_status()
    body = r.json()
    data = body.get("data") or {}
    if body.get("status") != "success" or data.get("unavailable"):
        return 0  # not found, or suspended (data.get("unavailableReason"))
    return data.get("followers", 0)

for h in ["nasa", "github", "vercel"]:
    print(f"  @{h}: {follower_count(h):,} followers")
03 — Section

Path 2 — X official

Auth via bearer token from X Developer Console. Requires X account + Developer Console onboarding.

Pricing per docs.x.com/x-api/getting-started/pricing: $0.010 per profile lookup.

python
# pip install tweepy
import tweepy

client = tweepy.Client(bearer_token="YOUR_X_BEARER")

def follower_count_x(handle: str) -> int:
    user = client.get_user(username=handle, user_fields=["public_metrics"])
    return user.data.public_metrics.get("followers_count", 0)

for h in ["nasa", "github", "vercel"]:
    print(f"  @{h}: {follower_count_x(h):,}")
04 — Section

Side-by-side — 2 paths for follower count

Dimensiontwitterapi.ioX official
Endpoint/twitter/user/info/2/users/by/username/<handle>
Per-result cost$0.00018 (twitterapi.io/pricing)$0.010 (docs.x.com)
AuthX-API-Key headerBearer token (X Dev Console)
Setup frictionemail signupX account + Developer Console
Best forhigh-frequency polling, product dashboardsone-off use on existing X Dev bill

Per-call cost ratio: ~55×. At meaningful polling volumes the delta compounds fast.

05 — Section

Common polling workflows — cost math

Single account, daily check: 30 calls/month. twitterapi.io: $0.0054. X official: $0.30. Ratio: 55×.

Competitive dashboard, 20 accounts, daily: 600 calls/month. twitterapi.io: $0.11. X official: $6.00.

Growth tracking, 100 accounts, hourly: 72,000 calls/month. twitterapi.io: $12.96. X official: $720. Ratio: 55×.

Journalism / research, 1000 accounts, daily: 30,000 calls/month. twitterapi.io: $5.40. X official: $300.

The ratio holds at any volume. Choice depends on setup convenience + existing infrastructure.

06 — Section

Storing follower count over time

Follower count as a scalar isn't useful for growth analysis — you need time series. Store per-lookup as (handle, timestamp, followers_count) rows in your warehouse.

SQL for querying growth-rate: SELECT handle, MAX(followers_count) - MIN(followers_count) AS growth FROM followers WHERE captured_at BETWEEN X AND Y GROUP BY handle.

For dashboards, render the time-series as a line chart. Anomalies (sudden drops = likely purge / suspension; sudden spikes = viral moment) become visible at a glance.

If your warehouse is a spreadsheet, pull follower counts into Google Sheets with Apps Script shows a daily snapshot tab and a cached =TWITTER_FOLLOWERS() custom function.

07 — Section

Follower count vs 'active followers'

Follower count is what accounts follow the target. It's not the same as 'active audience'. Some followers are bots or dormant.

For active-audience estimation, combine follower count with engagement metrics (avg likes / retweets per post from /twitter/user/last_tweets). Engagement-per-1K-followers is a health signal even when raw follower count is stable. To pull the follower list itself rather than the count, use the Twitter followers API (/twitter/user/followers, 200 per page).

Reference: /blog/twitter-engagement-rate-calculator-api for the engagement-rate calculation pattern.

python
# Practical example: daily follower-count snapshot for a watchlist → JSONL time-series.
import os, requests, json
from datetime import datetime, timezone
from pathlib import Path

HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
BASE = "https://api.twitterapi.io"

WATCHLIST = [
    "nasa", "github", "vercel", "anthropic", "openai",
    "elonmusk", "realDonaldTrump", "BarackObama",
]

def snapshot(out_path: str = "followers.jsonl"):
    Path(out_path).parent.mkdir(exist_ok=True)
    now = datetime.now(timezone.utc).isoformat()
    with open(out_path, "a") as f:
        for h in WATCHLIST:
            r = requests.get(f"{BASE}/twitter/user/info", headers=HEADERS, params={"userName": h}, timeout=10)
            r.raise_for_status()
            body = r.json()
            data = body.get("data") or {}
            if body.get("status") != "success" or data.get("unavailable"):
                continue  # not found, or suspended (data.get("unavailableReason"))
            f.write(json.dumps({
                "captured_at": now,
                "handle": h,
                "followers_count": data.get("followers", 0),
            }) + "\n")

snapshot()
# Cost per twitterapi.io/pricing:
#   8 lookups × $0.00018 = $0.00144 per daily snapshot
#   Daily × 30 = ~$0.043/month for the full watchlist time-series
#   Same via X official: ~$2.40/month (55x)

Researching this?Free starter credits cover end-to-end testing — Google sign-in, no card. Get a key.

08 — Questions

Questions readers ask

How current is the follower count returned?

Real-time at query. Both providers reflect the current state per their indexing latency (usually seconds). Follower changes propagate quickly.

Can I get historical follower counts?

Neither API returns historical follower series directly — you have to build the time series by snapshotting periodically. For growth analysis, snapshot daily + query your own store.

What about follower count for accounts I don't follow?

All follower counts on public accounts are visible via the API. No follow relationship required. Only fully-private accounts are gated.

Do bot / spam followers count?

Yes, the count is total-followers including any bots. X occasionally does platform-wide bot purges that drop counts across affected accounts. Track deltas over time — you'll see the purge as a step function.

How do I detect an account being suspended or deleted?

The API returns HTTP 200 and reports it in the body: a deleted handle comes back as status: "error", a suspended one as data.unavailable: true. Handle that in your snapshot script (skip and log) so your time-series has gaps rather than errors.

Rate limits?

twitterapi.io: 20 requests per second once the account has paid, 0.2 before the first payment (see /qps-limits). X official: per-endpoint limits in 15-minute windows (see docs.x.com). For polling at your typical dashboard cadence (hundreds of calls/day) neither is a constraint.

09 — Further reading

Continue

Sources & further reading
More from this series

Writing about something you built with TwitterAPI.io? Our community rewards program pays API credits for honest tutorials, build logs and videos.

Build it

Stop reading. Start building.

Starter credits cover real testing on real data. Google sign-in, no card, no application queue.

Get an API key

Already building with TwitterAPI.io? Publish an honest tutorial or build log about it and earn up to $200 a month in API credits.