---
type: api
title: Generate a Logstash API key
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-post-fleet-logstash-api-keys
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-post-fleet-logstash-api-keys
products:
  - Kibana
---

# Generate a Logstash API key

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

## Paths

- `POST` `/api/fleet/logstash_api_keys`
- `POST` `/s/{space_id}/api/fleet/logstash_api_keys`

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

## Description

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

Generate an API key for Logstash to use with a Fleet output.<br/><br/>[Required authorization] Route required privileges: fleet-settings-all.

## Responses

#### `200`

Successful response

`application/json`

- `api_key` (string)
#### `400`

Bad Request

`application/json`

- `attributes` (object)
- `error` (string)
- `errorType` (string)
- `message` (string)
- `statusCode` (number)
## Code Examples

#### Console

```console
POST /api/fleet/logstash_api_keys
```

#### curl

```curl
curl -X POST "https://{kibana_url}/api/fleet/logstash_api_keys" \
  -H "kbn-xsrf: true"
```

## Response Examples

#### Post logstash api key

The generated Logstash API key

```json
{
  "api_key": "TiNAGG4BaaMdaH1tRfuU:KnR6yE41RrSowb0kQ0HWoA"
}
```

#### Generic error response

Example of a generic error response

```json
{
  "error": "Bad Request",
  "message": "An error message describing what went wrong",
  "statusCode": 400
}
```

