# Create (v2)

Create a new API Key in the v2 key format.

This endpoint works like [Create](/warpstream/reference/api-reference/api-keys/create): it takes the same request and returns the same response. The difference is that the new key is created in the [v2 key format](/warpstream/reference/api-reference/api-keys#key-formats).

The key's secret, `key` in the response, is only returned by this request. WarpStream does not store the secret and it can't be retrieved later, so save it right away. If the secret is lost, delete this key and create a new one.

Serverless agent keys (`"virtual_cluster_type": "serverless"`) and MCP keys can't be created in the v2 key format, because WarpStream needs to read their secret later. For those keys, this endpoint returns a `hashed_key_unsupported` error. Use [Create](/warpstream/reference/api-reference/api-keys/create) instead.

## Request

```bash wrap
curl https://api.warpstream.com/api/v1/create_api_key_v2 \
-H 'warpstream-api-key: XXXXXXXXXX' \
-H 'Content-Type: application/json' \
-d '{"name":"example_agent_key", "access_grants": [
    {"principal_kind": "agent", "resource_kind": "virtual_cluster", "resource_id": "vci_1d4930d7_8e6d_4ad9_b27a_654ed4aaa3ee"}
]}'
```

## Response

```json wrap
{
  "id": "aki_007f0341_3ab3_457a_a513_2b2c9415582f",
  "name": "akn_example_agent_key",
  "key": "aks_v2_007f03413ab3457aa5132b2c9415582f_a51b1fb20ac4a3af549503bb08cd309672fcada1030c5a494850e87ce5d4c613",
  "created_at": "2026-10-15T09:36:06.781306362Z",
  "access_grants": [
    {
      "principal_kind": "agent",
      "resource_kind": "virtual_cluster",
      "resource_id": "vci_1d4930d7_8e6d_4ad9_b27a_654ed4aaa3ee"
    }
  ]
}
```