> **Reading as an AI agent?** This is the Markdown version of https://docs.meshy.ai/api/creative-lab-keycap.
>
> - Full docs index: https://docs.meshy.ai/llms.txt
> - Single-fetch full content: https://docs.meshy.ai/llms-full.txt
> - Tool-calling access via MCP server: https://docs.meshy.ai/api/ai

---
# Creative Lab Keycap API

Turn a photo into a full-color custom keycap for a mechanical keyboard in two stages. A prototype task generates an image of the finished keycap from the photo. A build task turns that image into a textured 3D keycap model. It takes the prototype task's ID as `input_task_id` and the image's candidate ID as `candidate_id`.

- `POST /openapi/creative-lab/keycap/v1/prototype`
- `POST /openapi/creative-lab/keycap/v1/build`

Both `POST` endpoints need a paid plan. A request from a free-plan account returns `402`.

---

## POST /openapi/creative-lab/keycap/v1/prototype -- Create a Keycap prototype task

Generates one image of the finished keycap from a photo. The task's `image_urls` holds the image, and `candidate_ids` holds its ID, with one entry in each. If you don't like the design, create another prototype task. Meshy charges for each prototype task separately.

To build the 3D keycap, pass this task's ID to the [build endpoint](#create-a-keycap-build-task) as `input_task_id`, with the `candidate_ids` entry as `candidate_id`. For the task's fields, see [The Keycap prototype task object](#the-keycap-prototype-task-object).

### Parameters

  - `image_url` · *string* · **required**

  The photo to turn into a keycap design, as a public URL or a data URI (`data:image/jpeg;base64,<your base64-encoded image data>`).

  The image must be a JPG, JPEG, PNG, or WebP file of at most 20 MB (20,000,000 bytes). Each side must be at least 32 pixels, and the image can have at most 178,956,970 pixels in total. An image outside these limits returns `400`.

  Meshy detects the format from the image data, not from the file extension in the URL. A URL with no extension works, and Meshy follows HTTP redirects. Meshy applies the EXIF orientation, so a rotated phone photo comes out the way it looks.

  A data URI must be base64-encoded with an image type, such as `data:image/png;base64,...`, and the decoded image must be JPEG, PNG, or WebP. The 20 MB limit applies to the decoded image, so the base64 text can be about a third larger.

  - `name` · *string*

  A name for the task, up to 100 characters. It comes back in the task's `name` field. A longer name returns `400`.

  - `remove_background` · *boolean* · default: `false`

  Whether to remove the background from the prototype image. `true` returns a transparent RGBA PNG, so you can place the keycap on any background. If Meshy can't remove the background, it returns the image with its background, and the task still succeeds.

  The head design that the build turns into 3D keeps its background either way. The build paints the keycap base from the image in `image_urls`, without its background if you sent `true`. The build returns that image as `process_image_urls.composite`.

### Returns

The `result` field holds the ID of the new prototype task. [Get the task](#retrieve-a-keycap-task) or [stream it](#stream-a-keycap-task) until `status` is `SUCCEEDED`. Then pass the ID to the [build endpoint](#create-a-keycap-build-task) as `input_task_id`, with the entry from `candidate_ids` as `candidate_id`.

### Failure modes

  - `400 - Bad Request`

  The request can't run. For example:
  * `image_url` is missing.
  * The image isn't a JPG, JPEG, PNG, or WebP file.
  * The image is too small, over 20 MB, or over the maximum pixel count.
  * Meshy can't download the image, for example because the URL returns `404` or times out.
  * The data URI isn't valid base64.
  * The image was flagged as NSFW.

  The error message says which problem it found. Fix the request, then send it again.

  - `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 API key, workspace, or member reached its credit limit.
  * The account is on the free plan.

  Check your credits and plan, then retry.

  - `403 - Forbidden`

  Your team has **IP Filtering** turned on, and Meshy flagged the image for third-party intellectual property. Send an image you have the rights to use.

  - `429 - Too Many Requests`

  One of these limits was reached:
  * You sent more requests than your rate limit allows. Wait a few seconds, then retry. See [Rate limits](/api/rate-limits).
  * 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.

  - `500 - Internal Server Error`

  Meshy hit a server error, for example because content moderation or the intellectual property check couldn't run, or Meshy couldn't store the image. Meshy doesn't create the task, and refunds any credits it charged. Retry the request.

**cURL**

```bash
# Stage 1: generate a finished-keycap design render
curl https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype \
  -X POST \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "image_url": "<your publicly accessible image url or base64-encoded data URI>"
  }'
```

```javascript
import axios from 'axios'

const headers = { Authorization: `Bearer ${YOUR_API_KEY}` };

// Stage 1: generate a finished-keycap design render
const payload = {
  image_url: "<your publicly accessible image url or base64-encoded data URI>",
};

try {
  const response = await axios.post(
    'https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype',
    payload,
    { headers }
  );
  console.log(response.data);
} catch (error) {
  console.error(error);
}
```

```python
import requests

headers = {
    "Authorization": f"Bearer {YOUR_API_KEY}"
}

# Stage 1: generate a finished-keycap design render
payload = {
    "image_url": "<your publicly accessible image url or base64-encoded data URI>",
}

response = requests.post(
    "https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype",
    headers=headers,
    json=payload,
)
response.raise_for_status()
print(response.json())
```

**Response**

```json
{
  "result": "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef"
}
```

---

## POST /openapi/creative-lab/keycap/v1/build -- Create a Keycap build task

Generates the textured 3D keycap from a succeeded prototype task and one of its candidates. For its fields, see [The Keycap build task object](#the-keycap-build-task-object).

One build task runs every step. It generates a 3D model from the design and colors it. Then it seats and cuts the model onto the keycap base in a calibrated default pose, so you don't need to adjust it by hand. Last, it assembles the keycap and exports the files. A build typically takes 3 to 7 minutes.

### Parameters

  - `input_task_id` · *string* · **required**

  The ID of the prototype task to build. It must be a task your account created with `POST /openapi/creative-lab/keycap/v1/prototype`, with the status `SUCCEEDED`.

  An ID that isn't one of your Keycap prototype tasks from the API returns `404`, including a prototype made in the web app.

  - `candidate_id` · *string* · **required**

  The candidate to build, from the `candidate_ids` array of the prototype task. A value that isn't in that array returns `400`.

  - `name` · *string*

  A name for the task, up to 100 characters. It comes back in the task's `name` field. A longer name returns `400`.

#### `options`

Optional geometry settings. Each field has a calibrated default, so send only the fields you want to change.

  - `base_model` · *string* · default: `cherry-mx-1x1-r1`

  The keycap base to build on. The only value is `cherry-mx-1x1-r1`, a standard Cherry MX profile 1u keycap. Custom sizes aren't supported, and any other value returns `400`.

  - `head_size_mm` · *number* · default: `23`

  The size of the head along its longest dimension, in millimeters, from `10` to `40`. Meshy scales the head so its longest dimension matches this value. A value outside the range returns `400`.

  For a value above about `32.9`, Meshy might reduce the size so the head fits the base's protective footprint limit. The head can then come out smaller than you asked. The task object doesn't return the size Meshy applied. To check it, measure the bounding box of the `keycap-head` mesh in the model.

  - `vertical_offset_mm` · *number* · default: `0`

  The vertical offset to apply to the head before Meshy seats it on the base, in millimeters, from `-5` to `5`. A value outside the range returns `400`.

### Returns

The `result` field holds the ID of the new build task. [Get the task](#retrieve-a-keycap-task) or [stream it](#stream-a-keycap-task) until `status` is `SUCCEEDED`. Then download the GLB file from `model_urls.glb` and the OBJ bundle from `model_urls.obj_zip`.

> **Note:** Meshy exports the GLB file and the OBJ bundle at real-world scale in millimeters. Both use a Y-up coordinate system, with the front of the keycap facing +Z.

### Failure modes

  - `400 - Bad Request`

  The request can't run. For example:
  * `input_task_id` is missing or isn't a valid task ID.
  * The prototype task's status isn't `SUCCEEDED`. If it's still running, wait and retry. If it failed or was canceled, create a new prototype task.
  * The prototype task succeeded but has no candidates. Create a new prototype task.
  * `candidate_id` is missing, or isn't in the prototype task's `candidate_ids`. Send a value from that array.
  * A field in `options` is out of range, or `base_model` isn't an available value.

  The error message says which problem it found.

  - `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 API key, workspace, or member reached its credit limit.
  * The account is on the free plan.

  Check your credits and plan, then retry.

  - `404 - Not Found`

  `input_task_id` doesn't match any Keycap prototype task your account created with the API. A prototype made in the web app also returns `404`. Send the `result` ID from a prototype create response.

  - `429 - Too Many Requests`

  One of these limits was reached:
  * You sent more requests than your rate limit allows. Wait a few seconds, then retry. See [Rate limits](/api/rate-limits).
  * 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.

  - `500 - Internal Server Error`

  Meshy couldn't create the task because of a server error. Meshy refunds any credits it charged. Retry the request.

**cURL**

```bash
# Stage 2: build the chosen candidate into a 3D keycap
curl https://api.meshy.ai/openapi/creative-lab/keycap/v1/build \
  -X POST \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "input_task_id": "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef",
    "candidate_id": "0198c1b2-33f5-7d21-a4b7-8e9d0c1f2a3b",
    "options": {
      "base_model": "cherry-mx-1x1-r1",
      "head_size_mm": 23,
      "vertical_offset_mm": 0
    }
  }'
```

```javascript
import axios from 'axios'

const headers = { Authorization: `Bearer ${YOUR_API_KEY}` };

// Stage 2: build the chosen candidate into a 3D keycap
const payload = {
  input_task_id: "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef",
  candidate_id: "0198c1b2-33f5-7d21-a4b7-8e9d0c1f2a3b",
  options: {
    base_model: "cherry-mx-1x1-r1",
    head_size_mm: 23,
    vertical_offset_mm: 0,
  },
};

try {
  const response = await axios.post(
    'https://api.meshy.ai/openapi/creative-lab/keycap/v1/build',
    payload,
    { headers }
  );
  console.log(response.data);
} catch (error) {
  console.error(error);
}
```

```python
import requests

headers = {
    "Authorization": f"Bearer {YOUR_API_KEY}"
}

# Stage 2: build the chosen candidate into a 3D keycap
payload = {
    "input_task_id": "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef",
    "candidate_id": "0198c1b2-33f5-7d21-a4b7-8e9d0c1f2a3b",
    "options": {
        "base_model": "cherry-mx-1x1-r1",
        "head_size_mm": 23,
        "vertical_offset_mm": 0,
    },
}

response = requests.post(
    "https://api.meshy.ai/openapi/creative-lab/keycap/v1/build",
    headers=headers,
    json=payload,
)
response.raise_for_status()
print(response.json())
```

**Response**

```json
{
  "result": "019c9a52-7d18-7e2b-9f01-6e3b98c4d2af"
}
```

---

## GET /openapi/creative-lab/keycap/v1/(prototype|build)/:id -- Get a Keycap task

Returns a prototype or build task. The path must match the task's stage. A build task requested through `/prototype/:id` returns `404`, and so does a prototype task requested through `/build/:id`.

For the fields, see [The Keycap prototype task object](#the-keycap-prototype-task-object) and [The Keycap build task object](#the-keycap-build-task-object).

### Parameters

  - `id` · *path*

  The task ID from the create response.

### Returns

The [prototype task object](#the-keycap-prototype-task-object) or the [build task object](#the-keycap-build-task-object), matching the stage in the path.

### Failure modes

  - `400 - Bad Request`

  `id` isn't a valid task ID. Send the `result` ID from the create response.

  - `403 - Forbidden`

  Your team has **IP Filtering** turned on, and Meshy flagged the prototype task's image for third-party intellectual property. Build tasks and teams on the Enterprise plan don't get this error. Create a prototype task from an image you have the rights to use.

  - `404 - Not Found`

  No Keycap task with this ID belongs to your account, or the task's stage doesn't match the path. Check the ID, and use `/prototype` or `/build` to match the task.

  - `500 - Internal Server Error`

  Meshy couldn't run the intellectual property check. Retry the request.

**cURL**

```bash
# Prototype
curl https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype/019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

# Build
curl https://api.meshy.ai/openapi/creative-lab/keycap/v1/build/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af \
  -H "Authorization: Bearer ${YOUR_API_KEY}"
```

```javascript
import axios from 'axios'

const headers = { Authorization: `Bearer ${YOUR_API_KEY}` };

// Prototype
const prototypeId = '019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef';
const proto = await axios.get(
  `https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype/${prototypeId}`,
  { headers }
);
console.log(proto.data);

// Build
const buildId = '019c9a52-7d18-7e2b-9f01-6e3b98c4d2af';
const build = await axios.get(
  `https://api.meshy.ai/openapi/creative-lab/keycap/v1/build/${buildId}`,
  { headers }
);
console.log(build.data);
```

```python
import requests

headers = {
    "Authorization": f"Bearer {YOUR_API_KEY}"
}

# Prototype
prototype_id = "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef"
proto = requests.get(
    f"https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype/{prototype_id}",
    headers=headers,
)
proto.raise_for_status()
print(proto.json())

# Build
build_id = "019c9a52-7d18-7e2b-9f01-6e3b98c4d2af"
build = requests.get(
    f"https://api.meshy.ai/openapi/creative-lab/keycap/v1/build/{build_id}",
    headers=headers,
)
build.raise_for_status()
print(build.json())
```

**Prototype Response**

```json
{
  "id": "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef",
  "type": "creative-lab-keycap-prototype",
  "name": "",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1753142456000,
  "started_at": 1753142460000,
  "finished_at": 1753142516000,
  "expires_at": 1753401716000,
  "preceding_tasks": 0,
  "task_error": null,
  "consumed_credits": 12,
  "image_urls": [
    "https://assets.meshy.ai/***/design-1.png?Expires=***"
  ],
  "candidate_ids": [
    "0198c1b2-33f5-7d21-a4b7-8e9d0c1f2a3b"
  ]
}
```

**Build Response**

```json
{
  "id": "019c9a52-7d18-7e2b-9f01-6e3b98c4d2af",
  "type": "creative-lab-keycap-build",
  "name": "",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1753142600000,
  "started_at": 1753142610000,
  "finished_at": 1753143050000,
  "expires_at": 1753402250000,
  "preceding_tasks": 0,
  "task_error": null,
  "consumed_credits": 50,
  "model_urls": {
    "glb": "https://assets.meshy.ai/***/tasks/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/output/model.glb?Expires=***",
    "obj_zip": "https://assets.meshy.ai/***/tasks/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/output/model-obj.zip?Expires=***"
  },
  "process_image_urls": {
    "head_design": "https://assets.meshy.ai/***/head-design.png?Expires=***",
    "composite": "https://assets.meshy.ai/***/composite.png?Expires=***",
    "base_canvas": "https://assets.meshy.ai/***/base-canvas.png?Expires=***"
  }
}
```

---

## DELETE /openapi/creative-lab/keycap/v1/(prototype|build)/:id -- Delete a Keycap task

Cancels a Keycap task. Canceling a `PENDING` task refunds its credits. An `IN_PROGRESS` task is canceled without a refund, because a worker has already started it. A task with a final status (`SUCCEEDED`, `FAILED`, or `CANCELED`) can't be canceled.

The path must match the task's stage. For example, `DELETE` on `/prototype/:id` with a build task's ID returns `404`.

### Path parameters

  - `id` · *path*

  The ID of the task to cancel.

### Returns

`204 No Content` with an empty body.

### Failure modes

  - `400 - Bad Request`

  One of these applies:
  * `id` isn't a valid task ID. Send the `result` ID from the create response.
  * The task already has a final status (`SUCCEEDED`, `FAILED`, or `CANCELED`), so it can't be canceled.

  - `404 - Not Found`

  No Keycap task with this ID belongs to your account, or the task's stage doesn't match the path. Check the ID, and use `/prototype` or `/build` to match the task.

  - `500 - Internal Server Error`

  Meshy hit a server error while canceling the task, so the task might or might not be canceled. Get the task to check its `status` before you retry.

  **cURL**

  ```bash
  curl --request DELETE \
    --url https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype/019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef \
    -H "Authorization: Bearer ${YOUR_API_KEY}"
  ```

  ```javascript
  import axios from 'axios'

  const taskId = '019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef'
  const headers = { Authorization: `Bearer ${YOUR_API_KEY}` }

  try {
    await axios.delete(
      `https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype/${taskId}`,
      { headers }
    )
  } catch (error) {
    console.error(error)
  }
  ```

  ```python
  import requests

  task_id = "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef"
  headers = {
      "Authorization": f"Bearer {YOUR_API_KEY}"
  }

  response = requests.delete(
      f"https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype/{task_id}",
      headers=headers,
  )
  response.raise_for_status()
  ```

**Response**

```json
// Returns 204 No Content on success (empty body).
```

---

## GET /openapi/creative-lab/keycap/v1/(prototype|build)/:id/stream -- Stream a Keycap task

Streams a Keycap task's updates as Server-Sent Events (SSE). The path must match the task's stage. If it doesn't, for example a build task's ID at `/prototype/:id/stream`, the stream sends one `error` event with `status_code: 404` and closes.

### Parameters

  - `id` · *path*

  The task ID from the create response.

### Returns

A stream of [prototype](#the-keycap-prototype-task-object) or [build](#the-keycap-build-task-object) task objects. Each event has the full task object, as [Get a Keycap task](#retrieve-a-keycap-task) returns it. While the task is `PENDING` or `IN_PROGRESS`, its output fields are still empty (`null`, `[]`, or `{}`), and `finished_at` is `null`.

If **IP Filtering** blocks the task's result, the stream sends one `error` event in its place, with the `status_code` that a get request would return.

  **cURL**

  ```bash
  curl -N https://api.meshy.ai/openapi/creative-lab/keycap/v1/build/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/stream \
  -H "Authorization: Bearer ${YOUR_API_KEY}"
  ```

  ```javascript
  const response = await fetch(
    'https://api.meshy.ai/openapi/creative-lab/keycap/v1/build/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/stream',
    {
      headers: { Authorization: `Bearer ${YOUR_API_KEY}` }
    }
  );

  const reader = response.body.getReader();
  const decoder = new TextDecoder();
  let buffer = '';

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    buffer += decoder.decode(value, { stream: true });
    const lines = buffer.split('\n');
    buffer = lines.pop();

    for (const line of lines) {
      if (line.startsWith('data:')) {
        const data = JSON.parse(line.slice(5));
        console.log(data);

        if (['SUCCEEDED', 'FAILED', 'CANCELED'].includes(data.status)) {
          reader.cancel();
        }
      }
    }
  }
  ```

  ```python
  import requests
  import json

  headers = {
      "Authorization": f"Bearer {YOUR_API_KEY}",
      "Accept": "text/event-stream"
  }

  response = requests.get(
      'https://api.meshy.ai/openapi/creative-lab/keycap/v1/build/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/stream',
      headers=headers,
      stream=True
  )

  for line in response.iter_lines():
      if line:
          if line.startswith(b'data:'):
              data = json.loads(line.decode('utf-8')[5:])
              print(data)

              if data['status'] in ['SUCCEEDED', 'FAILED', 'CANCELED']:
                  break

  response.close()
  ```

  **Response Stream**

  ```javascript
  // Error event example (wrong stage or task not found)
  event: error
  data: {
    "status_code": 404,
    "message": "Task not found"
  }

  // Message event examples illustrate task progress.
  // Every frame is the full task object; fields not yet populated are null / empty.
  // The following PENDING frame is shortened to the fields that change.
  event: message
  data: {
    "id": "019c9a52-7d18-7e2b-9f01-6e3b98c4d2af",
    "progress": 0,
    "status": "PENDING"
  }

  event: message
  data: {
    "id": "019c9a52-7d18-7e2b-9f01-6e3b98c4d2af",
    "type": "creative-lab-keycap-build",
    "status": "SUCCEEDED",
    "progress": 100,
    "created_at": 1753142600000,
    "started_at": 1753142610000,
    "finished_at": 1753143050000,
    "expires_at": 1753402250000,
    "task_error": null,
    "consumed_credits": 50,
    "model_urls": {
      "glb": "https://assets.meshy.ai/***/tasks/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/output/model.glb?Expires=***",
      "obj_zip": "https://assets.meshy.ai/***/tasks/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/output/model-obj.zip?Expires=***"
    },
    "process_image_urls": {
      "head_design": "https://assets.meshy.ai/***/head-design.png?Expires=***"
    }
  }
  ```

---

## GET /openapi/creative-lab/keycap/v1/(prototype|build) -- List Keycap tasks

Returns your Keycap tasks of one stage, one page at a time. The path selects the stage. `/prototype` returns only prototype tasks, and `/build` returns only build tasks.

### Path parameters

  - `stage` · *path* · **required**

  The stage to list, `prototype` or `build`.

### Query parameters

  - `page_num` · *integer* · default: `1`

  The page to return, from `1` to `255`. `0` returns the first page. A value outside `0` to `255` returns `400`.

  - `page_size` · *integer* · default: `10`

  Number of tasks per page, up to `100`. A value from `101` to `255` returns 100 tasks, and `0` uses the default. A value outside `0` to `255` returns `400`.

  - `sort_by` · *string* · default: `-created_at`

  The sort order.

  Available values:
  * `-created_at`: newest first
  * `+created_at`: oldest first

### Returns

An array of [prototype task objects](#the-keycap-prototype-task-object) or [build task objects](#the-keycap-build-task-object), matching the stage in the path.

  **cURL**

  ```bash
  # List prototype tasks
  curl https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype?page_size=10 \
    -H "Authorization: Bearer ${YOUR_API_KEY}"

  # List build tasks
  curl https://api.meshy.ai/openapi/creative-lab/keycap/v1/build?page_size=10 \
    -H "Authorization: Bearer ${YOUR_API_KEY}"
  ```

  ```javascript
  import axios from 'axios'

  const headers = { Authorization: `Bearer ${YOUR_API_KEY}` }

  try {
    const { data } = await axios.get(
      'https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype',
      { headers, params: { page_size: 10 } }
    )
    console.log(data)
  } catch (error) {
    console.error(error)
  }
  ```

  ```python
  import requests

  headers = {
      "Authorization": f"Bearer {YOUR_API_KEY}"
  }

  response = requests.get(
      "https://api.meshy.ai/openapi/creative-lab/keycap/v1/prototype",
      headers=headers,
      params={"page_size": 10},
  )
  response.raise_for_status()
  print(response.json())
  ```

**Response (List Prototype Tasks)**

```json
[
  {
    "id": "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef",
    "type": "creative-lab-keycap-prototype",
    "name": "",
    "status": "SUCCEEDED",
    "progress": 100,
    "created_at": 1753142456000,
    "started_at": 1753142460000,
    "finished_at": 1753142516000,
    "expires_at": 1753401716000,
    "preceding_tasks": 0,
    "task_error": null,
    "consumed_credits": 12,
    "image_urls": [
      "https://assets.meshy.ai/***/design-1.png?Expires=***"
    ],
    "candidate_ids": [
      "0198c1b2-33f5-7d21-a4b7-8e9d0c1f2a3b"
    ]
  }
]
```

---

## The Keycap prototype task object
A prototype task generates one image of the finished keycap from a photo. To turn the design into a 3D keycap, pass the task's ID to the [build endpoint](#create-a-keycap-build-task) as `input_task_id`, with its `candidate_ids` entry as `candidate_id`.

### Properties

- `id` · *string*

  The task ID. Don't rely on its format.

- `type` · *string*

  The task type, always `creative-lab-keycap-prototype`.

- `name` · *string*

  The `name` you sent when you created the task, or `""` if you didn't send one.

- `status` · *string*

  The task's status.

  Available values:
  * `PENDING`: waiting in the queue
  * `IN_PROGRESS`: generating the result
  * `SUCCEEDED`: final, with the result
  * `FAILED`: final, with the reason in `task_error`
  * `CANCELED`: final, with no result

- `progress` · *integer*

  Percentage of the work done, from `0` to `100`. It's `0` until the task starts and `100` when it succeeds.

- `created_at` · *timestamp*

  Time the task was created, in Unix milliseconds.

- `started_at` · *timestamp*

  Time a worker started the task, in Unix milliseconds. `null` until then.

- `finished_at` · *timestamp*

  Time the task reached a final status, in Unix milliseconds. `null` until then.

- `expires_at` · *timestamp*

  Time the task's result expires, in Unix milliseconds. It's 3 days after `finished_at`, or 3 days after `created_at` until the task finishes. For Enterprise accounts, which keep API results indefinitely, it's about 100 years later. See [Asset retention](/api/asset-retention).

- `preceding_tasks` · *integer*

  The task's position in the queue while it's `PENDING`. `1` means it starts next. `0` after the task leaves the queue, and always `0` in list results.

- `task_error` · *object*

  Why the task failed. `null` unless `status` is `FAILED`. See [Errors](/api/errors#task-errors).

- `consumed_credits` · *integer*

  Number of credits charged for the task, after any refund. A request that returns an error isn't charged. A failed task is `0`, because Meshy refunds it. Canceling refunds a task only while it's `PENDING`. If Meshy can't read the charge, a get or stream response leaves the field out, and a list request returns `500`. In that case, retry the request.

- `image_urls` · *array of strings*

  Download URLs for the image of the finished keycap. The array has one URL after the task succeeds, and is empty until then. `image_urls[i]` shows the candidate in `candidate_ids[i]`.

  These URLs are for display. The build endpoint takes an entry from `candidate_ids`, not a URL. They're signed URLs, so fetch them without an `Authorization` header. They stay valid until `expires_at`, and getting the task again returns the same URLs.

- `candidate_ids` · *array of strings*

  IDs of the candidates, in the same order as `image_urls`. To build a candidate, send its ID as `candidate_id` in the build request. Don't rely on the format of these IDs.

<span id="example-keycap-prototype-task-object" />

**Example Keycap Prototype Task Object**

```json
{
  "id": "019c9a4e-2b31-7f6a-8c44-5d2a87b3c1ef",
  "type": "creative-lab-keycap-prototype",
  "name": "",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1753142456000,
  "started_at": 1753142460000,
  "finished_at": 1753142516000,
  "expires_at": 1753401716000,
  "preceding_tasks": 0,
  "task_error": null,
  "consumed_credits": 12,
  "image_urls": [
    "https://assets.meshy.ai/***/design-1.png?Expires=***"
  ],
  "candidate_ids": [
    "0198c1b2-33f5-7d21-a4b7-8e9d0c1f2a3b"
  ]
}
```

---

## The Keycap build task object
A build task generates the textured 3D keycap from a succeeded prototype task and one of its candidates. It generates the 3D model, colors it, seats and cuts it onto the keycap base, and then assembles and exports the keycap.

### Properties

- `id` · *string*

  The task ID. Don't rely on its format.

- `type` · *string*

  The task type, always `creative-lab-keycap-build`.

- `name` · *string*

  The `name` you sent when you created the task, or `""` if you didn't send one.

- `status` · *string*

  The task's status.

  Available values:
  * `PENDING`: waiting in the queue
  * `IN_PROGRESS`: generating the result
  * `SUCCEEDED`: final, with the result
  * `FAILED`: final, with the reason in `task_error`
  * `CANCELED`: final, with no result

- `progress` · *integer*

  Percentage of the work done, from `0` to `100`. It's `0` until the task starts and `100` when it succeeds.

- `created_at` · *timestamp*

  Time the task was created, in Unix milliseconds.

- `started_at` · *timestamp*

  Time a worker started the task, in Unix milliseconds. `null` until then.

- `finished_at` · *timestamp*

  Time the task reached a final status, in Unix milliseconds. `null` until then.

- `expires_at` · *timestamp*

  Time the task's result expires, in Unix milliseconds. It's 3 days after `finished_at`, or 3 days after `created_at` until the task finishes. For Enterprise accounts, which keep API results indefinitely, it's about 100 years later. See [Asset retention](/api/asset-retention).

- `preceding_tasks` · *integer*

  The task's position in the queue while it's `PENDING`. `1` means it starts next. `0` after the task leaves the queue, and always `0` in list results.

- `task_error` · *object*

  Why the task failed. `null` unless `status` is `FAILED`. See [Errors](/api/errors#task-errors).

- `consumed_credits` · *integer*

  Number of credits charged for the task, after any refund. A request that returns an error isn't charged. A failed task is `0`, because Meshy refunds it. Canceling refunds a task only while it's `PENDING`. If Meshy can't read the charge, a get or stream response leaves the field out, and a list request returns `500`. In that case, retry the request.

- `model_urls` · *object*

  Download URLs for the 3D model. Meshy exports the GLB file and the OBJ bundle at real-world scale in millimeters, Y-up, with the front of the keycap facing +Z.

  The model has meshes named `keycap-head` and `keycap-base`. When Meshy falls back to a pattern fill for the base, the model also has a `keycap-base-interior` mesh for the stem cavity. Don't assume the model has exactly two meshes.

  These are signed URLs, so fetch them without an `Authorization` header. They stay valid until `expires_at`, and getting the task again before then returns the same URLs. An expired URL can't be renewed, so download and store the files before then.

  - `glb` · *string*

  Download URL for the textured GLB file, `model.glb`.

  - `obj_zip` · *string*

  Download URL for the OBJ bundle, a ZIP file with `model.obj`, `model.mtl`, and the PNG textures that `model.mtl` uses. With a solid-color base, the only texture is `keycap-head.png`. With a patterned base, the ZIP file also has `keycap-base.png`.

- `process_image_urls` · *object*

  Download URLs for images from the build's steps, keyed by kind. Like `model_urls`, they're signed URLs, so fetch them without an `Authorization` header. They stay valid until `expires_at`, and getting the task again returns the same URLs.

  It can have these keys:
  * `head_design`: the design image of the chosen candidate, which the build turned into 3D. Always present.
  * `composite`: the image of the finished keycap for the chosen candidate, which the build painted the base from. Can be missing.
  * `base_canvas`: the painted keycap base. Can be missing.

  Meshy may add keys, so ignore a key you don't recognize.

<span id="example-keycap-build-task-object" />

**Example Keycap Build Task Object**

```json
{
  "id": "019c9a52-7d18-7e2b-9f01-6e3b98c4d2af",
  "type": "creative-lab-keycap-build",
  "name": "",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1753142600000,
  "started_at": 1753142610000,
  "finished_at": 1753143050000,
  "expires_at": 1753402250000,
  "preceding_tasks": 0,
  "task_error": null,
  "consumed_credits": 50,
  "model_urls": {
    "glb": "https://assets.meshy.ai/***/tasks/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/output/model.glb?Expires=***",
    "obj_zip": "https://assets.meshy.ai/***/tasks/019c9a52-7d18-7e2b-9f01-6e3b98c4d2af/output/model-obj.zip?Expires=***"
  },
  "process_image_urls": {
    "head_design": "https://assets.meshy.ai/***/head-design.png?Expires=***",
    "composite": "https://assets.meshy.ai/***/composite.png?Expires=***",
    "base_canvas": "https://assets.meshy.ai/***/base-canvas.png?Expires=***"
  }
}
```

---

## End-to-end example

The example runs the whole flow:

1. Create a prototype task from a photo.
2. Get the task until its `status` is `SUCCEEDED`.
3. Pick a candidate from `candidate_ids`.
4. Create a build task with that candidate.
5. Get the build task until its `status` is `SUCCEEDED`.
6. Download the GLB file and the OBJ bundle from `model_urls`.

The example picks the first candidate. In your app, show the `image_urls` entries to your users and let them choose. A chosen image's index in `image_urls` is the index of its ID in `candidate_ids`.

**cURL**

```bash
#!/usr/bin/env bash
set -euo pipefail

# Requires curl and jq. Point IMAGE_PATH at a local photo, or IMAGE_URL at a public one:
#   export MESHY_API_KEY=msy_...
#   export IMAGE_PATH=./portrait.jpg          # or: export IMAGE_URL=https://...
: "${MESHY_API_KEY:?export MESHY_API_KEY first}"
if [[ -z "${IMAGE_PATH:-}" && -z "${IMAGE_URL:-}" ]]; then
  echo "export IMAGE_PATH (local file) or IMAGE_URL (public url) first" >&2
  exit 1
fi

BASE="https://api.meshy.ai/openapi/creative-lab/keycap/v1"
AUTH="Authorization: Bearer $MESHY_API_KEY"

# api METHOD URL [curl args...] -> prints the response body, non-zero on failure.
# Note we do not use -f/--fail: it discards the body, and the body is the only
# place the reason appears.
api() {
  local method=$1 url=$2 out http_code body
  shift 2
  out=$(curl --silent --show-error --max-time 60 --write-out $'\n%{http_code}' \
    -X "$method" "$url" -H "$AUTH" "$@") || return 1
  http_code=${out##*$'\n'}
  body=${out%$'\n'*}
  if ((http_code >= 400)); then
    echo "HTTP $http_code for $url: $body" >&2
    return 1
  fi
  printf '%s' "$body"
}

# Each task gets its own 40-minute budget.
poll() {
  local kind=$1 id=$2 delay=5 task_status deadline
  deadline=$(($(date +%s) + 2400))
  while :; do
    if (($(date +%s) >= deadline)); then
      echo "gave up waiting for $kind $id" >&2
      return 1
    fi
    task_status=$(api GET "$BASE/$kind/$id" | jq -r '.status')
    echo "$kind: $task_status"
    case "$task_status" in
    SUCCEEDED) return 0 ;;
    FAILED | CANCELED) return 1 ;;
    esac
    sleep "$delay"
    delay=$((delay * 2 > 30 ? 30 : delay * 2))
  done
}

# Build the request body in a file. A base64 data URI must never go on the
# command line or into an exported variable - a photo of any real size will
# exceed the OS argument limit.
BODY=$(mktemp)
trap 'rm -f "$BODY"' EXIT
if [[ -n "${IMAGE_PATH:-}" ]]; then
  # Declare the real type: the API accepts JPEG, PNG and WebP.
  case "$(printf '%s' "${IMAGE_PATH##*.}" | tr 'A-Z' 'a-z')" in
    png) MIME=image/png ;;
    webp) MIME=image/webp ;;
    *) MIME=image/jpeg ;;
  esac
  {
    printf '{"image_url":"data:%s;base64,' "$MIME"
    base64 <"$IMAGE_PATH" | tr -d '\n'
    printf '"}'
  } >"$BODY"
else
  printf '{"image_url":"%s"}' "$IMAGE_URL" >"$BODY"
fi

# 1. Create the prototype task
PROTO_ID=$(api POST "$BASE/prototype" \
  -H 'Content-Type: application/json' --data-binary @"$BODY" | jq -r '.result')

# 2. Wait for the design render
poll prototype "$PROTO_ID"

# 3. Pick a candidate (first one here; show image_urls to a user in production)
CANDIDATE_ID=$(api GET "$BASE/prototype/$PROTO_ID" | jq -r '.candidate_ids[0]')

# 4. Create the build task
jq -n --arg p "$PROTO_ID" --arg c "$CANDIDATE_ID" \
  '{input_task_id: $p, candidate_id: $c}' >"$BODY"
BUILD_ID=$(api POST "$BASE/build" \
  -H 'Content-Type: application/json' --data-binary @"$BODY" | jq -r '.result')

# 5. Wait for the model (a build usually takes 3-7 minutes)
poll build "$BUILD_ID"

# 6. Download the artifacts. These are signed URLs: no Authorization header,
#    and they stay valid for 3 days after the task finishes.
TASK=$(api GET "$BASE/build/$BUILD_ID")
curl --silent --show-error --fail --max-time 900 \
  -o keycap.glb "$(jq -r '.model_urls.glb' <<<"$TASK")"
curl --silent --show-error --fail --max-time 900 \
  -o keycap-obj.zip "$(jq -r '.model_urls.obj_zip' <<<"$TASK")"
echo "Done: keycap.glb + keycap-obj.zip"
```

```python
# Requires the requests package:  pip install requests
import base64
import os
import time

import requests

BASE = "https://api.meshy.ai/openapi/creative-lab/keycap/v1"
REQUEST_TIMEOUT = 60  # per HTTP call
TASK_DEADLINE = 2400  # give up on a single task after 40 minutes

def env(name: str) -> str:
    value = os.environ.get(name)
    if not value:
        raise SystemExit(f"set {name} before running")
    return value

# Point IMAGE_PATH at a local photo, or IMAGE_URL at a public one:
#   export MESHY_API_KEY=msy_...
#   export IMAGE_PATH=./portrait.jpg        # or: export IMAGE_URL=https://...
HEADERS = {"Authorization": f"Bearer {env('MESHY_API_KEY')}"}

def source_image() -> str:
    path = os.environ.get("IMAGE_PATH")
    if path:
        # Encode here, in the process. A base64 data URI passed on a command
        # line or through an exported variable will exceed the OS argument
        # limit for a photo of any real size.
        # Declare the real type: the API accepts JPEG, PNG and WebP.
        mime = {"png": "image/png", "webp": "image/webp"}.get(
            os.path.splitext(path)[1].lower().lstrip("."), "image/jpeg")
        with open(path, "rb") as f:
            return f"data:{mime};base64," + base64.b64encode(f.read()).decode()
    if not os.environ.get("IMAGE_URL"):
        raise SystemExit("set IMAGE_PATH (local file) or IMAGE_URL (public url) first")
    return os.environ["IMAGE_URL"]

def check(resp: requests.Response) -> dict:
    # raise_for_status()'s message omits the response body, and the body is
    # where the reason is.
    if not resp.ok:
        raise RuntimeError(f"HTTP {resp.status_code} for {resp.url}: {resp.text[:500]}")
    return resp.json()

def poll(stage: str, task_id: str) -> dict:
    deadline = time.monotonic() + TASK_DEADLINE
    delay = 5
    while True:
        if time.monotonic() > deadline:
            raise TimeoutError(f"gave up waiting for {stage} {task_id}")
        data = check(requests.get(f"{BASE}/{stage}/{task_id}",
                                  headers=HEADERS, timeout=REQUEST_TIMEOUT))
        print(f"{stage}: {data['status']} ({data['progress']}%)")
        if data["status"] == "SUCCEEDED":
            return data
        if data["status"] in ("FAILED", "CANCELED"):
            raise RuntimeError(
                f"{stage} task {task_id} ended as {data['status']}: {data['task_error']}")
        time.sleep(delay)
        delay = min(delay * 2, 30)

# 1. Create the prototype task
prototype_id = check(requests.post(
    f"{BASE}/prototype", headers=HEADERS,
    json={"image_url": source_image()}, timeout=REQUEST_TIMEOUT,
))["result"]

# 2. Wait for the design render
prototype = poll("prototype", prototype_id)

# 3. Pick a candidate (first one here; show image_urls to a user in production)
candidate_id = prototype["candidate_ids"][0]

# 4. Create the build task
build_id = check(requests.post(
    f"{BASE}/build", headers=HEADERS,
    json={"input_task_id": prototype_id, "candidate_id": candidate_id},
    timeout=REQUEST_TIMEOUT,
))["result"]

# 5. Wait for the model (a build usually takes 3-7 minutes)
build = poll("build", build_id)

# 6. Download the artifacts. These are signed URLs: no Authorization header,
#    and they stay valid for 3 days after the task finishes.
for key, filename in (("glb", "keycap.glb"), ("obj_zip", "keycap-obj.zip")):
    with requests.get(build["model_urls"][key], stream=True, timeout=(60, 900)) as dl:
        if not dl.ok:
            raise RuntimeError(f"download {key} failed: HTTP {dl.status_code}")
        with open(filename, "wb") as f:
            for chunk in dl.iter_content(chunk_size=1 << 20):
                f.write(chunk)
    print(f"Saved {filename}")
```
