Instagram Live - API Cheat Sheet
Reading duration: 12 mins
A concise, technical cheat sheet covering Instagram Live APIs, including how to detect live broadcasts, pull playback URLs, record streams, and collect comments, likes, and viewer counts.
Quick overview
- Goal: detect a user going live, pull stream URLs, and record while collecting comments, likes, and viewer count.
- Core concept: every live has a
broadcast_id. Use it to query info, heartbeat, comments, likes, and replay data. - Most calls require an authenticated mobile/web session. Keep cookies,
csrftoken, anduuidvalid.
Endpoints seen
| Method | Endpoint | Purpose | Key params |
|---|---|---|---|
| Helper | user_story_feed(user_id) | Returns story feed which may include broadcast if the user is live | user_id |
| Helper | user_broadcast(user_id) | Convenience wrapper over user_story_feed to fetch current broadcast | user_id |
| POST | live/{broadcast_id}/like/ | Send 1 to 5 likes | user_like_count in [1..5] |
| GET | live/{broadcast_id}/get_like_count/ | Get like count since like_ts | like_ts (epoch seconds) |
| GET | live/{broadcast_id}/get_comment/ | Fetch latest comments since last_comment_ts | last_comment_ts (epoch seconds) |
| POST | live/{broadcast_id}/heartbeat_and_get_viewer_count/ | Heartbeat and viewer count | _csrftoken, _uuid, unsigned=True |
| POST | live/{broadcast_id}/comment/ | Post a live comment | comment_text, user_breadcrumb, idempotence_token, live_or_vod=1, offset_to_video_start=0 |
| GET | live/{broadcast_id}/info/ | Broadcast metadata + playback URLs | None |
| GET | live/get_suggested_broadcasts/ | Suggested broadcasts | Optional query filters |
| GET | live/{broadcast_id}/get_post_live_comments/ | Comments for replay VOD | starting_offset, encoding_tag (default instagram_dash_remuxed) |
| GET | live/{broadcast_id}/get_post_live_likes/ | Likes for replay VOD | starting_offset, encoding_tag |
Notes
like_countmust be in 1..5 or or the mixin raisesValueError occurs.broadcast_statusvalues observed ininfo:active,interrupted,stopped,hard_stop.
Typical live record flow
- Discover a live
- Given a user numeric
user_id, calluser_broadcast(user_id). - If present, extract
broadcast_id. - Get playback URLs
- Call
broadcast_info(broadcast_id)to retrieve fields likedash_playback_url(MPD) andrtmp_playback_url. - Start recording
- Prefer
dash_playback_urlfor adaptive MPEG-DASH. - Maintain session
- Poll
broadcast_heartbeat_and_viewercount(broadcast_id)every 5 to 10 seconds to keep the session fresh and trackviewer_count. - Ingest chat and likes
- Loop
broadcast_comments(broadcast_id, last_comment_ts)and persist the largestcreated_atas the nextlast_comment_ts. - Periodically query
broadcast_like_count(broadcast_id, like_ts)and advancelike_ts. - Detect end of stream
broadcast_infoor heartbeat will stop returningactive. Close capture and finalize file.- Replay data (optional)
- For post-live, use
replay_broadcast_commentsandreplay_broadcast_likeswithstarting_offsetto reconstruct engagement alongside VOD.
Minimal example pseudocode
user_id = ...
broadcast = api.user_broadcast(user_id)
if not broadcast:
return # not live
bid = str(broadcast["id"]) # broadcast_id
info = api.broadcast_info(bid)
mpd = info.get("dash_playback_url")
# start ffmpeg recording in a subprocess
start_ffmpeg(mpd, out_path)
last_comment_ts = 0
like_ts = 0
while is_running():
# heartbeat + viewer count
hb = api.broadcast_heartbeat_and_viewercount(bid)
# comments
comments = api.broadcast_comments(bid, last_comment_ts)
for c in comments.get("comments", []):
save_comment(c)
last_comment_ts = max(last_comment_ts, c.get("created_at", 0))
# likes
likes = api.broadcast_like_count(bid, like_ts)
like_ts = likes.get("like_ts", like_ts)
# status check
info = api.broadcast_info(bid)
if info.get("broadcast_status") != "active":
break
sleep(7)
stop_ffmpeg()Example broadcast_info data
{
"status": "ok",
"broadcast_status": "active",
"media_id": "123...",
"cover_frame_url": "https://...jpg",
"broadcast_owner": {
"username": "abc",
"pk": 123456789,
"is_verified": true,
"is_private": false
},
"dash_playback_url": "https://.../something.mpd",
"rtmp_playback_url": "rtmp://.../live-hd/...",
"id": 178591123456789,
"viewer_count": 9000.0
}Error handling
- 403 → bad/expired auth. Refresh session.
- 404 → comments/likes unavailable (broadcast ended). Use replay endpoints.
- Heartbeat requires
_csrftokenand_uuideven withunsigned=True.
Recommended reads
Reverse Engineering Douyin’s ttwid: Understanding ByteDance’s Client Authentication
A deep dive into Douyin’s ttwid authentication cookie — exploring its structure, how it’s issued by ByteDance’s servers, and what it reveals about modern web client verification.
Instagram Live - API Cheat Sheet
A concise, technical cheat sheet covering Instagram Live APIs, including how to detect live broadcasts, pull playback URLs, record streams, and collect comments, likes, and viewer counts.