# Instagram Posts API

> Get a public Instagram account's recent posts as JSON: shortcode, URL, date, type, caption, and like, comment and view counts, with cursor pagination. 1 credit per page.

**Get a public account's recent posts**, newest first: link, date, type (photo, video or carousel), caption, and like, comment and view counts.

```
GET https://api.klupt.io/v1/users/{user}/posts
```

**Cost:** 1 credit per page (0.5 from cache). About 12 posts a page.

## Parameters

| Parameter | In | Description |
|---|---|---|
| `user` | path | Username or numeric user id. |
| `cursor` | query | `pagination.next_cursor` from the previous page. |
| `fresh` | query | `true` skips the cache (full price). |

## Response

```json
{
  "data": [
    {
      "id": "3500000000000000001",
      "shortcode": "C9xYzAbCdEf",
      "url": "https://www.instagram.com/p/C9xYzAbCdEf/",
      "taken_at": "2026-11-27T18:04:11.000Z",
      "media_type": "carousel",
      "caption": "Weekend dump",
      "counts": { "likes": 1204, "comments": 37, "views": null },
      "thumbnail_url": "https://scontent.cdninstagram.com/…"
    }
  ],
  "pagination": { "next_cursor": null, "has_more": false, "page_size": 12 },
  "meta": { "request_id": "req_…", "cached": false, "cache_age_seconds": 0, "credits_charged": 1, "credits_remaining": 26945.5 }
}
```

`counts.views` is set for videos and `null` otherwise. A count Instagram hides comes back as `null`.

## Examples

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

```python
import os, requests
posts = requests.get("https://api.klupt.io/v1/users/natgeo/posts",
                     headers={"X-Api-Key": os.environ["KLUPT_API_KEY"]}, timeout=30).json()["data"]
avg_likes = sum(p["counts"]["likes"] or 0 for p in posts) / max(len(posts), 1)
```

```javascript
const { data: posts } = await (await fetch("https://api.klupt.io/v1/users/natgeo/posts", {
  headers: { "X-Api-Key": process.env.KLUPT_API_KEY },
})).json();
```

## FAQ

### How do I get an Instagram account's latest posts with an API?
Call `GET /v1/users/{username}/posts`. Posts come newest first with URL, date, caption and engagement counts.
