# Build an Instagram follow tracker app (API)

> To build an Instagram follow tracker, call GET /v1/users/{user}/following and /followers on a schedule. Both lists come back newest first, so the top rows are the new follows. Architecture, cost per tracked account and code.

**Short answer:** an Instagram follow tracker needs two calls, `GET /v1/users/{user}/following` and `GET /v1/users/{user}/followers`, made on a schedule. The Klupt API returns both lists in **real newest-first order** (`position: 1` is the most recent follow), so the first page of each list is all a tracker has to read, and anything at the top that was not there last time is new.

> **Definition:** a follow tracker (or recent-follows tracker) is an app that shows which accounts a public Instagram profile followed most recently, and which accounts followed it most recently, and tells its users when the top of either list changes.

## The two calls

| Call (`GET /v1…`) | Rows a page | Credits | Shows |
|---|---|---|---|
| `/users/{user}/following` | ~200 | 2 | Who the profile followed most recently |
| `/users/{user}/followers` | 25 | 1 | Who most recently followed the profile |
| `/users/by-username/{name}` | 1 | 1 | Once per profile: its id, name and counts |

Cached answers cost nothing, and live data is cached for 60 seconds, so two of your users opening the same profile within a minute cost one call. Failed calls are not billed.

```bash
curl "https://api.klupt.io/v1/users/natgeo/following" \
  -H "X-Api-Key: $KLUPT_API_KEY"
```

```python
import os, requests

H = {"X-Api-Key": os.environ["KLUPT_API_KEY"]}
following = requests.get("https://api.klupt.io/v1/users/natgeo/following", headers=H, timeout=30).json()
followers = requests.get("https://api.klupt.io/v1/users/natgeo/followers", headers=H, timeout=30).json()
print("Followed most recently:", [r["username"] for r in following["data"][:5]])
print("Newest followers:", [r["username"] for r in followers["data"][:5]])
```

```javascript
const headers = { "X-Api-Key": process.env.KLUPT_API_KEY };
const get = (path) => fetch(`https://api.klupt.io/v1${path}`, { headers }).then((r) => r.json());
const [following, followers] = await Promise.all([
  get("/users/natgeo/following"),
  get("/users/natgeo/followers"),
]);
console.log(following.data.slice(0, 5).map((r) => r.username));
console.log(followers.data.slice(0, 5).map((r) => r.username));
```

```php
$ch = curl_init("https://api.klupt.io/v1/users/natgeo/following");
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => ["X-Api-Key: " . getenv("KLUPT_API_KEY")],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = json_decode(curl_exec($ch), true);
print_r($body["data"]);
```

```go
req, _ := http.NewRequest("GET", "https://api.klupt.io/v1/users/natgeo/following", nil)
req.Header.Set("X-Api-Key", os.Getenv("KLUPT_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()
var body map[string]any
json.NewDecoder(res.Body).Decode(&body)
fmt.Println(body["data"])
```

## How a tracker is put together

1. **Add a profile.** Look the username up once with `GET /v1/users/by-username/{username}` and store the numeric `id`. Send the id from then on: a username we have to look up costs 1 extra credit per call.
2. **Check on a schedule.** A worker reads the first page of `following` and `followers` for each tracked profile, for example once an hour. Check a busy profile more often and a quiet one less often.
3. **Compare with the last check.** Rows at the top that were not in your last snapshot are new. Stop at the first row you already know. The details are in [Detect new followers](/docs/detect-new-instagram-followers-api).
4. **Show the list newest first.** Keep the API's order. There is nothing to sort and no follow date to guess, because Instagram does not publish follow dates.
5. **Keep the key on your server.** The browser or mobile app calls your backend, and only the backend calls the Klupt API ([Build with AI tools](/docs/build-with-ai) has a ready server route).

A server route for step 5, in Node.js:

```javascript
import express from "express";

const app = express();
const LISTS = new Set(["following", "followers"]);

app.get("/api/track/:user/:list", async (req, res) => {
  const { user, list } = req.params;
  if (!LISTS.has(list) || !/^[A-Za-z0-9._]{1,30}$/.test(user)) return res.status(400).end();
  const r = await fetch(`https://api.klupt.io/v1/users/${user}/${list}`, {
    headers: { "X-Api-Key": process.env.KLUPT_API_KEY },
  });
  res.status(r.status).json(await r.json());
});

app.listen(3000);
```

## What a tracked profile costs

One check reads one page of each list: 2 + 1 = **3 credits**. Checked every hour, that is 72 credits a day and 2,160 credits a month, about **$4.32 a month per tracked profile** at the base price of $2.00 per 1,000 credits. Several users tracking the same profile share the same calls, and cached answers cost nothing. Packs and plans are on [Pricing](/pricing).

## A real app built this way

[RecentlyFollowed](https://recentlyfollowed.io) is a front end over exactly these two calls. It checks followers and following every hour, shows the newest first, and went from an empty repo to live, with payments, in one day. It is built and run by the team behind Klupt, so it is our own example, not an independent customer. See [Built on the Klupt API](/customers).

## Rules worth keeping

- **Public accounts only.** A private account answers `403 private_account`, and that call is not billed.
- **A missing row is not an unfollow.** A page can now and then come back one row short. Confirm over several checks before you tell anyone an account left ([Newest-first order](/docs/newest-first-order)).
- **Hidden lists.** Some public profiles hide a list: you get an empty page with `meta.list_hidden: true`. Show "this list is hidden", not "no follows".
- Read the [acceptable-use policy](/docs/acceptable-use): no stalking, harassment or reselling personal data.

## FAQ

### What API do Instagram follow tracker apps use?
Trackers need another account's following and followers lists in order, which the official Instagram Graph API does not return. The Klupt API returns both lists newest first: GET /v1/users/{user}/following and GET /v1/users/{user}/followers, where position 1 is the most recent follow.

### How often should a follow tracker check a profile?
Once an hour is a good default. Live data is cached for 60 seconds, so checking more often than once a minute returns the cached answer, which costs nothing but holds no new rows.

### How much does it cost to track one Instagram account?
About 3 credits per check (one following page plus one followers page). Checked every hour, that is 2,160 credits a month, about $4.32 at the base price of $2.00 per 1,000 credits.

### Do I need the whole following list to see new follows?
No. The lists are newest first, so new follows are always at the top of page one. Read deeper pages only when more new rows arrived since the last check than fit on one page.

### Is there a real app built on this?
Yes. RecentlyFollowed (recentlyfollowed.io) runs on these two calls and checks every hour. It is built and run by the team behind Klupt. See Built on the Klupt API at /customers.
