> For the complete documentation index, see [llms.txt](https://docs.m-xr.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.m-xr.com/marso-studio-api/getting-started/mesh.md).

# Mesh

**Upload one mesh**

Use `POST /uploads` to get a presigned URL. Upload the bytes to that URL, then poll `GET /uploads/{asset_id}` until the status is `ready`.

{% tabs %}
{% tab title="cURL" %}

```bash
file="model.glb"
size=$(wc -c < "$file")
upload=$(curl -sS "$MARSO_API_BASE_URL/uploads" \
  -H "Authorization: Bearer $MARSO_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"filename\":\"$file\",\"size_bytes\":$size}")
upload_args=()
while IFS= read -r header; do upload_args+=(--header "$header"); done < <(
  echo "$upload" | jq -r '.headers | to_entries[] | "\(.key): \(.value)"'
)
curl -sS "$(echo "$upload" | jq -r .upload_url)" "${upload_args[@]}" --upload-file "$file"
asset_id=$(echo "$upload" | jq -r .asset_id)
while :; do
  status=$(curl -sS "$MARSO_API_BASE_URL/uploads/$asset_id" \
    -H "Authorization: Bearer $MARSO_API_KEY")
  state=$(echo "$status" | jq -r .status)
  [[ "$state" != "pending" ]] && break
  sleep 2
done
echo "$status"
```

{% endtab %}

{% tab title="Python" %}

```python
import os
from pathlib import Path
import time
import requests

base = os.environ["MARSO_API_BASE_URL"]
headers = {"Authorization": f"Bearer {os.environ['MARSO_API_KEY']}"}
path = Path("model.glb")
data = path.read_bytes()
upload = requests.post(
    f"{base}/uploads", headers=headers,
    json={"filename": path.name, "size_bytes": len(data)}, timeout=30
).json()
requests.put(upload["upload_url"], headers=upload["headers"], data=data, timeout=300).raise_for_status()
while True:
    status = requests.get(f"{base}/uploads/{upload['asset_id']}", headers=headers, timeout=30).json()
    if status["status"] == "ready":
        break
    if status["status"] == "rejected":
        raise RuntimeError("mesh validation failed")
    time.sleep(2)
```

{% endtab %}

{% tab title="Go" %}

```go
base := os.Getenv("MARSO_API_BASE_URL")
key := os.Getenv("MARSO_API_KEY")
body := strings.NewReader(`{"filename":"model.glb","size_bytes":12345}`)
req, _ := http.NewRequest(http.MethodPost, base+"/uploads", body)
req.Header.Set("Authorization", "Bearer "+key)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { log.Fatal(err) }
defer resp.Body.Close()
```

{% endtab %}
{% endtabs %}

**Download and unzip the USDZ mesh result**

Submit the ready asset to `POST /pbr/execute/mesh`. Poll the execution until it reaches a terminal status, then download `usdz.download_url`.

{% tabs %}
{% tab title="cURL" %}

```bash
execution=$(curl -sS "$MARSO_API_BASE_URL/pbr/execute/mesh" \
  -H "Authorization: Bearer $MARSO_API_KEY" -H "Content-Type: application/json" \
  -d '{"asset_id":"<ready-asset-id>"}')
execution_id=$(echo "$execution" | jq -r .execution_id)
while :; do
  result=$(curl -sS "$MARSO_API_BASE_URL/pbr/executions/$execution_id" \
    -H "Authorization: Bearer $MARSO_API_KEY")
  status=$(echo "$result" | jq -r .status)
  [[ "$status" == "SUCCEEDED" || "$status" == "PARTIAL_SUCCEEDED" || "$status" == "FAILED" || "$status" == "CANCELED" ]] && break
  sleep 5
done
[[ "$status" == "FAILED" || "$status" == "CANCELED" ]] && exit 1
usdz_url=$(echo "$result" | jq -r '.usdz.download_url // empty')
[[ -z "$usdz_url" ]] && exit 1
curl -L "$usdz_url" -o material.usdz
unzip material.usdz -d material
```

{% endtab %}

{% tab title="Python" %}

```python
execution = requests.post(
    f"{base}/pbr/execute/mesh", headers=headers,
    json={"asset_id": "<ready-asset-id>"}, timeout=30
).json()
while True:
    result = requests.get(
        f"{base}/pbr/executions/{execution['execution_id']}", headers=headers, timeout=30
    ).json()
    if result["status"] in {"SUCCEEDED", "PARTIAL_SUCCEEDED", "FAILED", "CANCELED"}:
        break
    time.sleep(5)
if result["status"] in {"FAILED", "CANCELED"} or "usdz" not in result:
    raise RuntimeError(result["error"]["message"])
Path("material.usdz").write_bytes(requests.get(result["usdz"]["download_url"], timeout=300).content)
```

{% endtab %}

{% tab title="Go" %}

```go
// Poll GET /pbr/executions/{execution_id} until status is SUCCEEDED.
req, _ := http.NewRequest(http.MethodGet, base+"/pbr/executions/<execution-id>", nil)
req.Header.Set("Authorization", "Bearer "+key)
resp, err := http.DefaultClient.Do(req)
if err != nil { log.Fatal(err) }
defer resp.Body.Close()
var result struct { USDZ struct { DownloadURL string `json:"download_url"` } `json:"usdz"` }
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { log.Fatal(err) }
download, err := http.Get(result.USDZ.DownloadURL)
if err != nil { log.Fatal(err) }
defer download.Body.Close()
file, _ := os.Create("material.usdz")
defer file.Close()
_, _ = io.Copy(file, download.Body)
```

{% endtab %}
{% endtabs %}

**Upload a batch**

Use `POST /batch/uploads` for 5 to 200 files. Upload each file to its returned URL, then poll `GET /batch/uploads/{upload_batch_id}`.

{% tabs %}
{% tab title="cURL" %}

```bash
batch=$(curl -sS "$MARSO_API_BASE_URL/batch/uploads" \
  -H "Authorization: Bearer $MARSO_API_KEY" -H "Content-Type: application/json" \
  -d '{"files":[{"filename":"one.glb","size_bytes":12345},{"filename":"two.glb","size_bytes":23456},{"filename":"three.glb","size_bytes":34567},{"filename":"four.glb","size_bytes":45678},{"filename":"five.glb","size_bytes":56789}]}')
for i in 0 1 2 3 4; do
  file=$(printf '%s\n' one.glb two.glb three.glb four.glb five.glb | sed -n "$((i + 1))p")
  url=$(echo "$batch" | jq -r ".files[$i].upload_url")
  upload_args=()
  while IFS= read -r header; do upload_args+=(--header "$header"); done < <(
    echo "$batch" | jq -r ".files[$i].headers | to_entries[] | \"\(.key): \(.value)\""
  )
  curl -sS "$url" "${upload_args[@]}" --upload-file "$file"
done
batch_id=$(echo "$batch" | jq -r .upload_batch_id)
while :; do
  status=$(curl -sS "$MARSO_API_BASE_URL/batch/uploads/$batch_id" \
    -H "Authorization: Bearer $MARSO_API_KEY")
  state=$(echo "$status" | jq -r .state)
  [[ "$state" != "UPLOADING" ]] && break
  sleep 2
done
echo "$status"
```

{% endtab %}

{% tab title="Python" %}

```python
files = [{"filename": name, "size_bytes": Path(name).stat().st_size} for name in ["one.glb", "two.glb", "three.glb", "four.glb", "five.glb"]]
batch = requests.post(f"{base}/batch/uploads", headers=headers, json={"files": files}, timeout=30).json()
for path, upload in zip([Path(file["filename"]) for file in files], batch["files"]):
    requests.put(upload["upload_url"], headers=upload["headers"], data=path.read_bytes(), timeout=300).raise_for_status()
while True:
    status = requests.get(f"{base}/batch/uploads/{batch['upload_batch_id']}", headers=headers, timeout=30).json()
    if status["state"] != "UPLOADING":
        break
    time.sleep(2)
print(status)
```

{% endtab %}

{% tab title="Go" %}

```go
payload := `{"files":[{"filename":"one.glb","size_bytes":12345},{"filename":"two.glb","size_bytes":23456},{"filename":"three.glb","size_bytes":34567},{"filename":"four.glb","size_bytes":45678},{"filename":"five.glb","size_bytes":56789}]}`
req, _ := http.NewRequest(http.MethodPost, base+"/batch/uploads", strings.NewReader(payload))
req.Header.Set("Authorization", "Bearer "+key)
req.Header.Set("Content-Type", "application/json")
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.m-xr.com/marso-studio-api/getting-started/mesh.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
