import requests
import json
import time
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.mixpeek.com"
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
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}")
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']
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
}
}
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))