> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useautumn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Query data in SQL

> Run a read-only SQL query over your Autumn data. Streams the result as newline-delimited JSON; see the [SQL guide](/documentation/query-with-sql).

### Body Parameters

Read-only DuckDB SQL over your Autumn data (customers, subscriptions, balances, etc...). Runs against your org and environment only.

```json 200 theme={null}
{"type":"columns","columns":[{"name":"plan_id","type":"VARCHAR"},{"name":"customers","type":"BIGINT"}]}
{"type":"row","values":["pro","42"]}
{"type":"row","values":["starter","17"]}
{"type":"end","rows":2,"truncated":false,"stopped_by":null}
```

```json 200 with error theme={null}
{"type":"columns","columns":[{"name":"plan_id","type":"VARCHAR"},{"name":"customers","type":"BIGINT"}]}
{"type":"row","values":["pro","42"]}
{"type":"error","code":"statement_timeout","message":"Query exceeded the 30s compute limit for your plan and was cancelled. Narrow it (filter by date or customer, select fewer columns, or add LIMIT) or contact support@useautumn.com to raise your compute limit.","details":{"limit_ms":30000}}
```


## OpenAPI

````yaml openapi POST /v1/analytics.query
openapi: 3.1.0
info:
  title: Autumn API
  version: 2.6.0
servers:
  - url: https://api.useautumn.com
    description: Production server
security:
  - secretKey: []
paths:
  /v1/analytics.query:
    post:
      tags:
        - analytics
      summary: Query data in SQL
      description: >-
        Run a read-only SQL query over your Autumn data. Streams the result as
        newline-delimited JSON; see the [SQL
        guide](/documentation/query-with-sql).
      operationId: queryAnalytics
      parameters:
        - name: x-api-version
          in: header
          required: true
          schema:
            type: string
            default: 2.6.0
          x-speakeasy-globals-hidden: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                sql:
                  type: string
                  minLength: 1
                  maxLength: 100000
                  description: >-
                    Read-only DuckDB SQL over your Autumn data (customers,
                    subscriptions, balances, etc...). Runs against your org and
                    environment only.
              required:
                - sql
              title: AnalyticsQueryParams
              examples:
                - sql: >-
                    SELECT plan_id, count(*) AS customers FROM subscriptions
                    WHERE status = 'active' GROUP BY 1
                - sql: DESCRIBE customers
            example:
              sql: >-
                SELECT plan_id, count(*) AS customers FROM subscriptions WHERE
                status = 'active' GROUP BY 1
      responses:
        '200':
          description: >-
            A newline-delimited JSON stream. Each line is an
            [AnalyticsQueryLine](#/components/schemas/AnalyticsQueryLine):
            columns first, then one row line per result row, then an end or
            error line.
          content:
            application/x-ndjson:
              schema:
                type: string
                format: binary
              examples:
                success:
                  summary: '200'
                  value: >
                    {"type":"columns","columns":[{"name":"plan_id","type":"VARCHAR"},{"name":"customers","type":"BIGINT"}]}

                    {"type":"row","values":["pro","42"]}

                    {"type":"row","values":["starter","17"]}

                    {"type":"end","rows":2,"truncated":false,"stopped_by":null}
                error:
                  summary: 200 with error
                  value: >
                    {"type":"columns","columns":[{"name":"plan_id","type":"VARCHAR"},{"name":"customers","type":"BIGINT"}]}

                    {"type":"row","values":["pro","42"]}

                    {"type":"error","code":"statement_timeout","message":"Query
                    exceeded the 30s compute limit for your plan and was
                    cancelled. Narrow it (filter by date or customer, select
                    fewer columns, or add LIMIT) or contact
                    support@useautumn.com to raise your compute
                    limit.","details":{"limit_ms":30000}}
          headers:
            Content-Encoding:
              description: >-
                zstd when the request's Accept-Encoding allows it, otherwise
                gzip.
              schema:
                type: string
                enum:
                  - zstd
                  - gzip
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Autumn } from 'autumn-js'

            const autumn = new Autumn()

            const result = await autumn.analytics.query({
              sql: "SELECT plan_id, count(*) AS customers FROM subscriptions WHERE status = 'active' GROUP BY 1",
            });
        - lang: python
          label: Python (SDK)
          source: |-
            from autumn_sdk import Autumn

            autumn = Autumn(secret_key="am_sk_test...")

            res = autumn.analytics.query(
                sql="SELECT plan_id, count(*) AS customers FROM subscriptions WHERE status = 'active' GROUP BY 1",
            )
components:
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.