> **Reading as an AI agent?** This is the Markdown version of https://docs.meshy.ai/api/v2/text-to-motion, 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

---

# Text to Motion API

Generate a character animation from a text prompt, then play it on any two-legged character you rigged with the [Rigging API](https://docs.meshy.ai/api/v2/rigging.md).

> **Note:** Moving from v1? The main changes for Text to Motion:
>   * The request is the same.
>   * Results are in `output` instead of `result`.
>   * `output` is `null` until the task succeeds.
>
>   See [what changed for the other endpoints](/api/migrate-to-v2/reference#other-endpoints).

---

## POST /openapi/v2/text-to-motion -- Create a Text to Motion task

Creates a Text to Motion task and returns the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object). The task runs in the background. To read its result, see [Get the result](#get-the-result). For how long a task usually takes, see [Processing times](/api/task-lifecycle#processing-times).

To play the motion on a character, see [Apply the motion to a character](#apply-the-motion-to-a-character).

### Parameters

  - `prompt` · *string* · **required**

  Text that describes the motion to generate, up to 400 characters. For example, `A person waves with the right hand, then takes a bow`. Longer text returns `400`.

  You can write the prompt in other languages.

  - `duration` · *number* · **required**

  The clip length in seconds, from `2` to `10` in steps of `0.5`, for example `3` or `4.5`. Any other value returns `400`.

  - `mode` · *string* · default: `prime`

  The motion model, which also sets the clip's file format.

  Available values:
  * `prime`: returns an FBX clip
  * `swift`: returns a BVH clip

  Any other value returns `400`. The two modes cost different amounts. See [Pricing](/api/pricing).

### Returns

`202 Accepted` with the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object). The task starts as `PENDING`, with your request in `input` and `output` set to `null`.

Two response headers help you read the task:
* `Location`: the task's URL on [Tasks](https://docs.meshy.ai/api/v2/tasks.md#how-a-task-runs)
* `Retry-After`: how many seconds to wait before you first read it

### Failure modes

  - `400 - Bad Request`

  The request can't run. For example:
  * `prompt` is missing, blank (`prompt must not be empty`), or longer than 400 characters
  * `duration` is missing, outside 2 to 10 seconds, or not a multiple of 0.5 (`duration must be between 2 and 10 seconds in 0.5 second steps`)

  The error message says which problem it found. See [Errors](https://docs.meshy.ai/api/v2/errors.md#request-errors).

  - `401 - Unauthorized`

  The API key is missing or invalid. Check the `Authorization` header.

  - `402 - Payment Required`

  One of these applies:
  * The account doesn't have enough credits.
  * The account reached a credit limit.
  * The account is on the free plan.

  Check your credits and plan, then retry.

  - `403 - Forbidden`

  Content moderation blocked the prompt. The message is `explicit content` or `prohibited content`. Change the prompt, then send the request again.

  - `429 - Too Many Requests`

  One of these limits was reached:
  * You sent too many requests. Wait the number of seconds in `Retry-After`, then retry.
  * Too many of your tasks are queued or running. Wait for some to finish, then retry.
  * On an unlimited plan with no credits left, you reached the number of tasks that can run without credits. Wait for a task to finish, or add credits.

**cURL**

```bash
# Generate a 3-second motion
curl https://api.meshy.ai/openapi/v2/text-to-motion \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "A person waves with the right hand, then takes a bow",
    "duration": 3
  }'

# Generate a 2.5-second BVH clip with swift
curl https://api.meshy.ai/openapi/v2/text-to-motion \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "A person jumps twice in place",
    "duration": 2.5,
    "mode": "swift"
  }'
```

```javascript
// Generate a 3-second motion
const response = await fetch("https://api.meshy.ai/openapi/v2/text-to-motion", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MESHY_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    prompt: "A person waves with the right hand, then takes a bow",
    duration: 3,
  }),
});
if (!response.ok) throw new Error(await response.text());
const task = await response.json();
console.log(task.id, task.status);
```

```python
import os
import requests

# Generate a 3-second motion
response = requests.post(
    "https://api.meshy.ai/openapi/v2/text-to-motion",
    headers={"Authorization": f"Bearer {os.environ['MESHY_API_KEY']}"},
    json={
        "prompt": "A person waves with the right hand, then takes a bow",
        "duration": 3,
    },
)
response.raise_for_status()
task = response.json()
print(task["id"], task["status"])
```

**Response**

```json
{
  "id": "0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13",
  "type": "text-to-motion",
  "status": "PENDING",
  "progress": 0,
  "created_at": 1790640079880,
  "started_at": null,
  "finished_at": null,
  "expires_at": null,
  "preceding_tasks": 1,
  "consumed_credits": 10,
  "task_error": null,
  "input": {
    "prompt": "A person waves with the right hand, then takes a bow",
    "duration": 3
  },
  "output": null
}
```

---

## Apply the motion to a character

The clip in `output.motion_url` has the motion on its own, with no character. To play it on your character, wait until the Text to Motion task's status is `SUCCEEDED`. Then create an [Animation](https://docs.meshy.ai/api/v2/animation.md) task with these parameters:
* `motion_task_id`: the Text to Motion task's `id`
* `rig_task_id`: the `id` of a [Rigging](https://docs.meshy.ai/api/v2/rigging.md) task

Create the Animation task within 3 days after the Text to Motion task finishes. After that, Meshy deletes the clip, like other task files, and Animation returns `404`. Enterprise accounts keep their files.

Meshy charges for each task separately. See [Pricing](/api/pricing).

**cURL**

```bash
# 1. Generate a 3-second motion
curl https://api.meshy.ai/openapi/v2/text-to-motion \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "A person waves with the right hand, then takes a bow",
    "duration": 3
  }'

# 2. When it succeeds, play it on a rigged character
curl https://api.meshy.ai/openapi/v2/animations \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "rig_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "motion_task_id": "<Text to Motion task ID>"
  }'
```

```javascript
const API = "https://api.meshy.ai/openapi/v2";
const headers = {
  Authorization: `Bearer ${process.env.MESHY_API_KEY}`,
  "Content-Type": "application/json",
};

async function create(path, body) {
  const response = await fetch(`${API}/${path}`, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
  });
  if (!response.ok) throw new Error(await response.text());
  return (await response.json()).id;
}

async function wait(id) {
  for (;;) {
    const response = await fetch(`${API}/tasks/${id}`, { headers });
    if (!response.ok) throw new Error(await response.text());
    const task = await response.json();
    if (task.status === "SUCCEEDED") return task;
    if (task.status === "FAILED" || task.status === "CANCELED") {
      throw new Error(JSON.stringify(task.task_error));
    }
    const seconds = Number(response.headers.get("Retry-After") ?? 5);
    await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
  }
}

// 1. Generate a motion, 2. play it on a rigged character
const motion = await wait(await create("text-to-motion", {
  prompt: "A person waves with the right hand, then takes a bow",
  duration: 3,
}));
const animation = await wait(await create("animations", {
  rig_task_id: "018a210d-8ba4-705c-b111-1f1776f7f578",
  motion_task_id: motion.id,
}));

console.log(animation.output.animation_glb_url);
```

```python
import os
import time
import requests

API = "https://api.meshy.ai/openapi/v2"
HEADERS = {"Authorization": f"Bearer {os.environ['MESHY_API_KEY']}"}

def create(path, body):
    response = requests.post(f"{API}/{path}", headers=HEADERS, json=body)
    response.raise_for_status()
    return response.json()["id"]

def wait(task_id):
    while True:
        response = requests.get(f"{API}/tasks/{task_id}", headers=HEADERS)
        response.raise_for_status()
        task = response.json()
        if task["status"] == "SUCCEEDED":
            return task
        if task["status"] in ("FAILED", "CANCELED"):
            raise RuntimeError(task["task_error"])
        time.sleep(int(response.headers.get("Retry-After", 5)))

# 1. Generate a motion, 2. play it on a rigged character
motion = wait(create("text-to-motion", {
    "prompt": "A person waves with the right hand, then takes a bow",
    "duration": 3,
}))
animation = wait(create("animations", {
    "rig_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "motion_task_id": motion["id"],
}))

print(animation["output"]["animation_glb_url"])
```

---

## Get the result
Read Text to Motion tasks the same way as every other v2 task, through the [Tasks](https://docs.meshy.ai/api/v2/tasks.md) routes. To list only Text to Motion tasks, filter by `type=text-to-motion`.

| To | Call |
| --- | --- |
| Get one task | [`GET /openapi/v2/tasks/{id}`](https://docs.meshy.ai/api/v2/tasks.md#get-a-task) |
| Wait for updates | [`GET /openapi/v2/tasks/{id}/stream`](https://docs.meshy.ai/api/v2/tasks.md#stream-a-task) or a [webhook](https://docs.meshy.ai/api/v2/webhooks.md) |
| List your tasks | [`GET /openapi/v2/tasks?type=text-to-motion`](https://docs.meshy.ai/api/v2/tasks.md#list-tasks) |
| Delete a task | [`DELETE /openapi/v2/tasks/{id}`](https://docs.meshy.ai/api/v2/tasks.md#delete-a-task) |

---

## Text to Motion output
When the task succeeds, `output` holds these fields. The rest of the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object) is the same for every task type. The URL in `output` stops working at `expires_at`.

  - `motion_url` · *string | null*

  Signed URL to the motion clip, an FBX file for `prime` or a BVH file for `swift`.

  - `motion_format` · *string*

  The clip's file format, `fbx` or `bvh`.

  - `duration_ms` · *integer*

  The clip length you asked for, in milliseconds.

  - `mode` · *string*

  The `mode` Meshy used to make the clip, `prime` or `swift`.

**Succeeded Text to Motion task**

```json
{
  "id": "0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13",
  "type": "text-to-motion",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1790640079880,
  "started_at": 1790640079886,
  "finished_at": 1790640092812,
  "expires_at": 1790899292812,
  "preceding_tasks": 0,
  "consumed_credits": 10,
  "task_error": null,
  "input": {
    "prompt": "A person waves with the right hand, then takes a bow",
    "duration": 3
  },
  "output": {
    "motion_url": "https://assets.meshy.ai/***/output/clip.fbx?Expires=***",
    "motion_format": "fbx",
    "duration_ms": 3000,
    "mode": "prime"
  }
}
```
