---
type: api
title: Create a Vega library item
description: "Creates a new Vega library item and returns its ID, full state, and metadata."
url: https://www.elastic.co/elastic/docs-builder/docs/5002/api/kibana/next/operation/operation-post-vega
resource: https://www.elastic.co/elastic/docs-builder/docs/5002/api/kibana/next/operation/operation-post-vega
products:
  - Kibana
---

# Create a Vega library item

Authentication: required

Availability: Planned

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

## Paths

- `POST` `/api/vega`
- `POST` `/s/{space_id}/api/vega`

#### 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

Creates a new Vega library item and returns its ID, full state, and metadata.

## Header parameters

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

## Request body

`application/json`

- `description` (string · min length: 0 · max length: 10000) — optional
  A short description of the Vega library item.
- `filters` (union oneOf[] · max items: 100) — optional
  Filters. Applied together with the dashboard filters to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
  - **condition**
    A filter that evaluates a single field condition such as equality, range, or existence.
    - `type` (enum) — required
      Values: `condition`
    - `condition` (union oneOf) — required
      A filter condition with strict operator/value type matching.
      - **is** (`operator: is`)
        Matches documents where `field` equals a single specified value.
        - `operator` (enum) — required
          Values: `is`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
        - `value` (union string | number | boolean) — required
          Single value to compare against the field.
      - **is_one_of** (`operator: is_one_of`)
        Matches documents where `field` equals any value in a provided list.
        - `operator` (enum) — required
          Values: `is_one_of`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
        - `value` (union string[] | number[] | boolean[]) — required
          Homogeneous array of values to match against the field.
      - **range** (`operator: range`)
        Matches documents where `field` falls within a specified numeric or date range.
        - `operator` (enum) — required
          Values: `range`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
        - `value` (object) — required
          Boundary values for a range comparison.
          - `format` (string) — optional
            Elasticsearch [date format](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/mapping-date-format) string applied when parsing date boundary values. For example, `strict_date_optional_time` or `epoch_millis`.
          - `gt` (number | string) — optional
            Greater than.
          - `gte` (number | string) — optional
            Greater than or equal to.
          - `lt` (number | string) — optional
            Less than.
          - `lte` (number | string) — optional
            Less than or equal to.
      - **exists** (`operator: exists`)
        Matches documents where `field` exists and contains a non-null value.
        - `operator` (enum) — required
          Values: `exists`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
  - **group**
    A filter that combines multiple conditions or nested groups using a logical `and` or `or` operator.
    - `type` (enum) — required
      Values: `group`
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `group` (object) — required
      Logical group that combines one or more conditions or nested groups.
      - `conditions` (union anyOf[]) — required — recursive
        Ordered list of conditions or nested groups combined by the group `operator`.
      - `operator` (enum) — required
        Logical operator applied across all entries in `conditions`. Use `and` to require all conditions, or `or` to require at least one.
        Values: `and`, `or`
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
  - **dsl**
    A filter expressed as a raw [Elasticsearch Query DSL](https://www.elastic.co/docs/reference/query-languages/querydsl) object, used for queries that cannot be represented by condition or group filters.
    - `type` (enum) — required
      Values: `dsl`
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `dsl` (map string to object) — required
      Elasticsearch Query DSL object passed directly to the query.
    - `field` (string) — optional
      Field name for scripted filters where the field cannot be extracted from the DSL query.
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
    - `params` (object) — optional
      Filter parameters metadata. May contain display values, formats, and parameters for scripted filters.
  - **spatial**
    A filter that applies an Elasticsearch geo query, used for geographic boundary and shape matching.
    - `type` (enum) — required
      Values: `spatial`
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `dsl` (map string to object) — required
      Elasticsearch geo query DSL object.
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
- `query` (object) — optional
  KQL or Lucene query. Applied together with the dashboard query to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
  - `expression` (string · min length: 0 · max length: 1000000) — required
    A query expression in KQL or Lucene syntax.
  - `language` (enum) — required
    Query language. Use `kql` for Kibana Query Language (KQL) or `lucene` for Lucene query syntax.
    Values: `kql`, `lucene`
- `spec` (union oneOf) — required
  The Vega or Vega-Lite specification. Use `{ "format": "hjson", "value": "<hjson-string>" }` for HJSON (comments and unquoted keys are preserved) or `{ "format": "json", "value": { ... } }` for a JSON object.
  - **HJSON spec** (`format: hjson`)
    - `format` (enum) — required
      Values: `hjson`
    - `value` (string · min length: 1 · max length: 1000000) — required
      The Vega or Vega-Lite specification in HJSON format. Comments and unquoted keys are preserved.
  - **JSON spec** (`format: json`)
    - `format` (enum) — required
      Values: `json`
    - `value` (map string to object) — required
      The Vega or Vega-Lite specification as a JSON object.
- `tags` (string[] · max items: 1000 · default: []) — optional
  Tag IDs associated with this library item.
- `title` (string · min length: 1 · max length: 1024) — required
  The Vega library item title.

## Responses

#### `201`

created

`application/json`

- `data` (object)
  - `description` (string · min length: 0 · max length: 10000)
    A short description of the Vega library item.
  - `filters` (union oneOf[] · max items: 100)
    Filters. Applied together with the dashboard filters to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
    Same options as `filters`
  - `query` (object)
    KQL or Lucene query. Applied together with the dashboard query to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
    - `expression` (string · min length: 0 · max length: 1000000)
      A query expression in KQL or Lucene syntax.
    - `language` (enum)
      Query language. Use `kql` for Kibana Query Language (KQL) or `lucene` for Lucene query syntax.
      Values: `kql`, `lucene`
  - `spec` (union oneOf)
    The Vega or Vega-Lite specification. Use `{ "format": "hjson", "value": "<hjson-string>" }` for HJSON (comments and unquoted keys are preserved) or `{ "format": "json", "value": { ... } }` for a JSON object.
    - **HJSON spec** (`format: hjson`)
      - `format` (enum)
        Values: `hjson`
      - `value` (string · min length: 1 · max length: 1000000)
        The Vega or Vega-Lite specification in HJSON format. Comments and unquoted keys are preserved.
    - **JSON spec** (`format: json`)
      - `format` (enum)
        Values: `json`
      - `value` (map string to object)
        The Vega or Vega-Lite specification as a JSON object.
  - `tags` (string[] · max items: 1000 · default: [])
    Tag IDs associated with this library item.
  - `title` (string · min length: 1 · max length: 1024)
    The Vega library item title.
- `id` (string)
  The unique ID of the Vega library item, as returned by the create or search endpoints.
- `meta` (object)
  - `created_at` (string)
    Timestamp when the object was created (ISO 8601).
  - `created_by` (string)
    User profile ID of the user who created the object.
  - `managed` (boolean)
    When `true`, the object is managed by Kibana and cannot be edited by users.
  - `owner` (string)
    Identifier of the plugin or team that owns this object.
  - `updated_at` (string)
    Timestamp when the object was last updated (ISO 8601).
  - `updated_by` (string)
    User profile ID of the user who last updated the object.
  - `version` (string)
    Internal version identifier for optimistic concurrency control.
#### `400`

invalid request

#### `403`

forbidden

#### `404`

not found

## Code examples

#### Console

```console
POST kbn:/api/vega
{
  "title": "Requests over time",
  "description": "Hourly request count from the sample web logs.",
  "spec": {
    "format": "hjson",
    "value": "{\n  $schema: https://vega.github.io/schema/vega-lite/v5.json\n  // Applies the dashboard time range, query, and filters\n  data: {\n    url: {\n      %context%: true\n      %timefield%: timestamp\n      index: kibana_sample_data_logs\n      body: {\n        size: 0\n        aggs: { hours: { date_histogram: { field: \"timestamp\", fixed_interval: \"1h\" } } }\n      }\n    }\n    format: { property: \"aggregations.hours.buckets\" }\n  }\n  mark: line\n  encoding: {\n    x: { field: \"key\", type: \"temporal\", title: null }\n    y: { field: \"doc_count\", type: \"quantitative\", title: \"Requests\" }\n  }\n}"
  }
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/vega" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "title": "Requests over time",
  "description": "Hourly request count from the sample web logs.",
  "spec": {
    "format": "hjson",
    "value": "{\n  $schema: https://vega.github.io/schema/vega-lite/v5.json\n  // Applies the dashboard time range, query, and filters\n  data: {\n    url: {\n      %context%: true\n      %timefield%: timestamp\n      index: kibana_sample_data_logs\n      body: {\n        size: 0\n        aggs: { hours: { date_histogram: { field: \"timestamp\", fixed_interval: \"1h\" } } }\n      }\n    }\n    format: { property: \"aggregations.hours.buckets\" }\n  }\n  mark: line\n  encoding: {\n    x: { field: \"key\", type: \"temporal\", title: null }\n    y: { field: \"doc_count\", type: \"quantitative\", title: \"Requests\" }\n  }\n}"
  }
}'
```

## Response examples

#### Create Vega library item response

`application/json`

Returns the generated ID, the full item state in `data`, and metadata.

```json
{
  "data": {
    "description": "Hourly request count from the sample web logs.",
    "spec": {
      "format": "hjson",
      "value": "{\n  $schema: https://vega.github.io/schema/vega-lite/v5.json\n  // Applies the dashboard time range, query, and filters\n  data: {\n    url: {\n      %context%: true\n      %timefield%: timestamp\n      index: kibana_sample_data_logs\n      body: {\n        size: 0\n        aggs: { hours: { date_histogram: { field: \u0022timestamp\u0022, fixed_interval: \u00221h\u0022 } } }\n      }\n    }\n    format: { property: \u0022aggregations.hours.buckets\u0022 }\n  }\n  mark: line\n  encoding: {\n    x: { field: \u0022key\u0022, type: \u0022temporal\u0022, title: null }\n    y: { field: \u0022doc_count\u0022, type: \u0022quantitative\u0022, title: \u0022Requests\u0022 }\n  }\n}"
    },
    "title": "Requests over time"
  },
  "id": "7c1d8e40-9b2f-11f0-a5c3-2f6e4b8d9a10",
  "meta": {
    "created_at": "2026-09-30T10:00:00.000Z",
    "managed": false,
    "updated_at": "2026-09-30T10:00:00.000Z",
    "version": "WzU5LDFd"
  }
}
```

