Skip to content
Instagram APIPythonTutorialReelsLifetime Credits

Instagram API Python Tutorial — Extract Reels, Stories & Profiles (2026)

October 10, 2026 · 7 min read · By AR Digital Services

In this tutorial, you'll learn how to integrate the Instagram API into your Python project to extract direct MP4 download URLs from Instagram Reels, scrape public profile data, and handle API responses with proper error handling. You need an Instagram API key — every verified account gets 100 free requests, enough to follow this tutorial.

Prerequisites

  • Python 3.8 or higher
  • An Instagram API key — sign up free to get 100 requests
  • The requests library

Install dependencies

pip install requests

Step 1 — Extract a Reel MP4 Download URL

The GET /instagram endpoint accepts any public Instagram Reel or post URL and returns a direct MP4 link:

import requests

API_KEY = "your_api_key"
BASE_URL = "https://api.teraboxdl.site/v1/instagram"

def get_instagram_reel(url: str) -> dict:
    """Direct video URL (and every slide of a carousel) for a reel or post link."""
    response = requests.post(
        f"{BASE_URL}/reel",
        headers={"X-API-Key": API_KEY},
        json={"url": url},
        timeout=30,
    )
    response.raise_for_status()
    return response.json()

# Example usage
result = get_instagram_reel("https://www.instagram.com/reel/DeSX7IaAIUu/")
data = result["data"]
print("MP4 URL:", data["video_url"])
print("Thumbnail:", data["thumbnail"])
print("Caption:", data["caption"])
print("Credits left:", result["credits_remaining"])

Credits are only deducted when the API returns HTTP 200 OK. Private posts and failed extractions consume 0 credits.

Step 2 — Fetch Instagram Profile Data

Use the profile endpoint to extract public user metadata including avatar, bio, and follower counts:

def get_instagram_profile(username: str) -> dict:
    """Public profile details: name, bio, followers, verified badge, avatar."""
    response = requests.get(
        f"{BASE_URL}/profile",
        headers={"X-API-Key": API_KEY},
        params={"username": username},
        timeout=30,
    )
    response.raise_for_status()
    return response.json()

# Example
user = get_instagram_profile("natgeo")["data"]["user"]
print("Followers:", user["stats"]["followers_count"])
print("Bio:", user["biography"])
print("Avatar:", user["profile_pic_url"])

Step 3 — Production Error Handling

Always implement proper error handling for production Telegram bots or automation tools:

import requests

def safe_get_reel(url: str) -> dict | None:
    try:
        result = get_instagram_reel(url)
        return result["data"] if result.get("status") == "success" else None
    except requests.HTTPError as e:
        status = e.response.status_code
        if status == 402:
            print("Out of credits: buy a pack at teraboxapi.com/instagram-api")
        elif status == 401:
            print("Invalid API key")
        elif status == 404:
            print("Post not found, deleted or private (no credit was used)")
        elif status == 429:
            print("Rate limit reached, wait a moment and retry")
        else:
            print(f"HTTP error {status}")
        return None
    except requests.Timeout:
        print("Request timed out, retry")
        return None

Lifetime Credit Model Explained

Unlike monthly Instagram API subscriptions that expire unused credits, the AR Digital Services Instagram API uses lifetime credits:

  • Buy a credit pack once — balance never expires
  • Purchase ₹499 Starter (25K credits) or scale up to ₹14,999 Mega (1M credits)
  • Credits stack — buy more and they add to your balance
  • Zero-waste: credits only deduct on successful HTTP 200 OK responses

Get Your Instagram API Key

Sign up free: 100 requests, no card. Start building with the Python code above.

Related Instagram API Guides