Mixpeek Quickstart Guide

There is an interactive version of this guide embedded in your dashboard on the Notebooks page

Getting Started

First, install the required libraries:

pip install requests

import requests
import json
import time

# Replace with your Mixpeek API key
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.mixpeek.com"

headers = {
    'Authorization': f'Bearer {API_KEY}',
    'Content-Type': 'application/json'
}

Indexing and Retrieving Video Data

Step 1: Index and Perform Feature Extraction

Start by indexing a video URL:

url = f"{BASE_URL}/index/url"

payload = json.dumps({
    "url": "https://mixpeek-public-demo.s3.us-east-2.amazonaws.com/starter/aussie_agility.mp4",
    "collection_id": "quickstart",
    "metadata": {
        "hello": "world"
    }
    "video_settings": [{
        "interval_sec": 10,
        "read": {"model_id": "video-descriptor-v1"},
        "embed": {"model_id": "multimodal-v1"},
        "transcribe": {"model_id": "polyglot-v1"},
        "describe": {
            "model_id": "video-descriptor-v1",
            "prompt": "Create a holistic description of the video, include sounds and screenplay"
        },
        "json_output": {
            "response_shape": {"emotions": ["str"]},
            "prompt": "This is a list of emotion labels, each one should be a string representing the scene."
        }
    }]
})

response = requests.post(url, headers=headers, data=payload)
task_id = response.json()['task_id']
print(f"Indexing started. Task ID: {task_id}")

Step 2: Wait for Task Completion

Wait for the indexing task to complete:

def check_task_status(task_id):
    url = f"{BASE_URL}/tasks/{task_id}"
    response = requests.get(url, headers=headers)
    return response.json()['status']

while True:
    status = check_task_status(task_id)
    print(f"Current task status: {status}")
    if status == 'DONE':
        break
    time.sleep(2)

asset_id = response.json()['asset_id']

Step 3: Retrieve Full File Properties

Once the indexing is complete, retrieve the fully extracted video data:

url = f"{BASE_URL}/assets/{asset_id}/features"

response = requests.get(url, headers=headers)
asstet_data = response.json()
print(json.dumps(asstet_data, indent=2))
{
    "video_segments": [
        {
            "start_time": 10.0,
            "end_time": 20.0,
            "interval_sec": 10,
            "transcription": "0:10 Can't lose weight. She might have high cortisol levels. 0:15 Neck, shoulder, and back tension. Often due to \"fight or flight\" stress response. 0:19 Procrastination is a freeze response to trauma. \n",
            "text": "CORTISOL DETOX\nSomatic Yoga challenge\n",
            "description": "The video starts with a still image ...",
            "json_output": {
                "emotions": [
                    "neutral"
                ]
            }
        },
    ],
    "pagination": {
        "total": 12,
        "page": 1,
        "page_size": 10,
        "total_pages": 2,
        "next_page": "https://api.mixpeek.com/assets/198dacbb-c7d2-41c3-b008-83ea41b29c31?page=2&page_size=10",
        "previous_page": null
    }
}

Searching Indexed Content

With your video indexed, you can now perform text-based searches across your collection:

url = f"{BASE_URL}/features/search/text"

payload = json.dumps({
    "query": "dog jumping",
    "collection_ids": ["quickstart"],
    "filters": {
        "AND": [
            {
                "key": "metadata.hello",
                "value": "world",
                "operator": "eq"
            }
        ]
    },
    "model_id": "multimodal-v1",
    "search_type": "semantic"
})

response = requests.post(url, headers=headers, data=payload)
search_results = response.json()
print(json.dumps(search_results, indent=2))

Next Steps