---
title: "Create an APM agent key"
method: POST
path: "/api/apm/agent_keys"
tags: ["APM agent keys"]
---

# Create an APM agent key

`POST /api/apm/agent_keys`

**Spaces method and path for this operation:**

<div><span class="operation-verb post">post</span>&nbsp;<span class="operation-path">/s/{space_id}/api/apm/agent_keys</span></div>

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Create a new agent key for APM.
The user creating an APM agent API key must have at least the `manage_own_api_key` cluster privilege and the APM application-level privileges that it wishes to grant.
After it is created, you can copy the API key (Base64 encoded) and use it to to authorize requests from APM agents to the APM Server.

## Headers

- `elastic-api-version` '2023-10-31', required
- `kbn-xsrf` string, required

## Request body

- APMUIAgentKeysObject
  - `name` string, required — The name of the APM agent key.
  - `privileges` string[], required — The APM agent key privileges. It can take one or more of the following values: * `event:write`, which is required for ingesting APM agent events. * `config_agent:read`, which is required for APM agents to read agent configuration remotely.

## Response `200`

Agent key created successfully

- APMUIAgentKeysResponse
  - `agentKey` object — Agent key
    - `api_key` string, required
    - `encoded` string, required
    - `expiration` integer
    - `id` string, required
    - `name` string, required

## Other responses

- `400` — Bad Request response
- `401` — Unauthorized response
- `403` — Forbidden response
- `500` — Internal Server Error response

---

[API](https://skmtc.net/elastic/apis/kibana-apis.md) · [All operations](https://skmtc.net/elastic/apis/kibana-apis/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/elastic/kibana-apis/versions/531c9e2a7d23/schema)
