XFlux

Blog/

X/Twitter API Examples: Python and Node.js with XFlux

Copy-paste Python and Node.js examples using a Bearer API key against https://www.xfluxapi.com/api/v1 — profiles, timelines, and search.

Base URL and auth

All examples hit https://www.xfluxapi.com/api/v1. Pass Authorization: Bearer xflux_YOUR_KEY (or X-API-Key). Keys are created on signup; copy once from the welcome screen or create new keys under Dashboard → API Keys.

Successful responses wrap payloads in a data field. Errors return error with HTTP 4xx/5xx. Full reference: /docs/api.

curl (sanity check)

Before wiring SDKs, confirm the key works with curl.

curl -X GET "https://www.xfluxapi.com/api/v1/users/elonmusk" \
  -H "Authorization: Bearer xflux_YOUR_KEY"

curl -G "https://www.xfluxapi.com/api/v1/search" \
  -H "Authorization: Bearer xflux_YOUR_KEY" \
  --data-urlencode "q=fed rate" \
  --data-urlencode "limit=10"

Python (requests)

Install requests if needed. Store the key in an environment variable — never commit it.

import os
import requests

BASE = "https://www.xfluxapi.com/api/v1"
headers = {"Authorization": f"Bearer {os.environ['XFLUX_API_KEY']}"}

# Profile
r = requests.get(f"{BASE}/users/OpenAI", headers=headers, timeout=30)
r.raise_for_status()
print(r.json()["data"]["username"])

# Timeline
r = requests.get(
    f"{BASE}/users/OpenAI/tweets",
    headers=headers,
    params={"limit": 5},
    timeout=30,
)
r.raise_for_status()
for tweet in r.json()["data"]:
    print(tweet["id"], tweet.get("text", "")[:80])

# Search
r = requests.get(
    f"{BASE}/search",
    headers=headers,
    params={"q": "from:OpenAI lang:en", "limit": 5},
    timeout=30,
)
r.raise_for_status()
print(len(r.json()["data"]), "results")

Node.js (fetch)

Node 18+ has global fetch. Same Bearer header pattern.

const BASE = "https://www.xfluxapi.com/api/v1";
const headers = {
  Authorization: `Bearer ${process.env.XFLUX_API_KEY}`,
};

const user = await fetch(`${BASE}/users/OpenAI`, { headers });
if (!user.ok) throw new Error(await user.text());
console.log((await user.json()).data.username);

const q = new URLSearchParams({ q: "fed rate", limit: "5" });
const search = await fetch(`${BASE}/search?${q}`, { headers });
if (!search.ok) throw new Error(await search.text());
console.log((await search.json()).data.length, "results");

Next steps

Longer guides: /docs/guides/python and /docs/guides/nodejs. For always-on account alerts, add monitors and webhooks (/docs/monitors, /docs/webhooks). For agents, install MCP (/mcp).

FAQ

Is there an official Python/Node SDK?
You can call the REST API with any HTTP client. MCP covers agent tooling; thin REST examples are enough for most scripts.
What is the rate limit / quota?
Monthly call quotas by plan (Free 1,000; Starter 150K; higher tiers more). See /docs/limits and /pricing.
Can I post tweets with these examples?
Write/post endpoints are not the product focus (posting marked coming soon). Use XFlux for reads, search, monitors, and webhooks.
Where do I get a key?
Register at /register — a Default key is created automatically. No credit card on Free.

Build with XFlux

Free tier for reads and one monitor. Starter from $19/mo for signed webhooks and faster polling.

More from the blog

X/Twitter API Examples: Python and Node.js with XFlux | XFlux