> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/zec/instance/placement-group/createplacementgroup.md).

# CreatePlacementGroup

## 1. API Description

This API (CreatePlacementGroup) is used to create a placement group.

{% hint style="info" %}
**Notes**

* Permission must be activated before using the placement group feature. Please contact Support.
* The number of partitions (partitionNum) ranges from 2 to 5 and determines the maximum number of instances that can be associated with the placement group (number of partitions = maximum number of instances).
* The affinity (affinity) ranges from 1 to floor(partitionNum / 2), and defaults to floor(partitionNum / 2) when it is not specified. The affinity ensures that the number of virtual machines on a single physical machine does not exceed 1/2 of the number of partitions, which guarantees the high availability distribution logic.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type                                                                 | Description                                                                                                                                                                                                                                 |
| --------------- | -------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| zoneId          | Yes      | String                                                               | <p>ID of the availability zone that the placement group belongs to.</p><p>A placement group is managed at the zone level.</p><p>It can be obtained by calling <a href="/api-reference/zec/location/describezones.md">DescribeZones</a>.</p> |
| name            | Yes      | String                                                               | <p>Placement group name.</p><p>Length must be between 2 and 63 characters.</p><p>Must start and end with a letter or digit. Letters, digits, spaces, hyphens, slashes, and periods are supported.</p>                                       |
| partitionNum    | No       | Integer                                                              | <p>Number of partitions of the placement group.</p><p>The minimum value is 2.</p><p>It determines the maximum number of instances that can be associated with the placement group.</p><p>Value range: \[2, +)</p><p>Default value: 3</p>    |
| affinity        | No       | Integer                                                              | <p>Affinity of the placement group.</p><p>Valid values range from 1 to floor(partitionNum / 2).</p><p>Defaults to floor(partitionNum / 2) if not specified.</p><p>Value range: \[1, +)</p>                                                  |
| resourceGroupId | No       | String                                                               | Resource Group ID                                                                                                                                                                                                                           |
| tags            | No       | [TagAssociation](/api-reference/zec/datastructure.md#tagassociation) | Tags to associate with the placement group upon creation.                                                                                                                                                                                   |

## 3. Output Parameters

| Parameter Name   | Type   | Description                                                                                                           |
| ---------------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| requestId        | String | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p> |
| placementGroupId | String | ID of the successfully created placement group.                                                                       |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Create a placement group.**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreatePlacementGroup
<Common Request Params>

Request：
{
  "zoneId": "asia-east-1a",
  "name": "my-placement-group",
  "partitionNum": 3,
  "affinity": 1
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "placementGroupId": "placementgroup-xxxxxxxx"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](/api-reference/api-introduction/toolkit/api-sdk.md)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                                               | Description                                                        |
| ---------------- | -------------------------------------------------------- | ------------------------------------------------------------------ |
| 404              | INVALID\_ZONE\_NOT\_FOUND                                | Region does not exist.                                             |
| 400              | INVALID\_PLACEMENT\_GROUP\_PARTITION\_NUM\_EXCEED\_LIMIT | The number of partitions in the placement group exceeds the limit. |
