### Setup Webhooks for Triggers (Shell Script) Source: https://docs.mosaic.so/overview/webhooks This section provides instructions on configuring webhooks for triggers. It shows a shell script example for sending a POST request to the Mosaic API to set up automatic run notifications. The example includes essential headers for authorization and content type. ```shellscript curl -X POST \"https://api.mosaic.so/webhook/trigger\" \\ -H \"Authorization: Bearer mk_your_api_key\" \\ -H \"Content-Type: application/json\" \\ -d '{\"\nname\\\": \\"My Trigger Webhook\\", \"\nurl\\\": \\"https://your-app.com/webhooks/mosaic/trigger/xyz789abc\\", \"\ntriggers\\\": [ \"video_processing_complete\" ]\n}' ``` -------------------------------- ### Add YouTube Listeners Example Source: https://context7_llms Example code demonstrating how to add YouTube channels to monitor and set a callback URL for an agent. ```APIDOC ## Add YouTube Channels to Monitor Here's how to set up automatic video processing for a YouTube channel: ```python import requests API_KEY = "mk_your_api_key" BASE_URL = "https://api.mosaic.so" AGENT_ID = "{agent_id}" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } # Add YouTube channels to monitor response = requests.post( f"{BASE_URL}/agent/{AGENT_ID}/triggers/lowest_youtube_id/add_listeners", headers=headers, json={ "youtube_channels": [ "https://www.youtube.com/@yourchannel", "UCxxxxxxxxxxxxxx" # Can use channel ID too ], "trigger_callback_url": "https://your-app.com/webhooks/youtube" } ) # Check configured triggers triggers_response = requests.get( f"{BASE_URL}/agent/{AGENT_ID}/triggers", headers=headers ) triggers = triggers_response.json() for trigger in triggers: if trigger["type"] == "youtube": print(f"Monitoring {len(trigger['youtube_channels'])} channels") for channel in trigger["youtube_channels"]: print(f" - {channel}") ``` ### Parameters for `add_listeners` #### Request Body - **youtube_channels** (string[]) - Required - YouTube channel IDs or URLs to monitor. - **trigger_callback_url** (string | null) - Required - Webhook URL for trigger notifications (set to `null` to remove). ``` -------------------------------- ### Webhook Payload Examples (JSON) Source: https://context7_llms These JSON examples illustrate the structure of webhook payloads sent when a trigger detects new content and an agent run starts or completes. They include details about the agent, run, inputs, and how the trigger was activated. ```json { "flag": "RUN_STARTED", "agent_id": "123e4567-e89b-12d3-a456-789012345678", "run_id": "7f8d9c2b-4a6e-8b3f-1d5c-9e2f3a4b5c6d", "status": "running", "inputs": [ { "video_id": "youtube_dQw4w9WgXcQ", "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", "thumbnail_url": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg" } ], "triggered_by": { "id": "8f7d6c5b-4a3e-2b1f-9d8c-1a2b3c4d5e6f", "type": "youtube", "youtube": { "id": "dQw4w9WgXcQ", "channel": "UCxxxxxxxxxxxxxx", "title": "Never Gonna Give You Up", "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" } } } ``` ```json { "flag": "RUN_FINISHED", "agent_id": "123e4567-e89b-12d3-a456-789012345678", "run_id": "7f8d9c2b-4a6e-8b3f-1d5c-9e2f3a4b5c6d", "status": "completed", "inputs": [ { "video_id": "youtube_dQw4w9WgXcQ", "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", "thumbnail_url": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg" } ], "outputs": [ { "video_url": "https://storage.googleapis.com/mosaic-outputs/output.mp4", "thumbnail_url": "https://storage.googleapis.com/mosaic-thumbnails/thumb.jpg" } ], "triggered_by": { "id": "8f7d6c5b-4a3e-2b1f-9d8c-1a2b3c4d5e6f", "type": "youtube", "youtube": { "id": "dQw4w9WgXcQ", "channel": "UCxxxxxxxxxxxxxx", "title": "Never Gonna Give You Up", "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" } } } ``` -------------------------------- ### Starting an Agent Run with Callback URL Source: https://docs.mosaic.so/overview/webhooks This shell script example demonstrates how to initiate an agent run while specifying a callback URL. The `callback_url` parameter is crucial for receiving webhook notifications about the agent's progress or completion. Ensure the provided URL is accessible and configured to handle incoming webhook requests. ```shellscript ng agent start --callback_url "YOUR_CALLBACK_URL_HERE" ``` -------------------------------- ### Complete Python Example for Mosaic Agent Workflow Source: https://docs.mosaic.so/overview/agent-operations This Python code snippet demonstrates a complete workflow for triggering agent processing on Mosaic, starting from a video upload scenario. It includes setting up API credentials and making a request to the Mosaic API. Dependencies include the 'requests' library. ```python import requests import time API_KEY = "mk_your_api_key" BASE_URL = "https://api.mosaic.so" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } def create_agent_run(agent_id, input_data): url = f"{BASE_URL}/v1/agents/{agent_id}/run" payload = { "input": input_data } response = requests.post(url, headers=headers, json=payload) response.raise_for_status() # Raise an exception for bad status codes return response.json() def get_agent_run_status(run_id): url = f"{BASE_URL}/v1/runs/{run_id}" response = requests.get(url, headers=headers) response.raise_for_status() return response.json() if __name__ == "__main__": # Replace with your actual agent ID and input data example_agent_id = "your_agent_id" example_input = { "video_url": "https://www.youtube.com/watch?v=example_video_id" } try: # Create a new agent run print("Creating agent run...") run_result = create_agent_run(example_agent_id, example_input) run_id = run_result['id'] print(f"Agent run created with ID: {run_id}") # Poll for the status of the agent run print("Polling for run status...") while True: status_result = get_agent_run_status(run_id) status = status_result['status'] print(f"Current status: {status}") if status in ["completed", "failed", "cancelled"]: print("Agent run finished.") print("Final result:", status_result) break time.sleep(5) # Wait for 5 seconds before polling again except requests.exceptions.RequestException as e: print(f"An error occurred: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") ``` -------------------------------- ### Install Python Dependencies Source: https://context7_llms Command to install the necessary Python libraries, 'moviepy' and 'requests', for interacting with the Mosaic platform and handling video processing. ```bash pip install moviepy requests ``` -------------------------------- ### RunFinishedWebhook Payload Example - TypeScript Source: https://docs.mosaic.so/overview/webhooks An example of a RunFinishedWebhook payload structure defined in TypeScript. This demonstrates the expected fields and their types for a run completion event, ensuring data consistency. ```typescript type WebhookPayload = RunStartedWebhook | RunFinishedWebhook | TestWebhook; ``` -------------------------------- ### Example Trigger Information Payloads (JSON) Source: https://context7_llms These JSON examples illustrate the structure of trigger information for different trigger types: YouTube, Schedule, and Manual. The structure varies based on the event that initiated the agent run. ```json { "type": "youtube", "channel_id": "UC123456789", "video_id": "dQw4w9WgXcQ", "video_title": "Amazing Video Title", "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", "triggered_at": "2024-01-15T10:30:00Z", "trigger_id": "aba7b810-9dad-11d1-80b4-00c04fd430c8" } ``` ```json { "type": "schedule", "scheduled_at": "2024-01-15T10:30:00Z", "schedule_id": "schedule-uuid", "cron_expression": "0 10 * * *" } ``` ```json { "type": "manual", "source": "api", "user_id": "user-uuid", "triggered_at": "2024-01-15T10:30:00Z" } ``` -------------------------------- ### Setting Up Webhooks for Agent Runs Source: https://context7_llms Configure a callback URL when starting an agent run to receive notifications about its progress and completion. ```APIDOC ## Setting Up Webhooks for Agent Runs Include the `callback_url` when starting an agent run: ```bash curl -X POST "https://api.mosaic.so/agent/[agent_id]/run" \ -H "Authorization: Bearer mk_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "video_ids": ["550e8400-e29b-41d4-a716-446655440000"], "callback_url": "https://your-app.com/webhooks/mosaic/abc123xyz" }' ``` ``` -------------------------------- ### Validating API Key Source: https://context7_llms Verify your API key's validity and retrieve user information by making a GET request to the `/whoami` endpoint. This is recommended for testing authentication setup. ```APIDOC ## Validating Your API Key Use the `/whoami` endpoint to verify your API key is working correctly and get information about the associated user: ```bash curl -X GET "https://api.mosaic.so/whoami" \ -H "Authorization: Bearer mk_your_api_key" ``` ### Response ```json { "user_id": "123e4567-e89b-12d3-a456-789012345678", "email": "user@example.com", "is_admin": false, "api_key_id": "98765432-dcba-4321-abcd-987654321098", "created_at": "2024-01-15T08:00:00Z", "last_used_at": "2024-01-15T14:30:00Z" } ``` This endpoint is useful for: * Verifying your API key is valid and active * Checking which user account the key belongs to * Confirming the key's creation and last usage timestamps * Testing your authentication setup before making other API calls Always test your API key with `/whoami` first when setting up a new integration. This helps catch authentication issues early. ``` -------------------------------- ### Set Up Webhooks for Agent Runs (Bash) Source: https://context7_llms This bash command demonstrates how to start an agent run and include a `callback_url` to receive webhook notifications. It uses `curl` to send a POST request to the Mosaic API. ```bash curl -X POST "https://api.mosaic.so/agent/[agent_id]/run" \ -H "Authorization: Bearer mk_your_api_key" \ -H "Content-Type: application/json" \ -d '{ \ "video_ids": ["550e8400-e29b-41d4-a716-446655440000"], \ "callback_url": "https://your-app.com/webhooks/mosaic/abc123xyz" \ }' ``` -------------------------------- ### JSON Response Example for LLM Operation Source: https://docs.mosaic.so/overview/agent-operations This snippet displays a sample JSON response from the Mosaic LLMs API, detailing the output of a completed operation. It includes fields such as agent ID, start time, status, and input parameters. The structure is typical for asynchronous LLM task results. ```json { "agent_id": "123e4567-e89b-12d3-a456-789012345678", "started_at": "2025-01-10T14:30:00Z", "status": "completed", "inputs": [ { "video_id": "550e8400-e29b-41d4-a716-446655440000", "video_url": "https://storage.googleapis.com/mosaic-inputs/..." } ] } ``` -------------------------------- ### Webhook Payload Example (JSON) Source: https://docs.mosaic.so/overview/triggers This is an example of the JSON payload that would be sent to your configured callback URL when an agent run is triggered by new content. It includes standard agent run information along with a 'triggered_by' field indicating the cause of the webhook. ```json { "agent_id": "agent_1234", "agent_run_id": "run_abcd", "triggered_by": "youtube_new_content", "status": "completed", "created_at": "2023-10-27T10:00:00Z", "outputs": { "summary": "New video from channel X detected.", "links": [ "https://www.youtube.com/watch?v=dQw4w9WgXcQ" ] }, "error": null } ``` -------------------------------- ### Setup YouTube Triggers and Check (Python) Source: https://context7_llms This Python script demonstrates how to use the Mosaic SO API to add YouTube channels for monitoring and set a callback URL for trigger notifications. It also shows how to retrieve and inspect configured triggers for an agent. ```python import requests API_KEY = "mk_your_api_key" BASE_URL = "https://api.mosaic.so" AGENT_ID = "{agent_id}" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } # Add YouTube channels to monitor response = requests.post( f"{BASE_URL}/agent/{AGENT_ID}/triggers/lowest_youtube_id/add_listeners", headers=headers, json={ "youtube_channels": [ "https://www.youtube.com/@yourchannel", "UCxxxxxxxxxxxxxx" # Can use channel ID too ], "trigger_callback_url": "https://your-app.com/webhooks/youtube" } ) # Check configured triggers triggers_response = requests.get( f"{BASE_URL}/agent/{AGENT_ID}/triggers", headers=headers ) triggers = triggers_response.json() for trigger in triggers: if trigger["type"] == "youtube": print(f"Monitoring {len(trigger['youtube_channels'])} channels") for channel in trigger["youtube_channels"]: print(f" - {channel}") ``` -------------------------------- ### Request Header Example: Authorization Source: https://docs.mosaic.so/overview/agent-operations This snippet shows an example of the Authorization header required for API requests. It includes the 'Authorization: Bearer mk_your_api_key' format, which is a common pattern for token-based authentication. ```http -H "Authorization: Bearer mk_your_api_key" ``` -------------------------------- ### Run Agent API Request (cURL) Source: https://docs.mosaic.so/overview/introduction Example cURL command to run an agent using the Mosaic API. It demonstrates the necessary Authorization header with an API key and the Content-Type header. ```shell curl -H "Authorization: Bearer mk_your_key" \ -H "Content-Type: application/json" \ https://api.mosaic.so/agent/[agent_id]/run ``` -------------------------------- ### JSON: Authentication Header Example Source: https://docs.mosaic.so/overview/agent-operations An example of a JSON structure representing authentication details, likely for an API request. It specifies the 'Authorization' header with a 'Bearer' token and an API key. This format is crucial for securing API interactions. ```json { "Authorization": "Bearer f"API_KEY"" } ``` -------------------------------- ### Mosaic API Authentication Example Source: https://docs.mosaic.so/overview/introduction Demonstrates how to authenticate API requests to Mosaic using an API key with the Authorization Bearer header. This is a common pattern for securing API access. ```shellscript curl -H "Authorization: Bearer mk_your_key" \ -H "Content-Type: application/json" \ https://api.mosaic.so/agent/[agent_id]/run ``` -------------------------------- ### Example /whoami API Response Source: https://context7_llms A successful response from the /whoami endpoint provides user identification, email, admin status, API key details, and timestamps for creation and last usage. This JSON structure helps in verifying authentication. ```json { "user_id": "123e4567-e89b-12d3-a456-789012345678", "email": "user@example.com", "is_admin": false, "api_key_id": "98765432-dcba-4321-abcd-987654321098", "created_at": "2024-01-15T08:00:00Z", "last_used_at": "2024-01-15T14:30:00Z" } ``` -------------------------------- ### Validate API Key with Curl Source: https://docs.mosaic.so/overview/introduction This example shows how to use cURL to validate your API key by accessing the '/whoami' endpoint. This helps confirm that your key is working correctly and provides associated user information. ```shellscript curl -H "Authorization: Bearer mk_your_key" \ https://api.mosaic.so/whoami ``` -------------------------------- ### Authenticate API Requests Source: https://context7_llms All API requests require authentication using an API key prefixed with 'mk_'. This example shows how to include the API key in the Authorization header for curl requests. ```bash curl -H "Authorization: Bearer mk_your_api_key" \ https://api.mosaic.so/agent/[agent_id]/run ``` ```bash curl -H "Authorization: Bearer mk_your_api_key" \ https://api.mosaic.so/whoami ``` -------------------------------- ### Example YouTube Trigger Response Source: https://context7_llms Response detailing the YouTube trigger configuration, including a unique ID, trigger type, a list of monitored YouTube channels (by URL or ID), and a callback URL for notifications. ```json { "id": "8f7d6c5b-4a3e-2b1f-9d8c-1a2b3c4d5e6f", "type": "youtube", "youtube_channels": [ "https://www.youtube.com/channel/UCxxxxxx", "https://www.youtube.com/@channelname" ], "callback_url": "https://your-app.com/webhooks/trigger" } ``` -------------------------------- ### Authenticate API Requests with Curl Source: https://docs.mosaic.so/overview/introduction This example demonstrates how to authenticate API requests using cURL. It shows the necessary headers, including the Authorization Bearer token and Content-Type, to interact with the /agent/[agent_id]/run endpoint. ```shellscript curl -H "Authorization: Bearer mk_your_key" \ -H "Content-Type: application/json" \ https://api.mosaic.so/agent/[agent_id]/run ``` -------------------------------- ### Data Structure Example in JavaScript Source: https://docs.mosaic.so/overview/webhooks This JavaScript snippet demonstrates a data structure likely representing event or log data. It includes fields such as video_title, video_url, triggered_at, and trigger_id, with associated styling for presentation. ```javascript const data = _jsxs(_components.div, { children: [ _jsx(_components.span, { style: { color: "#116329", "--shiki-dark": "#9CDCFE" }, children: " \"video_title\"" }), _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: ": " }), _jsx(_components.span, { style: { color: "#0A3069", "--shiki-dark": "#CE9178" }, children: "\"Amazing Video Title\"" }), _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: "," }), "\n", _jsxs(_components.span, { className: "line", children: [ _jsx(_components.span, { style: { color: "#116329", "--shiki-dark": "#9CDCFE" }, children: " \"video_url\"" }), _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: ": " }), _jsx(_components.span, { style: { color: "#0A3069", "--shiki-dark": "#CE9178" }, children: "\"https://www.youtube.com/watch?v=dQw4w9WgXcQ\"" }), _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: "," }) ] }), "\n", _jsxs(_components.span, { className: "line", children: [ _jsx(_components.span, { style: { color: "#116329", "--shiki-dark": "#9CDCFE" }, children: " \"triggered_at\"" }), _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: ": " }), _jsx(_components.span, { style: { color: "#0A3069", "--shiki-dark": "#CE9178" }, children: "\"2024-01-15T10:30:00Z\"" }), _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: "," }) ] }), "\n", _jsxs(_components.span, { className: "line", children: [ _jsx(_components.span, { style: { color: "#116329", "--shiki-dark": "#9CDCFE" }, children: " \"trigger_id\"" }), _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: ": " }), _jsx(_components.span, { style: { color: "#0A3069", "--shiki-dark": "#CE9178" }, children: "\"aba7b810-9dad-11d1-80b4-00c04fd430c8\"" }) ] }), "\n", _jsx(_components.span, { className: "line", children: _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: " }" }) }), "\n", _jsx(_components.span, { className: "line", children: _jsx(_components.span, { style: { color: "#1F2328", "--shiki-dark": "#D4D4D4" }, children: "}" }) }), "\n" ] }); ``` -------------------------------- ### Upload Video to Mosaic API Source: https://context7_llms Python example demonstrating how to upload a video file to the Mosaic API. It requires the 'moviepy' library and handles potential exceptions during the upload process. The function returns a video ID upon successful upload. ```python if __name__ == "__main__": # Install required dependency: pip install moviepy api_key = "mk_your_api_key_here" video_file = "path/to/your/video.mp4" try: video_id = upload_video_to_mosaic(api_key, video_file) if video_id: print(f"✅ Success! Use video_id '{video_id}' in your agent runs") else: print("❌ Upload failed") except Exception as e: print(f"❌ Error: {e}") ``` -------------------------------- ### Setting Up Webhooks for Agent Runs Source: https://docs.mosaic.so/overview/webhooks Instructions on how to specify a callback URL when initiating an agent run. ```APIDOC ## Setting Up Webhooks ### For Agent Runs Include the `callback_url` when starting an agent run: ```shellscript # Example command structure (actual command may vary) python your_script.py --callback_url YOUR_WEBHOOK_URL ``` ``` -------------------------------- ### Get Agent Run Status Request Source: https://docs.mosaic.so/overview/agent-operations Shell command example using curl to fetch the status and output of an agent run using its unique run ID. ```shellscript curl -X GET "https://api.mosaic.so/agent_run/[run_id]" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Fetch Agent Triggers Response with Python Source: https://docs.mosaic.so/overview/triggers This Python code snippet shows how to retrieve trigger responses from an agent using the 'requests' library. It constructs a URL using base URL and agent ID variables and makes a GET request. Ensure that BASE_URL and AGENT_ID are properly defined and that the 'requests' library is installed. ```python # Check configured triggers triggers_response = requests.get("https://your-app.com/webhooks/youtube" # Assuming BASE_URL and AGENT_ID are defined elsewhere # Example: triggers_response = requests.get(f"{BASE_URL}/agent/{AGENT_ID}") ``` -------------------------------- ### Python Complete Workflow Example for Mosaic LLMs Source: https://docs.mosaic.so/overview/agent-operations This Python script demonstrates a full workflow using the Mosaic API, including setting up API keys and base URLs, and making requests. It showcases how to interact with the API for agent processing, likely triggered by an event like a video upload. Dependencies include the 'requests' and 'time' libraries. ```python import requests import time API_KEY = "mk_your_api_key" BASE_URL = "https://api.mosaic.so" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } def create_run(video_url): response = requests.post(f"{BASE_URL}/v1/runs", json={"video_url": video_url}, headers=headers) response.raise_for_status() return response.json() def get_run_status(run_id): response = requests.get(f"{BASE_URL}/v1/runs/{run_id}", headers=headers) response.raise_for_status() return response.json() def main(): video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" # Example video URL print(f"Creating run for video: {video_url}") try: run_data = create_run(video_url) run_id = run_data['id'] print(f"Run created with ID: {run_id}") while True: status_data = get_run_status(run_id) status = status_data['status'] print(f"Current run status: {status}") if status in ["RUN_FINISHED", "RUN_FAILED"]: print(f"Run finished with status: {status}") break time.sleep(5) # Wait for 5 seconds before checking status again except requests.exceptions.RequestException as e: print(f"An error occurred: {e}") if __name__ == "__main__": main() ``` -------------------------------- ### Setup Webhooks for Agent Runs (Shell Script) Source: https://docs.mosaic.so/overview/webhooks This snippet demonstrates how to set up webhooks for agent runs by sending a POST request to the Mosaic API. It includes the agent ID, API key for authentication, and a callback URL for receiving notifications. The request body specifies the video IDs to process and the designated callback URL. ```shellscript curl -X POST \"https://api.mosaic.so/agent/[agent_id]/run\" \\ -H \"Authorization: Bearer mk_your_api_key\" \\ -H \"Content-Type: application/json\" \\ -d '{\"\nvideo_ids\": [\"550e8400-e29b-41d4-a716-446655440000\"],\"\ncallback_url\": \"https://your-app.com/webhooks/mosaic/abc123xyz\"\n}' ``` -------------------------------- ### Get Agent Run Status - GET /agent_run/{run_id} Source: https://docs.mosaic.so/overview/agent-operations This snippet shows how to fetch the status of a specific agent run using a GET request to the /agent_run/{run_id} endpoint. It requires the run ID obtained from initiating an agent. The response provides the current status of the agent run, which can be one of the defined status values. ```javascript async function getAgentRunStatus(runId) { const response = await fetch(`/api/agent_run/${runId}`); if (!response.ok) { throw new Error(`Failed to get agent run status: ${response.statusText}`); } return await response.json(); } ``` -------------------------------- ### Set Up Webhooks for Triggers (Bash) Source: https://context7_llms This bash command shows how to configure webhooks for triggers, enabling notifications for automatic agent runs initiated by events like new YouTube videos. It specifies the `trigger_callback_url` in the request body. ```bash curl -X POST "https://api.mosaic.so/agent/[agent_id]/triggers/lowest_youtube_id/add_listeners" \ -H "Authorization: Bearer mk_your_api_key" \ -H "Content-Type: application/json" \ -d '{ \ "youtube_channels": ["UCxxxxxxxxxxxxxx"], \ "trigger_callback_url": "https://your-app.com/webhooks/triggers/def456uvw" \ }' ``` -------------------------------- ### Python: Upload Video and Run Agent Workflow Source: https://context7_llms This Python script demonstrates a complete workflow for uploading a video to Mosaic, running an agent on it, and then polling for the agent's status. It covers requesting upload URLs, performing the upload, finalizing the upload, initiating the agent run, and continuously checking the run's status until completion or failure. Dependencies include the 'requests' library. It takes an API key and agent ID as input and outputs the status of the agent run and any resulting video URLs. ```python import requests import time API_KEY = "mk_your_api_key" BASE_URL = "https://api.mosaic.so" headers = {"Authorization": f"Bearer {API_KEY}"} # Step 1: Get upload URL and policy fields response = requests.post(f"{BASE_URL}/videos/get_upload_url", headers={**headers, "Content-Type": "application/json"}, json={"filename": "my-video.mp4", "content_type": "video/mp4"}) upload_data = response.json() # Step 2: Upload video with policy fields (multipart form) with open("my-video.mp4", "rb") as video_file: # Build multipart form with policy fields first, then file files = {'file': ('my-video.mp4', video_file, 'video/mp4')} response = requests.post(upload_data["upload_url"], data=upload_data['fields'], # Policy fields files=files) if response.status_code != 204: raise Exception(f"Upload failed with status {response.status_code}") # Step 3: Finalize upload requests.post(f"{BASE_URL}/videos/finalize_upload", headers={**headers, "Content-Type": "application/json"}, json={"video_id": upload_data["video_id"]}) # Step 4: Run agent agent_id = "{agent_id}" run_response = requests.post( f"{BASE_URL}/agent/{agent_id}/run", headers={**headers, "Content-Type": "application/json"}, json={"video_ids": [upload_data["video_id"]]} ) run_id = run_response.json()["run_id"] # Step 5: Poll for status while True: status_response = requests.get(f"{BASE_URL}/agent_run/{run_id}", headers=headers) status_data = status_response.json() if status_data["status"] in ["completed", "failed"]: print(f"Agent run {status_data['status']}") if status_data["status"] == "completed": for output in status_data["outputs"]: print(f"Output video: {output['video_url']}") break time.sleep(5) # Poll every 5 seconds ``` -------------------------------- ### GET /whoami Source: https://docs.mosaic.so/overview/introduction Retrieves information about the currently authenticated user. ```APIDOC ## GET /whoami ### Description This endpoint returns details about the authenticated user, such as their user ID, email, and administrative status. ### Method GET ### Endpoint /whoami ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```bash curl -X GET "https://api.mosaic.so/whoami" \ -H "Authorization: Bearer mk_your_api_key" ``` ### Response #### Success Response (200) - **user_id** (string) - The unique identifier for the user. - **email** (string) - The email address of the user. - **is_admin** (boolean) - Indicates if the user has administrative privileges. - **api_key_id** (string) - The ID of the API key used for authentication. #### Response Example ```json { "user_id": "123e4567-e89b-12d3-a456-789012345678", "email": "user@example.com", "is_admin": false, "api_key_id": "abc123def456" } ``` ``` -------------------------------- ### MDX Component Rendering Setup (JavaScript) Source: https://docs.mosaic.so/overview/triggers This JavaScript code initializes the rendering of MDX components within a Next.js application. It sets up component mapping, including custom components like CodeBlock, Heading, and Note, and ensures all necessary components are provided. ```javascript "use strict";\nconst {Fragment: _Fragment, jsx: _jsx, jsxs: _jsxs} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n code: \"code\",\n hr: \"hr\",\n li: \"li\",\n ol: \"ol\",\n p: \"p\",\n pre: \"pre\",\n span: \"span\",\n strong: \"strong\",\n table: \"table\",\n tbody: \"tbody\",\n td: \"td\",\n th: \"th\",\n thead: \"thead\",\n tr: \"tr\",\n ul: \"ul\",\n ..._provideComponents(),\n ...props.components\n }, {CodeBlock, Heading, Note} = _components;\n if (!CodeBlock) _missingMdxReference(\"CodeBlock\", true);\n if (!Heading) _missingMdxReference(\"Heading\", true);\n if (!Note) _missingMdxReference(\"Note\", true);\n return _jsxs(_Fragment, {\n children: [ ``` -------------------------------- ### Start Agent Run with Callback URL (cURL) Source: https://docs.mosaic.so/overview/webhooks This cURL command demonstrates how to initiate an agent run and specify a callback URL for receiving webhook notifications. It includes the necessary HTTP method, headers for authorization and content type, and a JSON payload containing video IDs and the callback URL. This allows your application to be notified upon completion or status changes of the agent run. ```bash curl -X POST "https://api.mosaic.so/agent/[agent_id]/run" \ -H "Authorization: Bearer mk_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "video_ids": ["550e8400-e29b-41d4-a716-446655440000"], "callback_url": "https://your-app.com/webhooks/mosaic/abc123xyz" }' ``` -------------------------------- ### GET /whoami Source: https://docs.mosaic.so/overview/introduction Retrieves information about the currently authenticated user. ```APIDOC ## GET /whoami ### Description This endpoint retrieves information about the currently authenticated user based on the provided API key. ### Method GET ### Endpoint /whoami ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```shell curl -X GET \ "https://api.mosaic.so/whoami" \ -H "Authorization: Bearer mk_your_api_key" ``` ### Response #### Success Response (200) - **user_id** (string) - The unique identifier for the user. - **email** (string) - The email address of the user. - **is_admin** (boolean) - Indicates if the user has administrative privileges. - **api_key_id** (string) - The identifier for the API key used. #### Response Example ```json { "user_id": "123e4567-e89b-12d3-a456-789012345678", "email": "user@example.com", "is_admin": false, "api_key_id": "98765432-dcba-4321-abcd-987654321098" } ``` ``` -------------------------------- ### JavaScript Data Structure Example Source: https://docs.mosaic.so/overview/webhooks This snippet demonstrates a JavaScript object literal representing a data structure. It includes fields like 'run_id', 'timestamp', 'message', 'user_id', 'test_data', and 'status', along with their expected data types or example values. This is useful for understanding data formats used in logging or communication. ```javascript { run_id: 'test', timestamp: string, message: string, user_id: string, test_data: { status: 'test', description: string }; } ``` -------------------------------- ### POST /agent/[agent_id]/run Source: https://docs.mosaic.so/overview/introduction Initiates a video editing workflow (Agent) with a specified video and optional parameters. ```APIDOC ## POST /agent/[agent_id]/run ### Description Starts a predefined video editing workflow (Agent) using a previously uploaded video. ### Method POST ### Endpoint `/agent/[agent_id]/run` ### Parameters #### Path Parameters - **agent_id** (string) - Required - The unique identifier of the agent to run. #### Request Body - **video_id** (string) - Required - The ID of the video to process. - **parameters** (object) - Optional - Key-value pairs for agent-specific parameters. ### Request Example ```json { "video_id": "vid_abc123xyz", "parameters": { "output_format": "mp4", "resolution": "1080p" } } ``` ### Response #### Success Response (200) - **run_id** (string) - The unique identifier for this agent run. - **status** (string) - The initial status of the agent run (e.g., 'processing'). #### Response Example ```json { "run_id": "run_def456uvw", "status": "processing" } ``` ``` -------------------------------- ### GET /agent_run/[run_id] Source: https://docs.mosaic.so/overview/introduction Retrieves the current status and details of a specific agent run. ```APIDOC ## GET /agent_run/[run_id] ### Description Poll this endpoint to check the progress and status of an ongoing video processing job. ### Method GET ### Endpoint `/agent_run/[run_id]` ### Parameters #### Path Parameters - **run_id** (string) - Required - The ID of the agent run to query. ### Response #### Success Response (200) - **run_id** (string) - The ID of the agent run. - **status** (string) - The current status (e.g., 'processing', 'completed', 'failed'). - **outputs** (array) - A list of output files if the status is 'completed'. Each item may contain 'url' and 'filename'. - **error** (string) - Details of the error if the status is 'failed'. #### Response Example (Completed) ```json { "run_id": "run_def456uvw", "status": "completed", "outputs": [ { "url": "https://mosaic-outputs.s3.amazonaws.com/.../final_video.mp4", "filename": "final_video.mp4" } ] } ``` #### Response Example (Failed) ```json { "run_id": "run_ghi789xyz", "status": "failed", "error": "Error during audio processing: codec not supported." } ``` ``` -------------------------------- ### Get Agent Triggers Source: https://docs.mosaic.so/overview/triggers Retrieves the current triggers configured for a specific agent. ```APIDOC ## GET /agent/[agent_id]/triggers ### Description Retrieves the current triggers configured for a specific agent. ### Method GET ### Endpoint /agent/[agent_id]/triggers ### Parameters #### Path Parameters - **agent_id** (string) - Required - The unique identifier of the agent. ### Response #### Success Response (200) - **triggers** (array) - A list of triggers configured for the agent. - **type** (string) - The type of trigger (e.g., 'youtube'). - **config** (object) - Configuration details specific to the trigger type. #### Response Example ```json { "triggers": [ { "type": "youtube", "config": { "channel_id": "UC_x5XG1OV2P6uZZ5xwNWK1g" } } ] } ``` ``` -------------------------------- ### Initialize and Manage UI Theme (JavaScript) Source: https://docs.mosaic.so/overview/agent-operations This script handles the initialization and management of UI themes (light, dark, system). It reads theme preferences from local storage or defaults to 'system', applies the chosen theme by adding/removing CSS classes or attributes to the document element, and sets the 'color-scheme' CSS property. It also includes a fallback for older browsers or environments where local storage might be unavailable. ```javascript ((a,b,c,d,e,f,g,h)=>{let i=document.documentElement,j=["light","dark"];function k(b){var c;(Array.isArray(a)?a:[a]).forEach(a=>{let c="class"===a,d=c&&f?e.map(a=>f[a]||a):e;c?(i.classList.remove(...d),i.classList.add(f&&f[b]?f[b]:b)):i.setAttribute(a,b)}),c=b,h&&j.includes(c)&&(i.style.colorScheme=c)}if(d)k(d);else try{let a=localStorage.getItem(b)||c,d=g&&"system"===a?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":a;k(d)}catch(a){}})("class","isDarkMode","system",null,["dark","light","true","false","system""],{"true":"dark","false":"light","dark":"dark","light":"light"},true,true) ``` -------------------------------- ### GET /agent_run/{run_id} Source: https://docs.mosaic.so/overview/agent-operations Poll this endpoint to check the status of your agent run and retrieve outputs. ```APIDOC ## GET /agent_run/{run_id} ### Description Poll this endpoint to check the status of your agent run and retrieve outputs. ### Method GET ### Endpoint /agent_run/{run_id} ### Parameters #### Path Parameters - **run_id** (string) - Required - The ID of the agent run to query ### Request Example ```shellscript curl -X GET "https://api.mosaic.so/agent_run/{run_id}" \ -H "Authorization: Bearer YOUR_API_KEY" ``` ### Response #### Success Response (200) - **status** (string) - The current status of the agent run (e.g., "processing", "completed", "failed"). - **outputs** (object) - The results of the agent run, if completed. #### Response Example ```json { "status": "completed", "outputs": { "video1_id": { "summary": "This is a summary of video 1.", "transcription": "The full transcription of video 1." }, "video2_id": { "summary": "This is a summary of video 2.", "transcription": "The full transcription of video 2." } } } ``` ```