> **Reading as an AI agent?** This is the Markdown version of https://docs.meshy.ai/api/v2/webhooks, part of the Meshy API v2 docs.
>
> - v2 docs index: https://docs.meshy.ai/api/v2/llms.txt
> - All v2 pages in one file: https://docs.meshy.ai/api/v2/llms-full.txt
> - OpenAPI spec for v2: https://docs.meshy.ai/api/v2/openapi.yaml

---

# Webhooks

Get a `POST` request from Meshy when one of your API tasks makes progress or finishes, instead of polling for it.

> **Note:** Moving from v1? A webhook keeps its v1 payload until you switch it. See [Switch a webhook to v2](#switch-a-webhook-to-v2).

---

## Set up a webhook
To add a webhook, open the [Webhooks page](https://www.meshy.ai/developers/webhooks) in the [Developer Platform](/api/developer-platform) and click **Create Webhook**.

1. In **Payload URL**, enter the URL that receives the deliveries. Meshy delivers only over `https://`, and the URL's host must resolve to a public IPv4 address.
2. Leave **Payload version** on v2. See [Payload versions](#payload-versions).
3. Keep a copy of the **Webhook Secret** that the dialog fills in. Every delivery carries it, so your server can check that a request came from Meshy.
4. Check your server with **Send test** before you save. See [Test a webhook](#test-a-webhook).
5. Keep **Active** on, and click **Confirm**.

Each account can have 5 active webhooks, and 10 in total. Every active webhook receives the deliveries of the API tasks that run as the Meshy user who signs in to the Webhooks page. A team API key runs as the team owner, so the team owner signs in to see, test, and switch the team's webhooks.

---

## Payload versions
Each webhook has a payload version, v1 or v2. It sets the body of the webhook's deliveries:

- v2: the v2 [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object), the same object `GET /openapi/v2/tasks/{id}` returns, for every task type.
- v1: the v1 task object of the endpoint that created the task. See the [v1 Webhooks page](/api/webhooks#sample-response).

The version belongs to the webhook, not to the API version that created the task. A task you create on v1 reaches a v2 webhook as the v2 task object. A task you create on v2 reaches a v1 webhook as the v1 body. Moving your API calls to v2 doesn't change your webhooks.

Creative Lab endpoints aren't part of API v2. Their deliveries keep their v1 body and the `v1` header, even on a v2 webhook.

---

## Deliveries

Meshy sends a delivery while a task is `IN_PROGRESS`, and another when the task reaches a final status. A task can reach its final status without an `IN_PROGRESS` delivery.

Each delivery is a `POST` to your Payload URL with a JSON body and these headers:

| Header | Value |
| --- | --- |
| `Meshy-Webhook-Version` | `v2` when the body is the v2 task object, `v1` when it's the v1 body |
| `X-MESHY-API-WEBHOOK-SECRET-KEY` | The webhook's secret |
| `X-MESHY-API-WEBHOOK-USER-ID` | The ID of the Meshy user who owns the webhook |
| `Content-Type` | `application/json` |
| `User-Agent` | `MeshyAPIWebhook/1.0.0` |

Read the body by the `Meshy-Webhook-Version` header, not by the webhook's version. The header names the format of that one delivery, and a Creative Lab delivery on a v2 webhook is `v1`.

A v2 delivery's body is the task object as `GET /openapi/v2/tasks/{id}` returns it, except `progress`. A delivery sends `progress` as one of these values:

- `50` while the task is `IN_PROGRESS`
- `100` when the task succeeds
- `0` when the task fails or is canceled

To read the task's latest progress, [get the task](https://docs.meshy.ai/api/v2/tasks.md#get-a-task).

**A v2 delivery**

```http
POST /meshy-webhook HTTP/1.1
Content-Type: application/json
Meshy-Webhook-Version: v2
User-Agent: MeshyAPIWebhook/1.0.0
X-MESHY-API-WEBHOOK-SECRET-KEY: ********************************
X-MESHY-API-WEBHOOK-USER-ID: ***

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "type": "image-to-3d",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1791846275575,
  "started_at": 1791846275578,
  "finished_at": 1791846334536,
  "expires_at": 1792105534536,
  "preceding_tasks": 0,
  "consumed_credits": 30,
  "task_error": null,
  "input": {
    "image_url": "https://docs.meshy.ai/images/api/quick-start/source-photo.webp",
    "texture_model": "meshy-7"
  },
  "output": {
    "model_urls": {
      "glb": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/model.glb?Expires=***"
    },
    "thumbnail_url": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/preview.png?Expires=***",
    "thumbnail_urls": null,
    "texture_urls": [
      {
        "base_color": "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/texture_0.png?Expires=***",
        "metallic": null,
        "roughness": null,
        "normal": null,
        "metallic_roughness": null,
        "emission": null
      }
    ]
  }
}
```

---

## Handle a delivery

To accept a delivery, respond with a status below 400, such as `200` or `202`. Meshy waits about 25 seconds for the response, so store the delivery and respond first. Do the slow work after that, such as downloading the model.

A status of 400 or above, or no response, counts as a failed delivery. Meshy retries it with longer waits between attempts, up to 4 times for an `IN_PROGRESS` update and up to 9 times for a final status. If 20 updates in a row fail every attempt, Meshy can deactivate the webhook. To turn it back on, edit it on the Webhooks page and select **Active**.

Write your code for these cases:

- Deliveries can arrive out of order. An `IN_PROGRESS` delivery can arrive after the final one, so don't let it replace a final status.
- The same update can arrive more than once. Handle each pair of `id` and `status` once.
- Anyone who knows your URL can send it a request. Compare `X-MESHY-API-WEBHOOK-SECRET-KEY` with your copy of the secret, and reject a request that doesn't match.

If a task's final delivery hasn't arrived after about twice the task's typical time, [get the task](https://docs.meshy.ai/api/v2/tasks.md#get-a-task). For typical times, see [Processing times](/api/task-lifecycle#processing-times).

**Python**

```python
import hmac
import os

from flask import Flask, request

app = Flask(__name__)
SECRET = os.environ["MESHY_WEBHOOK_SECRET"]

@app.post("/meshy-webhook")
def meshy_webhook():
    sent = request.headers.get("X-MESHY-API-WEBHOOK-SECRET-KEY", "")
    if not hmac.compare_digest(sent, SECRET):
        return "", 401
    task = request.get_json()
    # The same update can arrive twice. Handle each id and status once.
    if already_handled(task["id"], task["status"]):
        return "", 200
    if request.headers.get("Meshy-Webhook-Version") == "v2":
        save_v2(task)  # results under task["output"]
    else:
        save_v1(task)  # Creative Lab, or a webhook on v1
    return "", 200
```

**JavaScript**

```javascript
const crypto = require('crypto');
const express = require('express');

const app = express();
const SECRET = Buffer.from(process.env.MESHY_WEBHOOK_SECRET);

function fromMeshy(req) {
  const sent = Buffer.from(req.get('X-MESHY-API-WEBHOOK-SECRET-KEY') ?? '');
  return sent.length === SECRET.length && crypto.timingSafeEqual(sent, SECRET);
}

app.post('/meshy-webhook', express.json(), async (req, res) => {
  if (!fromMeshy(req)) return res.sendStatus(401);
  const task = req.body;
  // The same update can arrive twice. Handle each id and status once.
  if (await alreadyHandled(task.id, task.status)) return res.sendStatus(200);
  if (req.get('Meshy-Webhook-Version') === 'v2') {
    await saveV2(task); // results under task.output
  } else {
    await saveV1(task); // Creative Lab, or a webhook on v1
  }
  res.sendStatus(200);
});
```

---

## Test a webhook
**Send test** on the [Webhooks page](https://www.meshy.ai/developers/webhooks) sends one of your tasks to a URL and shows you what your server answered. It works in the Create and Edit dialogs, before you save.

1. Click **Create Webhook**, or edit a webhook.
2. Enter the **Payload URL**, and set **Payload version** to the version you want to test.
3. Under **Test before saving**, pick a task and click **Send test**. The list shows your 10 newest finished API tasks created in the last 30 days.
4. Check the result. Any status below 400 counts as delivered. The response body is shown as your server returned it, up to the first 64 KiB. To see the exact request, open **What we sent**.

<ImageExample
  title="Send test"
  caption="Set Payload version, pick a task, and click Send test. Open What we sent to see the exact request."
>
  <ImageExampleCard
src="/images/api/migrate-to-v2/webhook-send-test.webp"
alt="The Edit Webhook dialog with Payload version set to v2. Send test delivered a task, and the result shows status 200 and the response body from the server."
label="Result"
aspectRatio="908 / 1488"
  />
  <ImageExampleCard
src="/images/api/migrate-to-v2/webhook-send-test-request.webp"
alt="What we sent, opened under the result, showing the request headers with Meshy-Webhook-Test: true and the start of the v2 task object"
label="What we sent"
aspectRatio="826 / 1016"
  />
</ImageExample>

A test has the same body and headers as a real delivery of that task, plus `Meshy-Webhook-Test: true`. Real deliveries never have this header. Your code handles a test the same way as a real delivery. So when this header is `true`, skip paid follow-up work, such as a Retexture you start after an Image to 3D task succeeds.

A test doesn't count as a delivery, and it doesn't change your webhook. To close the dialog without saving, click **Cancel**. You can send up to 10 tests a minute.

---

## Test on your computer
Meshy delivers only to a public `https://` URL, so it can't reach a server on your computer directly. To test code on your computer, forward a public URL to it with a webhook proxy. These steps use [smee.io](https://smee.io/), and any webhook proxy works the same way.

1. Open [smee.io](https://smee.io/) and click **Start a new channel**. Copy the **Webhook Proxy URL**.
2. Install the smee client:

   ```bash
   npm install --global smee-client
   ```

3. Forward the channel to your server. Replace `WEBHOOK_PROXY_URL` with your Webhook Proxy URL, and the path and port with your server's:

   ```bash
   smee --url WEBHOOK_PROXY_URL --path /meshy-webhook --port 3000
   ```

   Keep it running while you test. To stop forwarding, press Ctrl+C.

4. Use the Webhook Proxy URL as the Payload URL in [Send test](#test-a-webhook), or in a webhook.

---

## Switch a webhook to v2
A webhook on v1 keeps receiving v1 deliveries until you switch it. To switch it without missing an update:

1. Update the code behind the webhook's URL so it accepts both versions. Branch on the `Meshy-Webhook-Version` header, as in [Handle a delivery](#handle-a-delivery).
2. Edit the webhook and set **Payload version** to v2. Check your code with [Send test](#test-a-webhook). The webhook stays on v1 until you save.
3. Click **Save**. From then on, the webhook receives v2 deliveries for every task except Creative Lab.

To switch back, set Payload version to v1. Switching doesn't resend past deliveries. If your code missed any, read those tasks with `GET /openapi/v2/tasks/{id}`, or with their v1 routes for Creative Lab.

For the full steps with screenshots, see [Move your webhooks to v2](/api/migrate-to-v2#step-4-move-your-webhooks-to-v2) in the migration guide. For how the v1 and v2 bodies differ, see [Webhook payloads](/api/migrate-to-v2/reference#webhook-payloads).
