Open Instagram API
Provides tools for interacting with Instagram on the user's behalf: listing, reading, and sending DMs; browsing profiles, posts, reels, stories, hashtags, and locations; liking, saving, commenting, and following; publishing image posts and carousels; managing account settings; and receiving realtime DM events.
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
Export your instagram.com cookies to
cookies.json(export while logged in; keep that browser logged in). Check the file withpython3 check_cookies.py cookies.json.Install and run:
pip install -r requirements.txt
python3 server.pyThe 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 itAdd ?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 / disconnectedcurl -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 runningThen 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.pyauto-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.pyturns 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 toolsaccept_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_commentBDestructive
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_commentsCRead-only
Comments on a post or reel.
Inputs: shortcode (required), sort, cursor.
get_feedCRead-only
Your home feed, reels feed or explore page.
Inputs: feed, cursor.
get_followersCRead-only
Who follows a user (which="followers") or whom they follow (which="following").
Inputs: username (required), count, which, cursor.
get_friendshipBRead-only
Your relationship with a user: following, followed_by, requested, etc.
Inputs: username (required).
get_hashtagCRead-only
Posts for a hashtag (without the #).
Inputs: tag (required).
get_my_accountBRead-only
Your own profile settings: username, name, bio, privacy, profile photo.
Inputs: no named parameters.
get_new_messagesARead-only
Incoming messages newer than since_ms (epoch milliseconds). Use the newest timestamp_ms you've seen.
Inputs: since_ms.
get_notificationsBRead-only
Your activity feed: likes, comments, follows, mentions.
Inputs: no named parameters.
get_postBRead-only
One post or reel: caption, media URLs, author, like and comment counts.
Inputs: shortcode (required).
get_profileCRead-only
A user's profile: name, bio, follower counts, privacy, etc.
Inputs: username (required).
get_user_postsCRead-only
A user's posts, newest first (count 6-50).
Inputs: username (required), count, cursor.
get_user_reelsCRead-only
A user's reels, newest first.
Inputs: username (required), count, cursor.
get_user_storiesBRead-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_threadsARead-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_postADestructive
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_messagesARead-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.
searchCRead-only
Search Instagram for users, hashtags and places.
Inputs: query (required).
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).
unread_threadsARead-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_messageBDestructive
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_messagesARead-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
Scored across 33 tools
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.
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.
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.
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
Related MCP Connectors
Instagram data over MCP: profiles, posts, reels, stories, highlights and search as JSON
Hosted Instagram MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Hosted MCP server for DataLikers — Instagram & TikTok data API. 51 tools: Instagram user search by demographics (gender/age/race/country/city), profiles, bulk lookup, engagement, posts & reels, comments, hashtags, locations, stories, highlights, music, business accounts, top users; TikTok users, videos, comments, hashtags, playlists and top charts. Streamable HTTP, Bearer API key. Free tier: 100 requests on signup at https://datalikers.com/p/1by27bwg
Instagram MCP for DM and comment automation, AI Agent and content publishing via Meta's official API
Related MCP Servers
- AlicenseBqualityBmaintenancePersonal Instagram Library — a read-only local MCP server that turns your Instagram saved posts into a private, AI-searchable knowledge base.517 PyPI2MIT
- AlicenseNot gradedqualityBmaintenanceThin 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
- AlicenseBqualityBmaintenanceSelf-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.42MIT
- AlicenseBqualityBmaintenanceSelf-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.122MIT