Skip to main content

Developer Portal

Manage your API keys, webhooks, and view usage statistics

API Keys

0

Webhooks

0

Requests (30d)

0

Success Rate

100%

Quick Start

import requests
import time

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.formd.dev"

def generate_design(prompt: str, category: str = None, material: str = "pla"):
    """Generate a 3D design from a natural language prompt."""
    response = requests.post(
        f"{BASE_URL}/api/generate",
        headers={"X-API-Key": API_KEY},
        json={
            "prompt": prompt,
            "category": category,
            "material": material,
        }
    )
    response.raise_for_status()
    return response.json()

def check_status(job_id: str):
    """Check the status of a generation job."""
    response = requests.get(
        f"{BASE_URL}/api/status/{job_id}",
        headers={"X-API-Key": API_KEY}
    )
    response.raise_for_status()
    return response.json()

def get_design(job_id: str):
    """Get full design details including print settings."""
    response = requests.get(
        f"{BASE_URL}/api/design/{job_id}",
        headers={"X-API-Key": API_KEY}
    )
    response.raise_for_status()
    return response.json()

def download_stl(job_id: str, output_path: str):
    """Download the STL file for a completed design."""
    response = requests.get(
        f"{BASE_URL}/api/download/{job_id}",
        headers={"X-API-Key": API_KEY}
    )
    response.raise_for_status()
    with open(output_path, "wb") as f:
        f.write(response.content)

# Example usage
if __name__ == "__main__":
    # Generate a design
    result = generate_design(
        prompt="a phone stand with cable management for iPhone 15",
        category="phone_stand"
    )
    print(f"Job ID: {result['job_id']}")
    
    # Poll for completion
    while True:
        status = check_status(result['job_id'])
        print(f"Status: {status['status']}")
        
        if status['status'] == 'complete':
            design = get_design(result['job_id'])
            print(f"STL URL: {design['stl_url']}")
            print(f"Print time: {design.get('estimated_print_time_minutes')} min")
            
            # Download the STL
            download_stl(result['job_id'], f"{result['job_id']}.stl")
            print("Downloaded!")
            break
        elif status['status'] == 'failed':
            print(f"Error: {status.get('error')}")
            break
        
        time.sleep(2)