---
type: api
title: Create an agent policy
description: Create a new agent policy.<br/><br/>[Required authorization] Route required privileges: fleet-agent-policies-all.
url: https://www.elastic.co/elastic/docs-builder/docs/4948/api/doc/kibana/operation/operation-post-fleet-agent-policies
resource: https://www.elastic.co/elastic/docs-builder/docs/4948/api/doc/kibana/operation/operation-post-fleet-agent-policies
products:
  - Kibana
---

# Create an agent policy

Authentication: required

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

## Paths

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

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Description

Create a new agent policy.

## Required privileges

- Privileges: `fleet-agent-policies-all`

## Query string parameters

- `sys_monitoring` (boolean) — optional
  Whether to add the system integration to the new agent policy

## Header parameters

- `kbn-xsrf` (string) — required
  A required header to protect against CSRF attacks

## Request body

`application/json`

- `advanced_settings` (object) — optional
  - `agent_download_target_directory` (object) — optional
  - `agent_download_timeout` (object) — optional
  - `agent_features_disable_policy_change_acks_enabled` (object) — optional
  - `agent_features_include_tags_in_events_enabled` (object) — optional
  - `agent_internal` (object) — optional
  - `agent_limits_go_max_procs` (object) — optional
  - `agent_logging_files_interval` (object) — optional
  - `agent_logging_files_keepfiles` (object) — optional
  - `agent_logging_files_rotateeverybytes` (object) — optional
  - `agent_logging_level` (object) — optional
  - `agent_logging_metrics_period` (object) — optional
  - `agent_logging_to_files` (object) — optional
  - `agent_monitoring_runtime_experimental` (object) — optional
- `agent_features` (object[] · max items: 100) — optional
  - `enabled` (boolean) — required
  - `name` (string) — required
- `agentless` (object) — optional
  - `cloud_connectors` (object) — optional
    - `enabled` (boolean) — required
    - `target_csp` (enum) — optional
      Values: `aws`, `azure`, `gcp`
  - `cluster_id` (string) — optional
  - `resources` (object) — optional
    - `requests` (object) — optional
      - `cpu` (string) — optional
      - `memory` (string) — optional
- `data_output_id` (string · min length: 0) — optional — nullable
- `description` (string · min length: 0) — optional
- `download_source_id` (string · min length: 0) — optional — nullable — deprecated
  Use `download_source_ids` instead
- `download_source_ids` (string[] · max items: 3) — optional
- `fleet_server_host_id` (string · min length: 0) — optional — nullable
- `force` (boolean) — optional
- `global_data_tags` (object[] · max items: 100) — optional
  User defined data tags that are added to all of the inputs. The values can be strings or numbers.
  - `name` (string · min length: 0) — required
  - `value` (number | string) — required
- `has_agent_version_conditions` (boolean) — optional
- `has_fleet_server` (boolean) — optional
- `id` (string · min length: 0) — optional
- `inactivity_timeout` (number · min: 0 · default: 1209600) — optional
- `is_default` (boolean) — optional
- `is_default_fleet_server` (boolean) — optional
- `is_managed` (boolean) — optional
- `is_protected` (boolean) — optional
- `is_verifier` (boolean) — optional
- `keep_monitoring_alive` (boolean) — optional — nullable
  When set to true, monitoring will be enabled but logs/metrics collection will be disabled
- `min_agent_version` (string) — optional — nullable
- `monitoring_diagnostics` (object) — optional
  - `limit` (object) — optional
    - `burst` (number) — optional
    - `interval` (string) — optional
  - `uploader` (object) — optional
    - `init_dur` (string) — optional
    - `max_dur` (string) — optional
    - `max_retries` (number) — optional
- `monitoring_enabled` (enum[] · max items: 3) — optional
  Values: `logs`, `metrics`, `traces`
- `monitoring_http` (object) — optional
  - `buffer` (object) — optional
    - `enabled` (boolean · default: false) — optional
  - `enabled` (boolean) — optional
  - `host` (string) — optional
  - `port` (number · min: 0 · max: 65353) — optional
- `monitoring_output_id` (string · min length: 0) — optional — nullable
- `monitoring_pprof_enabled` (boolean) — optional
- `name` (string · min length: 1) — required
- `namespace` (string · min length: 1) — required
- `overrides` (map string to object) — optional — nullable
  Override settings that are defined in the agent policy. Input, output permissions and OpenTelemetry collector settings (receivers, exporters, processors, connectors, extensions, service) cannot be overridden. The override option should be used only in unusual circumstances and not as a routine procedure.
- `package_agent_version_conditions` (object[] · max items: 1000) — optional — nullable
  - `name` (string) — required
  - `title` (string) — required
  - `version_condition` (string) — required
- `required_versions` (object[] · max items: 100) — optional — nullable
  - `percentage` (number · min: 0 · max: 100) — required
    Target percentage of agents to auto upgrade
  - `version` (string) — required
    Target version for automatic agent upgrade
- `space_ids` (string[] · max items: 100) — optional
- `supports_agentless` (boolean) — optional — nullable — deprecated
  Indicates whether the agent policy supports agentless integrations. Deprecated in favor of the Fleet managed integrations API.
- `unenroll_timeout` (number · min: 0) — optional

## Responses

#### `200`

Successful response

`application/json`

- `item` (object)
  - `advanced_settings` (object)
    - `agent_download_target_directory` (object)
    - `agent_download_timeout` (object)
    - `agent_features_disable_policy_change_acks_enabled` (object)
    - `agent_features_include_tags_in_events_enabled` (object)
    - `agent_internal` (object)
    - `agent_limits_go_max_procs` (object)
    - `agent_logging_files_interval` (object)
    - `agent_logging_files_keepfiles` (object)
    - `agent_logging_files_rotateeverybytes` (object)
    - `agent_logging_level` (object)
    - `agent_logging_metrics_period` (object)
    - `agent_logging_to_files` (object)
    - `agent_monitoring_runtime_experimental` (object)
  - `agent_features` (object[] · max items: 100)
    - `enabled` (boolean)
    - `name` (string)
  - `agentless` (object)
    - `cloud_connectors` (object)
      - `enabled` (boolean)
      - `target_csp` (enum)
        Values: `aws`, `azure`, `gcp`
    - `cluster_id` (string)
    - `resources` (object)
      - `requests` (object)
        - `cpu` (string)
        - `memory` (string)
  - `agents` (number)
  - `agents_per_version` (object[] · max items: 1000)
    - `count` (number)
    - `version` (string)
  - `created_at` (string)
  - `data_output_id` (string) — nullable
  - `description` (string)
  - `download_source_id` (string) — nullable — deprecated
    Use `download_source_ids` instead
  - `download_source_ids` (string[] · max items: 3)
  - `fips_agents` (number)
  - `fleet_server_host_id` (string) — nullable
  - `global_data_tags` (object[] · max items: 100)
    User defined data tags that are added to all of the inputs. The values can be strings or numbers.
    - `name` (string)
    - `value` (number | string)
  - `has_agent_version_conditions` (boolean)
  - `has_fleet_server` (boolean)
  - `id` (string)
  - `inactivity_timeout` (number · min: 0 · default: 1209600)
  - `is_default` (boolean)
  - `is_default_fleet_server` (boolean)
  - `is_managed` (boolean)
  - `is_preconfigured` (boolean)
  - `is_protected` (boolean)
    Indicates whether the agent policy has tamper protection enabled. Defaults to `false`.
  - `is_verifier` (boolean)
  - `keep_monitoring_alive` (boolean) — nullable
    When set to true, monitoring will be enabled but logs/metrics collection will be disabled
  - `min_agent_version` (string) — nullable
  - `monitoring_diagnostics` (object)
    - `limit` (object)
      - `burst` (number)
      - `interval` (string)
    - `uploader` (object)
      - `init_dur` (string)
      - `max_dur` (string)
      - `max_retries` (number)
  - `monitoring_enabled` (enum[] · max items: 3)
    Values: `logs`, `metrics`, `traces`
  - `monitoring_http` (object)
    - `buffer` (object)
      - `enabled` (boolean · default: false)
    - `enabled` (boolean)
    - `host` (string)
    - `port` (number · min: 0 · max: 65353)
  - `monitoring_output_id` (string) — nullable
  - `monitoring_pprof_enabled` (boolean)
  - `name` (string · min length: 1)
  - `namespace` (string · min length: 1)
  - `overrides` (map string to object) — nullable
    Override settings that are defined in the agent policy. Input settings cannot be overridden. The override option should be used only in unusual circumstances and not as a routine procedure.
  - `package_agent_version_conditions` (object[] · max items: 1000) — nullable
    - `name` (string)
    - `title` (string)
    - `version_condition` (string)
  - `package_policies` (union anyOf)
    - **[]string**
    - **[]package_policy_response**
      - `additional_datastreams_permissions` (string[] · max items: 1000) — nullable
        Additional data stream permissions that will be added to the agent policy.
      - `agents` (number)
      - `cloud_connector_id` (string) — nullable
        ID of the cloud connector associated with this package policy.
      - `cloud_connector_name` (string · min length: 1 · max length: 255) — nullable
        Transient field for cloud connector name during creation.
      - `condition` (string · max length: 10000) — nullable
        Agent condition expression to evaluate whether to apply this integration to its inputs.
      - `created_at` (string)
      - `created_by` (string)
      - `description` (string)
        Package policy description
      - `elasticsearch` (object)
        - `privileges` (object)
          - `cluster` (string[] · max items: 100)
      - `enabled` (boolean)
      - `global_data_tags` (object[] · max items: 100) — nullable
        - `name` (string)
          The name of the custom field. Cannot contain spaces.
        - `value` (number | string)
          The value of the custom field.
      - `id` (string)
        Package policy unique identifier.
      - `inputs` (union anyOf)
        Package policy inputs.
        - **[]{ compiled_input, enabled, streams, … }**
          - `compiled_input` (object)
          - `condition` (string · max length: 10000) — nullable
            Agent condition expression to evaluate whether to apply this input.
          - `config` (map string to object)
            Package variable (see integration documentation for more information)
            Map values (object)
            - `frozen` (boolean)
            - `type` (string)
            - `value` (object)
          - `deprecated` (object)
            - `description` (string · max length: 4096)
            - `replaced_by` (map string to string)
              Map values (string · max length: 1024)
            - `since` (string · max length: 50)
          - `enabled` (boolean)
          - `id` (string)
          - `keep_enabled` (boolean)
          - `migrate_from` (string)
          - `name` (string)
          - `policy_template` (string)
          - `streams` (object[] · max items: 1000)
            - `compiled_stream` (object)
            - `condition` (string · max length: 10000) — nullable
              Agent condition expression to evaluate whether to apply this stream.
            - `config` (map string to object)
              Package variable (see integration documentation for more information)
              Map values (object)
              - `frozen` (boolean)
              - `type` (string)
              - `value` (object)
            - `data_stream` (object)
              - `dataset` (string)
              - `elasticsearch` (object)
                - `dynamic_dataset` (boolean)
                - `dynamic_namespace` (boolean)
                - `privileges` (object)
                  - `indices` (string[] · max items: 100)
              - `type` (string)
            - `deprecated` (object)
              - `description` (string · max length: 4096)
              - `replaced_by` (map string to string)
                Map values (string · max length: 1024)
              - `since` (string · max length: 50)
            - `enabled` (boolean)
            - `id` (string)
            - `keep_enabled` (boolean)
            - `migrate_from` (string)
            - `release` (enum)
              Values: `ga`, `beta`, `experimental`
            - `var_group_selections` (map string to string)
              Variable group selections. Maps var_group name to the selected option name within that group.
              Map values (string · max length: 1024)
            - `vars` (map string to object)
              Package variable (see integration documentation for more information)
              Map values (object)
              - `frozen` (boolean)
              - `type` (string)
              - `value` (object)
          - `type` (string)
          - `var_group_selections` (map string to string)
            Variable group selections. Maps var_group name to the selected option name within that group.
            Map values (string · max length: 1024)
          - `vars` (map string to object)
            Package variable (see integration documentation for more information)
            Map values (object)
            - `frozen` (boolean)
            - `type` (string)
            - `value` (object)
        - **string to object**
          Package policy inputs. Refer to the integration documentation to know which inputs are available.
          - `<string>` (object)
            - `condition` (string · max length: 10000) — nullable
              Agent condition expression to evaluate whether to apply this input.
            - `deprecated` (object)
              - `description` (string · max length: 4096)
              - `replaced_by` (map string to string)
                Map values (string · max length: 1024)
              - `since` (string · max length: 50)
            - `enabled` (boolean)
              Enable or disable that input. Defaults to `true` (enabled).
            - `streams` (map string to object)
              Input streams. Refer to the integration documentation to know which streams are available.
              Map values (object)
              - `condition` (string · max length: 10000) — nullable
                Agent condition expression to evaluate whether to apply this stream.
              - `deprecated` (object)
                - `description` (string · max length: 4096)
                - `replaced_by` (map string to string)
                  Map values (string · max length: 1024)
                - `since` (string · max length: 50)
              - `enabled` (boolean)
                Enable or disable that stream. Defaults to `true` (enabled).
              - `var_group_selections` (map string to string)
                Variable group selections. Maps var_group name to the selected option name within that group.
                Map values (string · max length: 1024)
              - `vars` (map string to anyOf)
                Input/stream level variable. Refer to the integration documentation for more information.
                Map values (union anyOf · default: null)
                Any of:
                - **[]string**
                - **string**
                - **[]number**
                - **number**
                - **boolean**
                - **{ id, isSecretRef }**
                  - `id` (string · max length: 255)
                  - `isSecretRef` (boolean)
            - `vars` (map string to anyOf)
              Input/stream level variable. Refer to the integration documentation for more information.
              Map values (union anyOf · default: null)
              Any of:
              - **[]string**
              - **string**
              - **[]number**
              - **number**
              - **boolean**
              - **{ id, isSecretRef }**
                - `id` (string · max length: 255)
                - `isSecretRef` (boolean)
      - `is_managed` (boolean)
      - `name` (string)
        Unique name for the package policy.
      - `namespace` (string · max length: 100)
        The package policy namespace. Leave blank to inherit the agent policy's namespace.
      - `onboarding_deployment_id` (string · max length: 256) — nullable
        ID of the cloud onboarding instance that manages this package policy. Set by Fleet, read-only.
      - `output_id` (string) — nullable
      - `overrides` (object) — nullable
        Override settings that are defined in the package policy. The override option should be used only in unusual circumstances and not as a routine procedure.
        - `inputs` (map string to object)
      - `package` (object)
        - `experimental_data_stream_features` (object[] · max items: 100)
          - `data_stream` (string · max length: 1024)
          - `features` (object)
            - `doc_value_only_numeric` (boolean)
            - `doc_value_only_other` (boolean)
            - `synthetic_source` (boolean)
            - `tsdb` (boolean)
        - `fips_compatible` (boolean)
        - `name` (string · max length: 255)
          Package name
        - `requires_root` (boolean)
        - `title` (string · max length: 255)
        - `version` (string · max length: 50)
          Package version
      - `package_agent_version_condition` (string)
      - `policy_id` (string) — nullable — deprecated
        ID of the agent policy which the package policy will be added to.
      - `policy_ids` (string[] · max items: 1000)
      - `revision` (number)
        Package policy revision.
      - `secret_references` (object[] · max items: 1000)
        - `id` (string)
      - `spaceIds` (string[] · max items: 100)
      - `supports_agentless` (boolean) — nullable
        Indicates whether the package policy belongs to an agentless agent policy.
      - `supports_cloud_connector` (boolean) — nullable
        Indicates whether the package policy supports cloud connectors.
      - `updated_at` (string)
      - `updated_by` (string)
      - `var_group_selections` (map string to string)
        Variable group selections. Maps var_group name to the selected option name within that group.
        Map values (string · max length: 1024)
      - `vars` (union anyOf)
        Package level variable.
        - **string to object**
          Package variable (see integration documentation for more information)
          - `<string>` (object)
            - `frozen` (boolean)
            - `type` (string)
            - `value` (object)
        - **string to anyOf**
          Input/stream level variable. Refer to the integration documentation for more information.
      - `version` (string)
        Package policy ES version.
  - `required_versions` (object[] · max items: 100) — nullable
    - `percentage` (number · min: 0 · max: 100)
      Target percentage of agents to auto upgrade
    - `version` (string)
      Target version for automatic agent upgrade
  - `revision` (number)
  - `schema_version` (string)
  - `space_ids` (string[] · max items: 100)
  - `status` (enum)
    Values: `active`, `inactive`
  - `supports_agentless` (boolean) — nullable
    Indicates whether the agent policy supports agentless integrations.
  - `unenroll_timeout` (number · min: 0)
  - `unprivileged_agents` (number)
  - `updated_at` (string)
  - `updated_by` (string)
  - `version` (string)
#### `400`

Bad Request

`application/json`

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

#### Console

```console
POST kbn:/api/fleet/agent_policies
{
  "description": "A sample agent policy",
  "monitoring_enabled": [
    "logs",
    "metrics"
  ],
  "name": "My agent policy",
  "namespace": "default"
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/fleet/agent_policies" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "A sample agent policy",
    "monitoring_enabled": [
      "logs",
      "metrics"
    ],
    "name": "My agent policy",
    "namespace": "default"
  }'
```

## Response examples

#### Post agent policy

`application/json`

The created agent policy

```json
{
  "item": {
    "description": "A sample agent policy",
    "id": "agent-policy-id-2",
    "is_managed": false,
    "is_protected": false,
    "name": "My agent policy",
    "namespace": "default",
    "revision": 1,
    "status": "active",
    "updated_at": "2024-01-15T10:00:00.000Z",
    "updated_by": "user1"
  }
}
```

#### Generic error response

`application/json`

Example of a generic error response

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

