---
type: api
title: Create an APM agent key
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v8/operation/operation-createagentkey
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v8/operation/operation-createagentkey
products:
  - Kibana
---

# Create an APM agent key

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/apm/agent_keys`
- `POST` `/s/{space_id}/api/apm/agent_keys`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v8/authentication#basicauth)

## Description

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

Create a new agent key for APM.

## Request Body

`application/json`

- `name` (string) — required
  Agent name
- `privileges` ([] enum) — required
  Privileges configuration
  Values: `event:write`, `config_agent:read`

## Responses

#### `200`

Agent key created successfully

`application/json`

- `agentKey` (object)
  Agent key
  - `api_key` (string)
  - `encoded` (string)
  - `expiration` (integer)
  - `id` (string)
  - `name` (string)
#### `400`

Bad Request response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
#### `401`

Unauthorized response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
#### `403`

Forbidden response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
#### `500`

Internal Server Error response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
## Code Examples

#### Console

```console
POST /api/apm/agent_keys
```

#### curl

```curl
curl -X POST "https://{kibana_url}/api/apm/agent_keys" \
  -H "elastic-api-version: string" \
  -H "kbn-xsrf: true"
```

