> 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 full documentation content, see https://docs.vapi.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.vapi.ai/_mcp/server.

# Create Analytics Queries

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

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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: api
  version: 1.0.0
paths:
  /analytics:
    post:
      operationId: get
      summary: Create Analytics Queries
      tags:
        - subpackage_analytics
      parameters:
        - name: Authorization
          in: header
          description: Retrieve your API Key from [Dashboard](dashboard.vapi.ai).
          required: true
          schema:
            type: string
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/AnalyticsQueryResult'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnalyticsQueryDTO'
servers:
  - url: https://api.vapi.ai
components:
  schemas:
    AnalyticsQueryTable:
      type: string
      enum:
        - call
        - subscription
      description: This is the table you want to query.
      title: AnalyticsQueryTable
    AnalyticsQueryGroupBy:
      type: string
      enum:
        - type
        - assistantId
        - endedReason
        - analysis.successEvaluation
        - status
      description: This is the list of columns you want to group by.
      title: AnalyticsQueryGroupBy
    VariableValueGroupBy:
      type: object
      properties:
        key:
          type: string
          description: This is the key of the variable value to group by.
      required:
        - key
      title: VariableValueGroupBy
    TimeRangeStep:
      type: string
      enum:
        - second
        - minute
        - hour
        - day
        - week
        - month
        - quarter
        - year
        - decade
        - century
        - millennium
      description: |-
        This is the time step for aggregations.

        If not provided, defaults to returning for the entire time range.
      title: TimeRangeStep
    TimeRange:
      type: object
      properties:
        step:
          $ref: '#/components/schemas/TimeRangeStep'
          description: |-
            This is the time step for aggregations.

            If not provided, defaults to returning for the entire time range.
        start:
          type: string
          format: date-time
          description: |-
            This is the start date for the time range.

            If not provided, defaults to the 7 days ago.
        end:
          type: string
          format: date-time
          description: |-
            This is the end date for the time range.

            If not provided, defaults to now.
        timezone:
          type: string
          description: |-
            This is the timezone you want to set for the query.

            If not provided, defaults to UTC.
      title: TimeRange
    AnalyticsOperationOperation:
      type: string
      enum:
        - sum
        - avg
        - count
        - min
        - max
        - history
      description: This is the aggregation operation you want to perform.
      title: AnalyticsOperationOperation
    AnalyticsOperationColumn:
      type: string
      enum:
        - 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
      description: This is the columns you want to perform the aggregation operation on.
      title: AnalyticsOperationColumn
    AnalyticsOperation:
      type: object
      properties:
        operation:
          $ref: '#/components/schemas/AnalyticsOperationOperation'
          description: This is the aggregation operation you want to perform.
        column:
          $ref: '#/components/schemas/AnalyticsOperationColumn'
          description: >-
            This is the columns you want to perform the aggregation operation
            on.
        alias:
          type: string
          description: >-
            This is the alias for column name returned. Defaults to
            `${operation}${column}`.
      required:
        - operation
        - column
      title: AnalyticsOperation
    AnalyticsQuery:
      type: object
      properties:
        table:
          $ref: '#/components/schemas/AnalyticsQueryTable'
          description: This is the table you want to query.
        groupBy:
          $ref: '#/components/schemas/AnalyticsQueryGroupBy'
          description: This is the list of columns you want to group by.
        groupByVariableValue:
          type: array
          items:
            $ref: '#/components/schemas/VariableValueGroupBy'
          description: This is the list of variable value keys you want to group by.
        name:
          type: string
          description: >-
            This is the name of the query. This will be used to identify the
            query in the response.
        timeRange:
          $ref: '#/components/schemas/TimeRange'
          description: This is the time range for the query.
        operations:
          type: array
          items:
            $ref: '#/components/schemas/AnalyticsOperation'
          description: This is the list of operations you want to perform.
      required:
        - table
        - name
        - operations
      title: AnalyticsQuery
    AnalyticsQueryDTO:
      type: object
      properties:
        queries:
          type: array
          items:
            $ref: '#/components/schemas/AnalyticsQuery'
          description: This is the list of metric queries you want to perform.
      required:
        - queries
      title: AnalyticsQueryDTO
    AnalyticsQueryResultResultItems:
      type: object
      properties: {}
      title: AnalyticsQueryResultResultItems
    AnalyticsQueryResult:
      type: object
      properties:
        name:
          type: string
          description: This is the unique key for the query.
        timeRange:
          $ref: '#/components/schemas/TimeRange'
          description: This is the time range for the query.
        result:
          type: array
          items:
            $ref: '#/components/schemas/AnalyticsQueryResultResultItems'
          description: >-
            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
            ]
      required:
        - name
        - timeRange
        - result
      title: AnalyticsQueryResult
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: Retrieve your API Key from [Dashboard](dashboard.vapi.ai).

```

## SDK Code Examples

```python
from vapi import Vapi, AnalyticsQuery, AnalyticsOperation

client = Vapi(
    token="YOUR_TOKEN_HERE",
)

client.analytics.get(
    queries=[
        AnalyticsQuery(
            table="call",
            name="Total Call Duration",
            operations=[
                AnalyticsOperation(
                    operation="sum",
                    column="duration",
                )
            ],
        )
    ],
)

```

```go
package example

import (
    context "context"

    serversdkgo "github.com/VapiAI/server-sdk-go"
    client "github.com/VapiAI/server-sdk-go/client"
    option "github.com/VapiAI/server-sdk-go/option"
)

func do() {
    client := client.NewClient(
        option.WithToken(
            "YOUR_TOKEN_HERE",
        ),
    )
    request := &serversdkgo.AnalyticsQueryDto{
        Queries: []*serversdkgo.AnalyticsQuery{
            &serversdkgo.AnalyticsQuery{
                Table: serversdkgo.AnalyticsQueryTableCall,
                Name: "Total Call Duration",
                Operations: []*serversdkgo.AnalyticsOperation{
                    &serversdkgo.AnalyticsOperation{
                        Operation: serversdkgo.AnalyticsOperationOperationSum,
                        Column: serversdkgo.AnalyticsOperationColumnDuration,
                    },
                },
            },
        },
    }
    client.Analytics.Get(
        context.TODO(),
        request,
    )
}

```

```python
from vapi import Vapi, AnalyticsQuery, AnalyticsOperation

client = Vapi(
    token="YOUR_TOKEN_HERE",
)

client.analytics.get(
    queries=[
        AnalyticsQuery(
            table="call",
            name="Total Call Duration",
            operations=[
                AnalyticsOperation(
                    operation="sum",
                    column="duration",
                )
            ],
        )
    ],
)

```

```go
package example

import (
    context "context"

    serversdkgo "github.com/VapiAI/server-sdk-go"
    client "github.com/VapiAI/server-sdk-go/client"
    option "github.com/VapiAI/server-sdk-go/option"
)

func do() {
    client := client.NewClient(
        option.WithToken(
            "YOUR_TOKEN_HERE",
        ),
    )
    request := &serversdkgo.AnalyticsQueryDto{
        Queries: []*serversdkgo.AnalyticsQuery{
            &serversdkgo.AnalyticsQuery{
                Table: serversdkgo.AnalyticsQueryTableCall,
                Name: "Total Call Duration",
                Operations: []*serversdkgo.AnalyticsOperation{
                    &serversdkgo.AnalyticsOperation{
                        Operation: serversdkgo.AnalyticsOperationOperationSum,
                        Column: serversdkgo.AnalyticsOperationColumnDuration,
                    },
                },
            },
        },
    }
    client.Analytics.Get(
        context.TODO(),
        request,
    )
}

```