Skip to content

LANGUAGE CLIENTS

TwitterAPIs language clients

TwitterAPIs is a plain REST API, so the client is whatever HTTP library your language already has. There is no package to install and no SDK version to keep current. All 51 endpoints are plain HTTPS with one Authorization header and ordinary query parameters, so a complete client is about fifteen lines. Below is that client, written properly for six languages, ready to paste into your own codebase and own outright.

A working client in six languages

Each tab is a complete, runnable client. It reads the key from an environment variable, sets the Bearer header, builds the query string, checks the status code, and decodes the JSON. Change the endpoint path and the parameters and the same function covers every read endpoint the API serves.

1import os
2import requests
3
4BASE = "https://api.twitterapis.com"
5KEY = os.environ["TWITTERAPIS_KEY"]
6
7session = requests.Session()
8session.headers["Authorization"] = f"Bearer {KEY}"
9
10def get(path, **params):
11 """Call any read endpoint. path is the docs path, e.g. 'user/info'."""
12 res = session.get(f"{BASE}/twitter/{path}", params=params, timeout=30)
13 res.raise_for_status()
14 return res.json()
15
16# Resolve a handle to the permanent numeric user ID
17profile = get("user/info", username="naval")
18print(profile["user"]["id"], profile["user"]["followers_count"])
19
20# Search posts, then page with the returned cursor
21page = get("tweet/advanced_search", query="from:naval min_faves:500")
22for tweet in page["tweets"]:
23 print(tweet["id"], tweet["text"][:80])

Why no package to install

An SDK earns its keep when the protocol underneath it is hard: OAuth dances, token refresh, streaming connections, pagination with inconsistent shapes, retry semantics that differ per endpoint. None of that is true here. Authentication is one static header. Paging is one cursor field you pass back. Every response is JSON with the payload under a named key. A wrapper over that adds a dependency you have to keep current and a layer you have to debug through, and it buys you almost nothing.

The one case where generated code does pay is a large integration in a strongly typed language. The public OpenAPI 3.1 specification covers every endpoint, so a generator will give you typed models for all of them. Both routes are supported and neither is privileged: what we commit to is that the specification and the server agree.

Before you write the client

Get a key first, then confirm it works with a single call. The quickstart takes about a minute end to end, and the API key guide covers where the key comes from. Once a call succeeds, the REST API reference covers the paging model and the error contract, and the ID finder is a fast way to sanity-check a handle before you wire it into a job. For agent workflows, the MCP server is a published npm package and is the one case where you do install something.

Frequently Asked Questions

No, and that is deliberate rather than a gap. Every endpoint is one HTTPS GET or POST with a single Authorization header and ordinary query parameters, so a wrapper would add an install step, a version to keep current, and a layer to debug through, in exchange for saving about eight lines. The clients on this page are those eight lines, written properly, for you to paste into your own codebase and own outright.

Not directly. Those libraries are built against the official X API surface, its endpoints, its auth model and its response shapes, so they cannot be pointed at a different provider by changing a base URL. Replacing one is usually less work than it sounds: the calls you actually use are typically a handful, and each becomes a single function like the ones on this page.

You can, and for a large integration in a typed language it is often the better answer. The specification is public and complete, so a generator gives you typed request and response models for every endpoint without hand-writing them. For a handful of calls the plain client on this page is simpler to read and simpler to debug, which is why it is the default suggestion here.

Send the header Authorization: Bearer YOUR_API_KEY on every request. The API also accepts x-api-key with the same value if that fits your stack better. There is no OAuth handshake, no token refresh, no app registration and no callback URL, because you are calling us rather than calling X, and we hold the X side ourselves.

JSON, with the payload under a named key rather than at the top level. A profile lookup returns an object with a user key, a search returns a tweets array plus a cursor for the next page. The full field list for every endpoint is in the reference documentation and in the public OpenAPI 3.1 specification, which you can also feed to a generator if you would rather have typed models than raw dictionaries.

There is no platform-level rate ceiling to design around, so the retry logic you need is the ordinary kind: retry a 5xx with backoff, do not retry a 4xx, and set a timeout on every call. Cost is per call at $0.0008 for a standard read, so the thing worth engineering is not throttling but deduplication, making sure a retry loop cannot silently bill you twice for a result you already hold.