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

# Get Sleep Metrics

> Get detailed sleep and recovery metrics including:
- Sleep stage distribution (deep, light, REM)
- Sleep latency and WASO
- Sleep efficiency
- Night events (out-of-bed counts)

# Get Sleep Metrics

Get detailed sleep and recovery metrics including sleep stage distribution (deep, light, REM), sleep latency and WASO, sleep efficiency, and night events (out-of-bed counts).

## Headers

| Parameter     | Type   | Required | Description                            |
| ------------- | ------ | -------- | -------------------------------------- |
| authorization | string | Yes      | API authorization token (Bearer token) |

## Path Parameters

| Parameter | Type   | Required | Description           |
| --------- | ------ | -------- | --------------------- |
| user\_id  | string | Yes      | The ID of the patient |

## Query Parameters

| Parameter | Type    | Required | Description                                        |
| --------- | ------- | -------- | -------------------------------------------------- |
| days      | integer | No       | Number of past days to fetch data for (default: 7) |

## Responses

| Status | Description         | Content Type     |
| ------ | ------------------- | ---------------- |
| 200    | Successful Response | application/json |
| 422    | Validation Error    | application/json |

## Sample Request

```bash theme={null}
curl -X GET "https://api.covita.com/api/v1/sleep_metrics/User1?days=7" \
  -H "Authorization: Bearer YOUR_API_TOKEN"
```

## Sample Response

```json theme={null}
{
  "user_id": "User1",
  "days": 7,
  "sleep_metrics": {
    "average_sleep_duration": 7.2,
    "average_sleep_efficiency": 83.5,
    "sleep_stages": {
      "deep_sleep_percentage": 20,
      "light_sleep_percentage": 55,
      "rem_sleep_percentage": 25
    },
    "sleep_latency_minutes": 12,
    "waso_minutes": 45,
    "out_of_bed_events": 1.5
  },
  "daily_breakdown": [
    {
      "date": "2023-08-15",
      "deep_sleep_minutes": 90,
      "light_sleep_minutes": 248,
      "rem_sleep_minutes": 112,
      "sleep_latency": 10,
      "waso": 40,
      "out_of_bed_count": 1
    }
  ]
}
```


## OpenAPI

````yaml GET /api/v1/sleep_metrics/{user_id}
openapi: 3.1.0
info:
  title: Covita API
  description: API for Covita health monitoring system
  version: 1.0.0
servers: []
security: []
tags:
  - name: AI Assistant
    description: >-
      Endpoints for interacting with the AI assistant, including sending
      messages and managing conversation history
  - name: Patient Data
    description: >-
      Endpoints for accessing and managing patient health data, including
      medical history, vitals, and demographic information
paths:
  /api/v1/sleep_metrics/{user_id}:
    get:
      tags:
        - Patient Data
      summary: Get Sleep Metrics
      description: |-
        Get detailed sleep and recovery metrics including:
        - Sleep stage distribution (deep, light, REM)
        - Sleep latency and WASO
        - Sleep efficiency
        - Night events (out-of-bed counts)
      operationId: get_sleep_metrics_api_v1_sleep_metrics__user_id__get
      parameters:
        - name: user_id
          in: path
          required: true
          schema:
            type: string
            title: User Id
        - name: days
          in: query
          required: false
          schema:
            type: integer
            default: 7
            title: Days
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````