Skip to content

This page is available as Markdown at https://developers.klaviyo.com/en/v2025-01-15/reference/reporting.md. An index of every page is at https://developers.klaviyo.com/llms.txt.

KlaviyoKlaviyoDevelopers
v2025-01-15

You're reading the reference for API revision 2025-01-15. The latest revision is 2026-10-15. See this page in the latest revision.

Reporting

Before you begin

  • Check out the general API overview before getting started with specific endpoints.
  • Enable the following scopes on your private API key to use these endpoints:
    • flows:read
    • campaigns:read
    • forms:read
    • segments:read

The Reporting API allows you to fetch 1:1 matches of campaign, flow, form, or segment performance data shown in the Klaviyo UI. You can create two different types of reports:

  • Values report

    Returns requested statistics for a given campaign, flow, form, or segment over a provided time frame. For example, opens for a specified campaign over the last 12 months.

  • Series report

    Returns requested flow, form, or segment statistics broken down by a specified time interval (daily, hourly, weekly, or monthly) over a provided time frame. For example, weekly click rates for a flow email over the last 30 days.

The Query Metrics Aggregates endpoint

You may be using the Query Metric Aggregates endpoint to export reporting data for campaigns and flows. It’s important to note that data from the Query Metric Aggregates endpoint does not match the data reflected in the Klaviyo UI. While this endpoint allows you to filter and group campaign and flow data based on the time an event occurred, performance in the Klaviyo UI is calculated based on send date (the date that a campaign or flow message sends). Klaviyo recommends the Reporting API for this use case, which is built to fetch 1:1 matches of data shown in the Klaviyo UI.

Use cases

Here are some example use cases supported by the Reporting API:

  • Request 1:1 matches of campaign, flow, form, or segment performance data shown in the Klaviyo app.
  • Return the overall value of statistics for a given campaign, flow, form, or segment.
  • Request data by statistic, time frame, and metric ID.
  • Request performance data for flows triggered by a Klaviyo app's metrics, metrics that Klaviyo can identify as being created by a Klaviyo integration.
  • Filter data by channel and/or campaign ID.

You can find example code for all of these use cases in the api-examples repo.

Data model

Values report

A values report request can have the following:

  • type (required)

    The type of report you are requesting. Supported types include: - campaign-values-report - flow-values-report, flow-series-report - form-values-report, form-series-report - segment-values-report, segment-series-report

  • attributes

    • statistics (required) A list of statistics computed by Klaviyo (see Available statistics).

    • timeframe (required) An object that contains fields for setting a predefined time frame (key) or a custom time frame (start and end) to pull data from (max length: 1 year).

    • To set a predefined time frame, use:

    • To set a custom time frame, use:

      • start A datetime that represents the start of a custom time frame (e.g., 2024-05-08T00:00:00+00:00).
      • end A datetime that represents the end of a custom time frame. The end time rounds up to include the current hour (e.g., 00:00:00 and 00:30:00 both resolve to 00:59:59), so to include a full day, set end to the last second of that day (e.g., 2024-06-20T23:59:59+00:00).
    • conversion_metric_id (required) The ID of the conversion metric (e.g., the metric ID for Placed Order) used for calculating conversion-based statistics.

    • filter A JSON:API filter string for filtering the query.

The conversion_metric_id is used for calculating conversion-based statistics. Other statistics fetched in a campaign or flows report will include all values, regardless of whether or not some values triggered conversions. For example, a query for opens will return all opens, including opens that did not trigger a conversion.

Series report

A series report request follows the same data model as a values report request, but it differs in that it additionally contains an interval field for breaking down performance over a specified time frame by day, week, etc. You can set the interval to daily, hourly, weekly, or monthly.

If the interval is not specified, it will default to weekly.

Campaigns

Campaign values report

The request below to the Query Campaign Values endpoint queries opens and open rate statistics over the last 12 months.

By default, results are grouped by campaign_message_id, campaign_id, and send_channel. Use group_by with the default or group by:

  • campaign_id (required)
  • campaign_message_id (required)
  • campaign_message_name (optional)
  • send_channel (optional)
  • group (optional)
  • group_name (optional)
  • variation (optional)
  • variation_name (optional)
  • text_message_format (optional)
  • tag_name (optional)
  • tag_id (optional)

Filters can be applied to the following attributes:

Scalar attributes support the equals and contains-any operators:

  • campaign_id
  • campaign_message_id
  • campaign_message_name
  • send_channel
  • variation
  • variation_name
  • text_message_format

List attributes support the contains-any and contains-all operators:

  • tag_id
  • tag_name

Only one filter can be used per attribute. Only AND can be used as a combination operator. A maximum of 100 items can be used per list filter.

Request
curl --request POST \
     --url https://a.klaviyo.com/api/campaign-values-reports/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2024-10-15' \
     --data '
{
  "data": {
    "type": "campaign-values-report",
    "attributes": {
      "timeframe": {
        "key": "last_12_months"
      },
      "conversion_metric_id": "RESQ6t",
      "filter": "equals(campaign_id,\"01GMRWDSA0ARTAKE1SFX8JGXAY\")",
      "statistics": [
        "opens",
        "open_rate"
      ],
      "group_by": [
        "campaign_message_id",
        "campaign_id",
        "send_channel"
      ]
    }
  }
}
'
Response
{
  "data": {
    "type": "campaign-values-report",
    "attributes": {
      "results": [
        {
          "groupings": {
            "send_channel": "email",
            "campaign_id": "01GMRWDSA0ARTAKE1SFX8JGXAY",
            "campaign_message_id": "01GMRWDSA0ARTAKE1SFX8JGXAY"
          },
          "statistics": {
            "opens": 123,
            "open_rate": 0.8253
          }
        }
      ]
    },
    "relationships": {
      "campaigns": {
        "data": [
          {
            "type": "campaign",
            "id": "string"
          }
        ],
        "links": {
          "self": "string",
          "related": "string"
        }
      }
    },
    "links": {
      "self": "string"
    }
  }
}

Each object in the results array returned in the response includes groupings (send channel, campaign ID, and campaign message ID) and their associated statistics (number of opens and open rate).

Flows

Flow values report

The example below uses the Query Flow Values endpoint to query statistics (clicks, unique clicks, and unique conversions) over a custom time frame.

By default, results are grouped by flow_message_id, flow_id and send_channel. Use group_by with the default or group by:

  • flow_message_id (required)
  • flow_id (required)
  • flow_message_name (optional)
  • flow_name (optional)
  • send_channel (optional)
  • tag_id (optional)
  • tag_name (optional)
  • text_message_format (optional)
  • variation (optional)
  • variation_name (optional)

The supported attributes for filtering flow values are:

Scalar attributes support the equals and contains-any operators:

  • flow_message_id
  • flow_id
  • flow_message_name
  • flow_name
  • send_channel
  • text_message_format
  • variation
  • variation_name

List attributes support the contains-any and contains-all operators:

  • tag_id
  • tag_name

Only one filter can be used per attribute. Only AND can be used as a combination operator. A maximum of 100 items can be used per list filter.

Request
curl --request POST \
     --url https://a.klaviyo.com/api/flow-values-reports/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2024-10-15' \
     --data '
{
  "data": {
    "type": "flow-values-report",
    "attributes": {
      "timeframe": {
        "start": "2024-05-08T00:00:00+00:00",
        "end": "2024-06-20T00:00:00+00:00"

      },
      "conversion_metric_id": "RESQ6t",
      "filter":"equals(flow_id,\"XVTP5Q\")",
      "statistics": [
        "clicks",
        "clicks_unique",
        "conversion_uniques"
      ],
      "group_by": [
        "flow_message_id",
        "flow_id",
        "send_channel"
      ]
    }
  }
}
'
Response
{
  "data": {
    "type": "flow-values-report",
    "attributes": {
      "results": [
        {
          "groupings": {
            "flow_id": "XVTP5Q",
            "send_channel": "email",
            "flow_message_id": "01GMRWDSA0ARTAKE1SFX8JGXAY"
          },
          "statistics": {
            "clicks": 123,
            "clicks_unique": 98,
            "conversion_uniques": 3
          }
        },
        {
          "groupings": {
            "flow_id": "XVTP5Q",
            "send_channel": "email",
            "flow_message_id": "01GJTHNWVG93F3KNX71SJ4FDBB"
          },
          "statistics": {
            "clicks": 342,
            "clicks_unique": 208,
            "conversion_uniques": 10
          }
        }
      ]
    },
    "relationships": {
      "flows": {
        "data": [
          {
            "type": "flow",
            "id": "string"
          }
        ],
        "links": {
          "self": "string",
          "related": "string"
        }
      },
      "flow-messages": {
        "data": [
          {
            "type": "flow-message",
            "id": "string"
          }
        ],
        "links": {
          "self": "string",
          "related": "string"
        }
      }
    },
    "links": {
      "self": "string"
    }
  }
}

Flow series report

The example below uses the Query Flow Series endpoint to query statistics for clicks, delivery rate, and open rate on a weekly interval over the last 30 days.

By default, results are grouped by flow_message_id, flow_id and send_channel. Use group_by with the default or group by:

  • flow_message_id (required)
  • flow_id (required)
  • flow_message_name (optional)
  • flow_name (optional)
  • send_channel (optional)
  • tag_id (optional)
  • tag_name (optional)
  • text_message_format (optional)
  • variation (optional)
  • variation_name (optional)

The supported attributes for filtering flow series are:

Scalar attributes support the equals and contains-any operators:

  • flow_message_id
  • flow_id
  • flow_message_name
  • flow_name
  • send_channel
  • text_message_format
  • variation
  • variation_name

List attributes support the contains-any and contains-all operators:

  • tag_id
  • tag_name

Only one filter can be used per attribute. Only AND can be used as a combination operator. A maximum of 100 items can be used per list filter.

Request
curl --request POST \
     --url https://a.klaviyo.com/api/flow-series-reports/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2024-10-15' \
     --data '
{
  "data": {
    "type": "flow-series-report",
    "attributes": {
      "timeframe": {
        "key": "last_30_days"
      },
      "interval": "weekly",
      "conversion_metric_id": "RESQ6t",
      "filter": "equals(flow_id,\"XVTP5Q\")",
      "statistics": [
        "clicks",
        "delivery_rate",
        "open_rate"
      ],
      "group_by": [
        "flow_message_id",
        "flow_id",
        "send_channel"
      ]
    }
  }
}
'
Response
{
  "data": {
    "type": "flow-series-report",
    "attributes": {
      "results": [
        {
          "groupings": {
            "flow_id": "XVTP5Q",
            "send_channel": "email",
            "flow_message_id": "01GMRWDSA0ARTAKE1SFX8JGXAY"
          },
          "statistics": {
            "clicks": [
              123,
              156,
              144
            ],
            "delivery_rate": [
              1.00,
              0.56,
              0.84
            ],
            "open_rate": [
              0.8253,
              0.8722,
              0.8398
            ]
          }
        },
        {
          "groupings": {
            "flow_id": "XVTP5Q",
            "send_channel": "email",
            "flow_message_id": "01GJTHNWVG93F3KNX71SJ4FDBB"
          },
          "statistics": {
            "clicks": [
              123,
              156,
              144
            ],
            "delivery_rate": [
              1.00,
              0.56,
              0.84
            ],
            "open_rate": [
              0.8253,
              0.8722,
              0.8398
            ]
          }
        }
      ],
      "date_times": [
        "2024-01-05T00:00:00+00:00",
        "2024-01-06T00:00:00+00:00",
        "2024-01-07T00:00:00+00:00"
      ]
    },
    "relationships": {
      "flows": {
        "data": [
          {
            "type": "flow",
            "id": "string"
          }
        ],
        "links": {
          "self": "string",
          "related": "string"
        }
      },
      "flow-messages": {
        "data": [
          {
            "type": "flow-message",
            "id": "string"
          }
        ],
        "links": {
          "self": "string",
          "related": "string"
        }
      }
    },
    "links": {
      "self": "string"
    }
  }
}

Forms

A form is represented by the following:

  • form_id The unique alphanumeric value identifying a single form. Use the equals operator to return a single form_id, or the any operator to return a list of matching form_ids.
  • form_version_id The unique alphanumeric value identifying the version for a single form

Results are grouped by form_id by default. Use group_by with the default or add form_version_id to enable form version reporting.

The supported attributes for filtering include both form_id and form_version_id.

Form values report

The Query Forms Values endpoint returns an array of objects that show a form's performance statistics.

Request
curl --request POST \
     --url https://a.klaviyo.com/api/form-values-reports/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2026-10-15' \
     --data '
{
  "data": {
    "type": "form-values-report",
    "attributes": {
      "timeframe": {
        "key": "last_12_months"
      },
      "filter": "any(form_id,[\"abc123\",\"def456\" ])",
      "statistics": [
          "viewed_form",
          "submits",
          "submit_rate"
      ],
      "group_by": [
          "form_id",
          "form_version_id"
      ]
    }
  }
}'
Response
{
  "data": {
    "type": "form-values-report",
    "attributes": {
      "results": [
        {
          "groupings": {
            "form_id": "abc123"
            "form_version_id": "012tuy"
          },
          "statistics": {
            "viewed_form": 90,
            "submits": 9,
            "submit_rate": 0.10
          }
        },
        {
          "groupings": {
            "form_id": "abc123"
            "form_version_id": "765ghi"
          },
          "statistics": {
            "viewed_form": 10,
            "submits": 1,
            "submit_rate": 0.10
          }
        },
        {
          "groupings": {
            "form_id": "def456",
            "form_version_id": "789jkl"
          },
          "statistics": {
            "viewed_form": 200,
            "submits": 10,
            "submit_rate": 0.05
          }
        }
      ]
    }
  }
}

Form series report

The Query Forms Series endpoint returns an array of objects that show performance for individual forms broken down by time series.

For each statistic included in the request, the response outputs a series of dates and the statistic’s corresponding values.

For example:

json
"viewed_form": {
              "2024-03-01": 20,
              "2024-03-02": 25,
              "2024-03-03": 30
					}

For the viewed_form statistic, form views were captured on three dates within the given time frame. Each date in the array corresponds to an integer, representing the total number of form views.

Request
curl --request POST \
     --url https://a.klaviyo.com/api/form-series-reports/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2026-10-15' \
     --data '
{
  "data": {
    "type": "form-series-report",
    "attributes": {
      "timeframe": {
        "key": "last_3_months"
      },
      "interval": "monthly",
      "filter": "equals(form_id,\"abc123\")",
      "statistics": [
        "viewed_form",
        "submits",
        "submit_rate"
      ]
    }
  }
}'
Response
{
  "data": {
    "type": "form-series-report",
    "attributes": {
      "results": [
        {
          "groupings": {
            "form_id": "01GMRWDSA0ARTAKE1SFX8JGXAY"
          },
          "statistics": {
            "viewed_form": {
              "2024-03-01": 20,
              "2024-04-01": 20,
              "2024-05-01": 20
            },
            "submits": {
              "2024-03-01": 2,
              "2024-04-01": 2,
              "2024-05-01": 2
            },
            "submit_rate": {
              "2024-03-01": 0.1,
              "2024-04-01": 0.1,
              "2024-05-01": 0.1
            }
          }
        }]
    }
}

Segments

A segment is represented by the following:

  • segment_id The unique alphanumeric value identifying a segment. Use the equals operator to return a single segment_id, or the any operator to return a list of matching segment_ids.

The supported attributes for filtering include: segment_id.

Segment values report

The Query Segments Values endpoint returns an array of objects that shows performance statistics for a single segment.

Request
 curl --request POST \
 --url https://a.klaviyo.com/api/segment-values-reports/ \
 --header 'Authorization: Klaviyo-API-Key <API-KEY>' \
 --header 'accept: application/json' \
 --header 'content-type: application/json' \
 --header 'revision: 2026-10-15' \
 --data '
 {
  "data": {
    "type": "segment-values-report",
    "attributes": {
      "statistics": [
        "total_members",
        "members_added",
        "members_removed",
        "net_members_changed"
      ],
      "timeframe": {
        "key": "last_7_days"
      },
      "filter": "equals(segment_id,\"RpKvCF\")"
    }
  }
}'
Response
{
  "data": {
    "type": "segment-values-report",
    "id": "b85c66bb-495d-479b-8425-3ffb7f298f60",
    "attributes": {
      "results": [
        {
          "groupings": {
            "segment_id": "RpKvCF"
          },
          "statistics": {
            "total_members": 79,
            "members_added": 79,
            "members_removed": 0,
            "net_members_changed": 79
          }
        }
      ]
    }
  },
  "links": {
    "self": "<https://a.klaviyo.com/api/segment-values-reports/">
  }
}

Segment series report

The Query Segments Series endpoint returns an array of objects that each show performance for a single segment over a given time series.

Request
curl --request POST \
     --url https://a.klaviyo.com/api/segment-series-reports/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2026-10-15' \
     --data '
{
  "data": {
    "type": "segment-series-report",
    "attributes": {
      "statistics": [
        "total_members",
        "members_added"
      ],
      "timeframe": {
        "key": "last_7_days"
      },
      "filter": "equals(segment_id,\"RpKvCF\")",
      "interval": "daily"
    }
  }
}'
Response
{
  "data": {
    "type": "segment-series-report",
    "id": "7bbe2230-3f89-42e7-af21-a31da4eb8b15",
    "attributes": {
      "results": \[
        {
          "groupings": {
            "segment_id": "RpKvCF"
          },
          "statistics": {
            "total_members": [
              0,
              0,
              79,
              79,
              79,
              79,
              79,
              79
            ],
            "members_added": [
              0,
              0,
              79,
              0,
              0,
              0,
              0,
              0
            ]
          }
        }
      ],
      "date_times": [
        "2024-07-30T00:00:00+00:00",
        "2024-07-31T00:00:00+00:00",
        "2024-08-01T00:00:00+00:00",
        "2024-08-02T00:00:00+00:00",
        "2024-08-03T00:00:00+00:00",
        "2024-08-04T00:00:00+00:00",
        "2024-08-05T00:00:00+00:00",
        "2024-08-06T00:00:00+00:00"
      ]
    }
  },
  "links": {
    "self": "<https://a.klaviyo.com/api/segment-series-reports/">
  }
}

Available statistics

Statistic Formula
average_order_value Conversion value / Conversion
bounce_rate (Bounced emails + Bounced pushes) / (Received emails + Received pushes + Bounced emails + Bounced pushes)
bounced Email bounces + Push bounces
bounced_or_failed Bounced emails + Failed SMS + Bounced pushes
bounced_or_failed_rate (Bounced emails + Failed SMS + Bounced pushes) / (Received emails + Received SMS + Received pushes + Bounced emails + Failed SMS + Bounced pushes)
click_rate (Unique email clicks + Unique SMS clicks) / (Received emails + Received SMS)
click_to_open_rate Unique email clicks / Unique email opens
clicks Email clicks + SMS clicks
clicks_unique Unique email clicks + Unique SMS clicks
conversion_rate Unique conversions / (Received emails + Received SMS + Received pushes)
conversion_uniques Count of unique conversions
conversion_value Sum of the value for the provided conversion metric (e.g., the sum of transaction totals from Placed Order events)
conversions Count of events for the provided conversion metric (e.g., the count of Placed Order events)
delivered Received emails + Received SMS + Received pushes
delivery_rate (Received emails + Received SMS + Bounced pushes) / (Received emails + Received SMS + Received pushes + Bounced emails + Failed SMS + Bounced pushes)
failed Failed SMS
failed_rate Failed SMS / (Received SMS + Failed SMS)
open_rate (Unique email opens + Unique push opens) / (Received emails + Received push uniques)
opens Email opens + Push opens
opens_unique Unique email opens + Unique push opens
recipients Received emails + Received SMS + Received pushes + Bounced emails + Failed SMS + Bounced pushes
revenue_per_recipient Conversion value / (Received emails + Received SMS + Received pushes)
spam_complaint_rate Email spam / Received emails
spam_complaints Count of spam complaints
unsubscribe_rate (Unique email unsubscribes + Unique SMS unsubscribes) / (Received emails + Received SMS)
unsubscribe_uniques Count of unique unsubscribes
unsubscribes Count of unsubscribes
viewed_form The total number of times the form was viewed.
viewed_form_uniques The number of times a form was viewed by unique users.
submits The total number of form submissions.
submit_rate The rate of form submissions over form views.
closed_form The total number of times a form was closed.
closed_form_uniques The number of times a form was closed by unique users.
qualified_form The total number of times a user qualified to view the form (such as in an A/B testing scenario).
qualified_form_uniques The number of times a unique user was qualified to view the form.
viewed_form_step The total number of times a form step is viewed by a user.
viewed_form_step_uniques The number of times a form step is viewed by unique users.
submitted_form_step The total number of times a form step is completed by a user.
submitted_form_step_uniques The number of times a form step is completed by unique users.
total_members The total number of profiles included in the segment.
members_added Profiles added to the segment
members_removed Profiles removed from the segment.
net_members_changed Net number of profiles changed.
message_segment_count_sum The total number of text message segments consumed.
text_message_credit_usage_amount The total number of text message credits (i.e. sms_credits) consumed.
text_message_roi Conversion Value / (Credit Usage * Average Cost per Credit)
text_message_spend The total text message spend in USD.

Available time frames

Time frame Description
today Returns same day data. Will respect the timezone of the account.
yesterday Returns data from the day before. Will respect the timezone of the account.
this_week Returns data from the current calendar week (Monday to Sunday).
last_7_days Returns data from the past 7 days (including the day the user makes the call).
last_week Returns data from the previous calendar week (Monday to Sunday).
this_month Returns data from the current month.
last_30_days Returns data from the last 30 days regardless of month.
last_month Returns data from the previous calendar month.
last_90_days Returns data from the last 90 days regardless of month.
last_3_months Returns data from the 3 previous months, (including the month the user makes the call).
last_365_days Returns data from the last 365 days regardless of year (including the current month).
last_12_months Returns data from the 12 previous months (excluding the current month).
this_year Returns all data from the current calendar year.
last_year Returns all data from the previous calendar year.

Common errors

4XX errors indicate a bad request, which can result from the following issues:

  • Missing fields for a time frame, or including too many time frame fields.
  • Filtering for more than 100 forms in a single request.
  • Passing in an invalid or unsupported statistic.
  • Requesting a time frame that is too long. The maximum supported time frame is 1 year, up to June 1, 2023.
  • Using an invalid filter or an unsupported operator.
  • Filtering for the same attribute more than once in a single request.
  • Grouping with group_by: ["form_version_id"] without including the form_id.

503 errors with Retry-After header specified are returned in response to temporary service outages. The Retry-After header indicates the number of seconds to wait before retrying the request.

Example error response

json
{
	"errors": [
		{
			"id": "51cd68be-29df-4229-ac1f-0f76c4ecb75e",
			"status": 400,
			"code": "invalid",
			"title": "Invalid input.",
			"detail": "Can group by form_version_id only if form_id are also passed in together",
			"source": {
				"pointer": "/data/attributes/group_bys"
			},
			"links": {},
			"meta": {}
		}
	]
}

K-SQL Ask API overview (revision 2026-10-15.pre)

Before you begin

Check out our general API overview before getting started with specific endpoints.

The K-SQL Ask API lets you ask a question about your Klaviyo account data in plain language and get a plain-language answer back. K-SQL turns your question into read-only queries over your account's data, runs them, and summarizes the results. The result sets behind the answer are included in the response so you can see how it was reached.

Use cases

Here are some example use cases supported by the K-SQL Ask API:

  • Answer ad hoc questions about your account data without writing queries, for example, "How many orders were placed last week?"
  • Add plain-language data questions to your own internal tools or assistants.
  • Show the figures behind an answer by displaying the returned result sets next to it.

Required scopes

You don't need every scope to call the endpoint. An answer only draws on data that your key's scopes allow, so a key with fewer scopes gets answers based on less of your account's data.

Scope Data it makes available to answers
campaigns:read Campaigns
catalogs:read Catalogs
events:read Events
lists:read Lists
metrics:read Metrics
profiles:read Profiles
segments:read Segments

How it works

  1. You send a question to the Ask Analytics Question endpoint.
  2. K-SQL decides which data it needs and runs read-only queries against it.
  3. You receive an answer, along with the result sets that support it.

If your question is too ambiguous to answer, you receive a clarifying question instead of an answer. Ask again with more detail. Each response has a status that tells you which case you're in:

Status Meaning
success answer contains the plain-language answer.
clarification answer contains a question for you. result_sets is empty.

Ask Analytics Question

Send a POST request to /api/ksql-ask with your question.

The request supports the following attributes:

Attribute Type Description
question string Required. The question to ask, in 1 to 2000 characters.
max_rows integer The maximum number of rows to return in each result set, from 1 to 1000. Defaults to 100.
Request
curl --request POST \
  --url https://a.klaviyo.com/api/ksql-ask \
  --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
  --header 'accept: application/vnd.api+json' \
  --header 'content-type: application/vnd.api+json' \
  --header 'revision: 2026-10-15.pre' \
  --data '
{
  "data": {
    "type": "ksql-ask",
    "attributes": {
      "question": "How many orders were placed last week?",
      "max_rows": 100
    }
  }
}'
Response
{
  "data": {
    "type": "ksql-ask",
    "id": "5b6e9c0a-3f4d-4e57-9a38-2c1f6d7b8e90",
    "attributes": {
      "status": "success",
      "answer": "42 orders were placed last week.",
      "result_sets": [
        {
          "columns": [
            {
              "name": "order_count",
              "type": "long"
            }
          ],
          "rows": [
            [
              42
            ]
          ],
          "row_count": 1,
          "rows_returned": 1,
          "completeness": "complete",
          "description": "Number of orders placed last week.",
          "sql": "SELECT count(*) FROM klaviyo.orders",
          "caveats": []
        }
      ],
      "warnings": []
    }
  }
}

The response id identifies this request.

Clarifying questions

When a question is too ambiguous to answer, the response has status set to clarification and answer holds a question for you. Send a new request with a more specific question. For example, if you send the question "How did my last campaign do?", the response asks which measure you want:

Response
{
  "data": {
    "type": "ksql-ask",
    "id": "0c8d2f61-7a19-4b3e-8e54-6f2a9d1b3c47",
    "attributes": {
      "status": "clarification",
      "answer": "Which measure do you want to see for your last campaign: open rate, click rate, or revenue?",
      "result_sets": [],
      "warnings": []
    }
  }
}

You can then ask again with the detail included, for example, "What was the click rate of my last campaign?"

Understanding the response

Each response has the following attributes:

  • status

    Either success or clarification.

  • answer

    The plain-language answer when status is success, or a clarifying question when status is clarification.

  • result_sets

    The result sets that support the answer. This is always empty when status is clarification, and it can be empty when status is success if the answer didn't require running a query.

  • warnings

    Caveats that change how you should read answer and result_sets, for example, a sampled result set or rows left out by a cap. Show these alongside the answer rather than discarding them.

Each result set has the following attributes:

  • columns

    The result set's columns, each with a name and a type. The type is one of boolean, long, double, string, timestamptz, or unknown.

  • rows

    The result rows. Each row is a list of values in the same order as columns. A value is a boolean for boolean columns, a number for long and double columns, and a string for every other type. A missing value is null.

  • row_count and rows_returned

    row_count is the number of rows in the query's result. rows_returned is the number of rows included in rows, which is lower than row_count when rows were left out by a cap.

  • completeness

    Whether the result set contains everything its query matched. complete means it does. sample means the result may be larger than what the query returned, which is common for list-style questions. truncated means the result reached the maximum result size.

  • description

    A short plain-language description of what the result set contains.

  • sql

    The K-SQL query that produced the result set, so you can see how the figures were derived. It is for explanation only. K-SQL is an internal dialect, and there is no endpoint that runs it. Don't parse it, store it, or build on its syntax.

  • caveats

    Caveats that apply to this result set, in plain language. The same sentences also appear in warnings.

Limits

  • Question length: 1 to 2000 characters.
  • Rows per result set: up to 1000. Use max_rows to request fewer.
  • Rate limits: burst 1/s and steady 15/m.
  • Composer AI Credits: each request uses Composer AI Credits from your account. See Common errors for what happens when an account runs out.
  • Response time: answers can take several seconds, so allow for this in your client's request timeout.

Common errors

The following errors can occur:

  • 400: the question can't be answered as asked. Rephrase it and try again.
  • 403 with code insufficient_ai_credits: the account has no Composer AI Credits left for the current billing period. Increase the account's AI usage limit to continue asking questions. Retrying doesn't help until credits are available.
  • 403 with code forbidden: the account isn't enabled for this API.
  • 503, including codes deadline_exceeded and unverified: a reliable answer couldn't be produced. Retry the request, and honor the Retry-After header when it's present. The Retry-After header indicates the number of seconds to wait before retrying.
  • 500 with code answer_failed: the question couldn't be answered because of a server error.

Example error response

json
{
  "errors": [
    {
      "id": "7d3f1b52-9c64-4e08-a1d7-5e2b8c4f6a93",
      "status": 403,
      "code": "insufficient_ai_credits",
      "title": "Forbidden.",
      "detail": "This account has no Composer AI Credits left for the current billing period. Increase the account's AI usage limit to continue asking questions.",
      "source": {
        "pointer": "/data"
      },
      "links": {},
      "meta": {
        "available_credits": "0"
      }
    }
  ]
}

Additional resources

Endpoints