Skip to main content
Glama
Open Instagram API

Open Instagram API

Open Instagram API

A self-hosted HTTP API for Instagram, reverse-engineered from the Instagram website.

Unofficial and not affiliated with Instagram or Meta. Automating an account can get it restricted, so try it on a test account first.

Setup

  1. Export your instagram.com cookies to cookies.json (export while logged in; keep that browser logged in). Check the file with python3 check_cookies.py cookies.json.

  2. Install and run:

pip install -r requirements.txt
python3 server.py

The API runs at http://127.0.0.1:8765. Send the token from api_token as Authorization: Bearer <token>.

The scripts in tools/ (for capturing new requests from the website) also need pip install -r requirements-tools.txt.

Related MCP server: jorgex-social-mcp

Endpoints

Messages
GET    /threads                              list chats (?folder=requests for message requests)
GET    /threads/{id}/messages                read messages (?cursor= for older ones)
POST   /threads/{id}/messages                send {"text": "hi"}
POST   /threads/{id}/photos                  send a photo (multipart: file)
DELETE /threads/{id}/messages/{mid}          unsend
POST   /threads/{id}/messages/{mid}/reactions   react {"emoji": "❤"}   (DELETE to remove)
POST   /threads/{id}/seen                    mark as seen
POST   /threads/{id}/accept                  accept a message request
GET    /updates?since_ms=0                   new incoming messages

Browsing
GET    /search?q=nasa                        users, hashtags, places
GET    /users/{username}                     profile
GET    /users/{username}/posts               posts (?cursor= for the next page)
GET    /users/{username}/reels               reels
GET    /users/{username}/tagged              tagged posts
GET    /users/{username}/stories             live stories
GET    /users/{username}/highlights          highlights   ->  GET /highlights/{id}
GET    /users/{username}/followers           followers (also /following)
GET    /users/{username}/friendship          follow status
GET    /media/{shortcode}                    post or reel
GET    /media/{shortcode}/comments           comments     ->  GET /comments/{pk}/replies
GET    /media/{shortcode}/likers             likers
GET    /feed/timeline                        home feed (also /feed/reels, /feed/explore)
GET    /stories/tray                         stories from people you follow
GET    /tags/{tag}                           hashtag posts
GET    /locations/{id}                       location posts
GET    /notifications                        activity
GET    /saved                                saved collections

Actions
POST   /media/{shortcode}/like               like (DELETE to unlike)
POST   /media/{shortcode}/save               save (DELETE to unsave)
POST   /users/{username}/follow              follow (DELETE to unfollow)
POST   /media/{shortcode}/comments           comment {"text": "nice"}
DELETE /media/{shortcode}/comments/{pk}      delete a comment
POST   /media/{shortcode}/share              send a post/reel to a chat {"thread_id": "..."} or {"users": ["name"]}

Publishing and account
POST   /media                                post 1 image, or 2-10 as a carousel (multipart: files, caption)
PATCH  /media/{shortcode}                    edit caption {"caption": "..."}
GET    /account                              your profile settings
PATCH  /account                              edit {"biography", "first_name", "username"}
PUT    /account/privacy                      {"private": true}
PUT    /account/photo                        set the profile photo (multipart: file; cropped to a square)
DELETE /account/photo                        remove it

Add ?raw=1 to read endpoints to get Instagram's response untouched.

Realtime

GET    /events                               live DM events (Server-Sent Events), new messages in ~0.5 s
GET    /events/status                        connected / disconnected
curl -N -H "Authorization: Bearer $TOKEN" localhost:8765/events
data: {"type": "message", "message": {"id": "...", "kind": "reel", "text": null, "thread_fbid": "...", ...}}

The server holds one connection to Instagram's own realtime gateway (the WebSocket instagram.com listens on) and reconnects by itself.

Not supported: blocking/restricting, deleting posts, publishing reels, stories and highlights, editing or muting messages. Instagram only accepts these from its own website code or app, not from a script. See docs/PROTOCOL.md.

Staying up to date

Instagram changes its website often, and that can break endpoints. A health check runs every endpoint against a test account each day; when something breaks, a fix is made and pushed here, usually the same day. If an endpoint starts failing, pull the latest version (git pull) and restart the server.

Use it from an AI agent

The repository ships a skill that teaches Claude Code, OpenClaw and other agents how to use this API (skills/open-instagram-api/SKILL.md).

/plugin install open-instagram-api --marketplace cprite/open-instagram-api   # Claude Code
openclaw skills install @cprite/open-instagram-api                           # OpenClaw (ClawHub)
npx skills add cprite/open-instagram-api                                     # any agent (skills.sh)

MCP server

mcp_server.py gives MCP apps (Claude Desktop, Claude Code, Cursor and others) 33 tools on top of the API: chats and messages, waiting for new DMs in realtime, profiles, posts, comments, likes, follows, sharing and publishing. Tools that can't be undone are marked as destructive, so the app asks before using them. The HTTP API keeps working as before; the MCP server is an optional extra that calls it.

pip install -r requirements-mcp.txt
python3 server.py                     # the API must be running

Then add it to your MCP app's config:

{"mcpServers": {"instagram": {"command": "python3", "args": ["/path/to/open-instagram-api/mcp_server.py"]}}}

It reads the token from api_token in the repository folder. IGDM_API and IGDM_TOKEN override the address and token.

Examples

  • examples/reel_autoreply.py auto-replies to reels while you're busy, about a second after they arrive.

  • examples/gpt_command.py: write /gpt <question> in any chat and a short answer from Codex appears there. It sees the recent chat and searches the web when needed.

  • examples/traffic_light_pfp.py turns your profile photo red while you're busy, yellow in between and green when you're free, on a schedule. It can make the three colour versions from your current photo.

License

MIT

Available Tools

33 tools
accept_requestB

Accept a message request, moving the chat to the inbox.

Inputs: thread_id (required).

comment_on_postB

Write a comment on a post or reel. Returns the comment's id (comment_pk).

Inputs: text (required), shortcode (required).

delete_commentB
Destructive

Delete one of your comments.

Inputs: shortcode (required), comment_pk (required).

follow_userA

Follow a user, or unfollow them (unfollow=True).

Inputs: username (required), unfollow.

get_commentsC
Read-only

Comments on a post or reel.

Inputs: shortcode (required), sort, cursor.

get_feedC
Read-only

Your home feed, reels feed or explore page.

Inputs: feed, cursor.

get_followersC
Read-only

Who follows a user (which="followers") or whom they follow (which="following").

Inputs: username (required), count, which, cursor.

get_friendshipB
Read-only

Your relationship with a user: following, followed_by, requested, etc.

Inputs: username (required).

get_hashtagC
Read-only

Posts for a hashtag (without the #).

Inputs: tag (required).

get_my_accountB
Read-only

Your own profile settings: username, name, bio, privacy, profile photo.

Inputs: no named parameters.

get_new_messagesA
Read-only

Incoming messages newer than since_ms (epoch milliseconds). Use the newest timestamp_ms you've seen.

Inputs: since_ms.

get_notificationsB
Read-only

Your activity feed: likes, comments, follows, mentions.

Inputs: no named parameters.

get_postB
Read-only

One post or reel: caption, media URLs, author, like and comment counts.

Inputs: shortcode (required).

get_profileC
Read-only

A user's profile: name, bio, follower counts, privacy, etc.

Inputs: username (required).

get_user_postsC
Read-only

A user's posts, newest first (count 6-50).

Inputs: username (required), count, cursor.

get_user_reelsC
Read-only

A user's reels, newest first.

Inputs: username (required), count, cursor.

get_user_storiesB
Read-only

A user's current stories (empty if none are live).

Inputs: username (required).

like_postA

Like a post or reel, or remove the like (unlike=True).

Inputs: shortcode (required), unlike.

list_threadsA
Read-only

List DM chats (newest first). folder="requests" lists message requests from people you don't follow.

Inputs: folder.

mark_seenB

Mark a chat as seen (the sender sees "Seen").

Inputs: thread_id (required).

publish_postA
Destructive

Publish a photo post (1 image) or carousel (2-10 images) from files on this machine. PERMANENT: posts can't be deleted through the API. Confirm with the user first.

Inputs: image_paths (required), caption.

react_to_messageB

React to a message with an emoji, or remove your reaction (remove=True).

Inputs: thread_id (required), message_id (required), emoji, remove.

read_messagesA
Read-only

Read the newest messages of a chat (about 20). Pass next_cursor as cursor for older ones.

Inputs: thread_id (required), cursor.

save_postA

Save a post to your saved items, or remove it (unsave=True).

Inputs: shortcode (required), unsave.

send_messageB

Send a text message to a chat, optionally as a reply to one of its messages.

Inputs: text (required), thread_id (required), reply_to_message_id.

send_photoB

Send an image file (path on this machine) to a chat.

Inputs: path (required), thread_id (required).

set_profile_photoA

Set your profile photo from an image file (it's centre-cropped to a square).

Inputs: path (required).

share_postB

Send a post or reel into a chat (thread_id) or to people by username.

Inputs: shortcode (required), thread_id, usernames.

unread_threadsA
Read-only

Chats whose newest message wasn't sent by you, i.e. ones waiting for a reply (inbox and requests).

Inputs: no named parameters.

unsend_messageB
Destructive

Unsend (delete for everyone) one of your own messages.

Inputs: thread_id (required), message_id (required).

update_profileA

Change your bio and/or display name. Fields you leave out stay as they are.

Inputs: biography, first_name.

wait_for_messagesA
Read-only

Wait for the next incoming DM on the realtime stream (up to seconds, max 300) and return it as soon as it arrives. Your own messages are skipped. timed_out=True means nothing came in.

Inputs: seconds.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 33 tools

    Disambiguation4/5

    Most tools map to a distinct resource+action, and the DM group (list_threads, unread_threads, get_new_messages, wait_for_messages) is separated by clear descriptions of polling vs. realtime vs. inbox listing. Minor overlap remains between get_profile/get_my_account and get_user_posts/get_post, but descriptions disambiguate them well.

    Naming Consistency4/5

    Nearly all tools follow a verb_noun pattern (update_profile, send_message, get_user_posts, like_post, delete_comment, publish_post). A few deviations exist—bare 'search', noun-only 'unread_threads', and verb+adjective 'mark_seen'—but the set is still highly readable and predictable.

    Tool Count3/5

    33 tools is heavy for a single integration and verges on overwhelming, though the broad Instagram domain (DMs, profiles, feed, content actions, account settings) gives most tools a reason to exist. Some consolidation (e.g. separate photo/message senders, multiple message-fetch tools) would tighten the surface.

    Completeness4/5

    Coverage is strong: full DM lifecycle (send, read, react, unsend, accept, seen), profile/social graph, feed/hashtag/search reading, and post interactions. Gaps exist for saved-items listing, story publishing, block/mute, and post deletion (explicitly unsupported), which agents may need to work around.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Personal Instagram Library — a read-only local MCP server that turns your Instagram saved posts into a private, AI-searchable knowledge base.
      5
      17 PyPI
      2
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Thin MCP server that turns each tool into one authenticated call to a self-hosted Instagram REST API, letting an agent schedule and publish posts, take and keep insights snapshots, and reply to comments and DMs by rules within Meta's limits. At startup it reads the API token's permissions and exposes only the tools that token can use.
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Self-hosted MCP server for Instagram creators: publish, schedule, triage comments and DMs, and read insights through Meta's official Instagram API, with approval before every write.
      42
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Self-hosted MCP server and CLI for publishing and scheduling Instagram Reels, photos, carousels and stories through the official Instagram Graph API. Validates and auto-fixes media with ffmpeg, keeps a persistent queue, and lets AI agents read insights and reply to comments.
      12
      2
      MIT