> For the complete documentation index, see [llms.txt](https://docs.warpstream.com/warpstream/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.warpstream.com/warpstream/reference/api-reference/api-keys/create-v2.md).

# Create (v2)

Create a new API Key in the v2 key format.

This endpoint works like [Create](/warpstream/reference/api-reference/api-keys/create.md): 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.md#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.md) instead.

## Request

{% code overflow="wrap" %}

```bash
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"}
]}'
```

{% endcode %}

## Response

{% code overflow="wrap" %}

```json
{
  "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"
    }
  ]
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.warpstream.com/warpstream/reference/api-reference/api-keys/create-v2.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
