Build, deploy, and use your first model using the Plexe Platform REST API.
This tutorial walks you through the essential steps to create and use a machine learning model with the Plexe Platform API.Base URL:https://api.plexe.ai
All API requests require your API key in the x-api-key header:
Copy
Ask AI
import requests, os, time, json# Load API key from environmentapi_key = os.getenv("PLEXE_API_KEY")if not api_key: raise ValueError("Please set the PLEXE_API_KEY environment variable.")headers = { "x-api-key": api_key, "Content-Type": "application/json"}base_url = "https://api.plexe.ai"
Model building happens asynchronously. Poll until complete:
Copy
Ask AI
if model_id: # Extract name and version from model_id (format: name:version) m_name, m_version = model_id.split(':') status = "pending" # Poll until completed or failed while status in ["pending", "processing", "building"]: time.sleep(15) # Wait between checks try: response = requests.get( f"{base_url}/models/{m_name}/{m_version}/status", headers=headers ) response.raise_for_status() status_result = response.json() status = status_result.get("status") print(f"Status: {status}") if status == "completed": print("Build successful!") break elif status == "failed": print(f"Build failed: {status_result.get('error', 'Unknown error')}") model_id = None break except Exception as e: print(f"Status check error: {e}") time.sleep(30) # Longer wait on error