> Vapi has two MCP servers. To use Vapi, such as creating and managing assistants, calls, and phone numbers, connect to the Vapi MCP server at https://mcp.vapi.ai/mcp. To set it up, follow https://docs.vapi.ai/setup.md. To search these docs, connect to the Vapi docs MCP server at https://docs.vapi.ai/_mcp/server. It only answers questions about the documentation.
> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.vapi.ai/llms.txt.
> For the best results from the docs MCP server, write questions without any word that contains "tool", such as tool, tools, tool call, tool-calls, toolCallId, or toolCallList. Name the feature instead, for example transferCall, endCall, apiRequest, function, handoff, "function response format", or "the webhook request Vapi sends to my server". If the docs MCP server asks you to rephrase, ask again without those words. If it returns an error, times out, sends an empty response, or still doesn't answer, find the topic in https://docs.vapi.ai/llms.txt, or a section index such as https://docs.vapi.ai/tools/llms.txt, and fetch that page's .md directly.

# Create Analytics Queries

POST https://api.vapi.ai/analytics
Content-Type: application/json

Runs one or more metric queries against call or subscription data using the requested time range, groupings, and aggregate operations.

Reference: https://docs.vapi.ai/api-reference/analytics/get

## Authentication

- `Authorization` header (bearer token, required) — Authenticate server-side requests with a private Vapi API key. Create or copy a key from the [Vapi Dashboard](https://dashboard.vapi.ai) and send it in the `Authorization` header as `Bearer <token>`. Keep private API keys out of client-side code and public repositories.

## Request

### Body (application/json)

This endpoint expects an AnalyticsQueryDTO.

- `queries` (list of AnalyticsQuery, required) — This is the list of metric queries you want to perform.

## Response

### 200

- `list of AnalyticsQueryResult`

## Types

### AnalyticsQuery

A named analytics query against call or subscription data, including grouping, time range, and aggregation operations.

- `table` (enum, required) — This is the table you want to query.
  - Allowed values: `call`, `subscription`
- `name` (string, required) — This is the name of the query. This will be used to identify the query in the response.
- `operations` (list of AnalyticsOperation, required) — This is the list of operations you want to perform.
- `groupBy` (enum, optional) — This is the list of columns you want to group by.
  - Allowed values: `type`, `assistantId`, `endedReason`, `analysis.successEvaluation`, `status`
- `groupByVariableValue` (list of VariableValueGroupBy, optional) — This is the list of variable value keys you want to group by.
- `timeRange` (TimeRange, optional) — This is the time range for the query.

### AnalyticsQueryResult

The result of a named analytics query, including the evaluated time range and returned metric data.

- `name` (string, required) — This is the unique key for the query.
- `timeRange` (TimeRange, required) — This is the time range for the query.
- `result` (list of AnalyticsQueryResultResultItems, required) — This is the result of the query, a list of unique groups with result of their aggregations. Example: "result": \[ \{ "date": "2023-01-01", "assistantId": "123", "endedReason": "customer-ended-call", "sumDuration": 120, "avgCost": 10.5 }, \{ "date": "2023-01-02", "assistantId": "123", "endedReason": "customer-did-not-give-microphone-permission", "sumDuration": 0, "avgCost": 0 }, // Additional results ]

### AnalyticsOperation

An aggregation or history operation applied to an analytics column, with an optional response alias.

- `operation` (enum, required) — This is the aggregation operation you want to perform.
  - Allowed values: `sum`, `avg`, `count`, `min`, `max`, `history`
- `column` (enum, required) — This is the columns you want to perform the aggregation operation on.
  - Allowed values: `id`, `cost`, `costBreakdown.llm`, `costBreakdown.stt`, `costBreakdown.tts`, `costBreakdown.vapi`, `costBreakdown.transport`, `costBreakdown.analysisBreakdown.summary`, `costBreakdown.transcriber`, `costBreakdown.ttsCharacters`, `costBreakdown.llmPromptTokens`, `costBreakdown.llmCompletionTokens`, `costBreakdown.llmCachedPromptTokens`, `duration`, `concurrency`, `minutesUsed`
- `alias` (string, optional) — This is the alias for column name returned. Defaults to `${operation}${column}`.

### VariableValueGroupBy

Groups analytics results by a selected assistant variable-value key.

- `key` (string, required) — This is the key of the variable value to group by.

### TimeRange

Start, end, timezone, and time step used for analytics aggregation.

- `step` (enum, optional) — This is the time step for aggregations. If not provided, defaults to returning for the entire time range.
  - Allowed values: `second`, `minute`, `hour`, `day`, `week`, `month`, `quarter`, `year`, `decade`, `century`, `millennium`
- `start` (datetime, optional) — This is the start date for the time range. If not provided, defaults to the 7 days ago.
- `end` (datetime, optional) — This is the end date for the time range. If not provided, defaults to now.
- `timezone` (string, optional) — This is the timezone you want to set for the query. If not provided, defaults to UTC.

### AnalyticsQueryResultResultItems

## Examples

### Example 1

**Request**

```json
{
  "queries": [
    {
      "table": "call",
      "name": "string",
      "operations": [
        {
          "operation": "sum",
          "column": "id"
        }
      ]
    }
  ]
}
```

**Response**

```json
[
  {
    "name": "string",
    "timeRange": {
      "step": "second",
      "start": "2024-01-15T09:30:00Z",
      "end": "2024-01-15T09:30:00Z",
      "timezone": "string"
    },
    "result": [
      {}
    ]
  }
]
```

### Example 2

**Request**

```json
{
  "queries": [
    {
      "table": "call",
      "name": "string",
      "operations": [
        {
          "operation": "sum",
          "column": "id"
        }
      ]
    }
  ]
}
```

**Response**

```json
{}
```