Instagram data API in Python and JavaScript
Short answer: from Python, call requests.get("https://api.klupt.io/v1/users/{user}/following", headers={"X-Api-Key": key}); from JavaScript or TypeScript, fetch the same URL with the same header. Every response is JSON shaped { data, pagination?, meta }. To read more rows, pass pagination.next_cursor back as ?cursor= until it is null.
fetch (built into Node.js 18 and later) and requests.X-Api-Key header; kd_test_ keys return sample data at no cost and kd_live_ keys return real data.Setup
Keep the key in an environment variable, never in code. Start with a test key from the dashboard: it returns sample data in the live schema, so the same code works when you switch to a live key (Sandbox).
| Python | JavaScript / TypeScript | |
|---|---|---|
| Runtime | Python 3.8+ | Node.js 18+, Deno, Bun, Cloudflare Workers |
| HTTP client | pip install requests | Built-in fetch |
| Key | os.environ["KLUPT_API_KEY"] | process.env.KLUPT_API_KEY |
| Types | Plain dicts | Generate from openapi.json |
First call: a profile
curl "https://api.klupt.io/v1/users/by-username/natgeo" \
-H "X-Api-Key: $KLUPT_API_KEY"Store data.id. Later calls that take {user} accept the numeric id, which skips the 1-credit username lookup.
Paging through a list
Lists such as followers and following are newest first and paged with an opaque cursor. Each page is one billed call, so stop as soon as you have what you need.
def pages(path, max_pages=10):
cursor = None
for _ in range(max_pages):
r = requests.get(f"https://api.klupt.io/v1{path}", params={"cursor": cursor} if cursor else {},
headers={"X-Api-Key": os.environ["KLUPT_API_KEY"]}, timeout=30)
r.raise_for_status()
body = r.json()
yield from body["data"]
cursor = body["pagination"]["next_cursor"]
if not cursor:
break
for row in pages("/users/natgeo/followers", max_pages=2):
print(row["position"], row["username"])Retries
Retry only what can succeed later: 429 (wait for the Retry-After header, in seconds) and 502, 503, 504 (back off). Never retry 401, 402, 403 or 404. Failed calls are not billed, so a retry costs nothing extra until it succeeds.
import time
def get(path, tries=3):
for attempt in range(tries):
r = requests.get(f"https://api.klupt.io/v1{path}", headers={"X-Api-Key": os.environ["KLUPT_API_KEY"]}, timeout=30)
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "1")))
elif r.status_code in (502, 503, 504):
time.sleep(2 ** attempt)
else:
r.raise_for_status()
return r.json()
r.raise_for_status()All error codes: Errors. Speed per plan: Rate limits.
TypeScript types
Generate types for every endpoint from the OpenAPI 3.1 spec, for example with openapi-typescript:
npx openapi-typescript https://api.klupt.io/openapi.json -o klupt-api.d.tsAny OpenAPI generator works the same way for other languages. AI coding tools can read AGENTS.md for the rules and endpoints (Build with AI tools).
Keep the key on the server
The API accepts browser requests for quick tests, but a live key in browser or mobile code is visible to every user, who could spend your credits. Call the API from your backend (a Python view, a Node.js route, a serverless function) and send only the result to the browser.
FAQ
Is there an official Klupt SDK for Python or JavaScript?
Official JavaScript and Python SDKs are coming soon (Python and JavaScript guide). The API is plain HTTPS and JSON with one header, so a few lines of fetch or requests are enough, and the OpenAPI spec generates a typed client in any language.
How do I call the Instagram followers API from Python?
Send GET https://api.klupt.io/v1/users/{user}/followers with requests and the header X-Api-Key. The response's data array holds 25 followers, newest first; pass pagination.next_cursor as ?cursor= for the next page.
How do I call the Instagram following API from JavaScript?
fetch("https://api.klupt.io/v1/users/{user}/following", { headers: { "X-Api-Key": key } }) from server-side code. The response holds about 200 accounts a page, newest first, for 2 credits.
Can I call the API from the browser?
Only with a kd_test_ key, for experiments. A live key in browser code is visible to every visitor, and the response carries a meta.warning when that happens. Use a server route for real traffic.
Updated 2026-11-30 · Markdown · Questions? [email protected]
