Optimize Model

Use model_optimize when you already have a GLB and want to optimize it for target size or performance.

When To Use

  • reducing polygon density for runtime performance
  • preparing assets for web or realtime pipelines
  • improving consistency across generated assets

Expected outcome: optimized GLB outputs retrievable by asset_id after completion.

Inputs

  • required input type: model/gltf-binary (GLB)
  • JSON requests should provide a valid GLB data URL

Minimal input object:

{
  "data": "data:model/gltf-binary;base64,<base64-glb>"
}

Parameters

NameTypeDefaultAllowed valuesPractical guidance
polygon_countinteger100000positive integerLower values reduce geometry complexity; tune based on target platform.

Minimal Runnable Payload

from pathlib import Path
from base64 import b64encode

def glb_to_data_url(path: Path) -> str:
    encoded = b64encode(path.read_bytes()).decode()
    return f"data:model/gltf-binary;base64,{encoded}"

payload = {
    "template": "model_optimize",
    "parameters": {
        "polygon_count": 50000
    },
    "inputs": [
        {
            "data": glb_to_data_url(Path("model.glb"))
        }
    ]
}

Polling And Output Retrieval

  1. Submit the optimization flow.
  2. Poll until terminal state.
  3. On completed, list outputs and fetch each by asset_id.

Reference helper code in Template Helpers.

Common Failure Modes

  • invalid GLB payload or corrupted input model
  • polygon count too aggressive for source geometry
  • wrong asset_id during output fetch

Recovery:

  1. verify source GLB opens correctly before upload
  2. retry with a less aggressive polygon_count
  3. always fetch asset_id from outputs list before download

See Troubleshooting for response-level diagnostics.