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

# Stream insights (SSE)

> Stream real-time insights via Server-Sent Events (SSE). On connect, recent insights are replayed as 'insight.replay' events (up to 20). New insights arrive as 'insight.batch.created' events. Keepalive comments are sent every 30 seconds.

<Note>
  This endpoint requires the `insight.stream` scope on your API key.
</Note>

## Connection Behavior

1. On connect, a comment is sent: `: connected workspace_id=... token_id=...`
2. Recent insights are replayed as `insight.replay` events (up to 20)
3. Keepalive comments (`: keepalive`) are sent every 30 seconds
4. New insights arrive as `insight.batch.created` events in real-time

## Example

```bash theme={null}
curl -N -s "https://app.nex.ai/api/developers/v1/insights/stream" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: text/event-stream"
```

## Event Types

| Event                   | Description                                    |
| ----------------------- | ---------------------------------------------- |
| `insight.batch.created` | Real-time: new insights just discovered        |
| `insight.replay`        | Historical: recent insights sent on connection |

## Event Format

```
event: insight.batch.created
data: {"workspace":{...},"insights":[...],"insight_count":3,"emitted_at":"2026-02-07T10:30:00Z"}
```


## OpenAPI

````yaml get /v1/insights/stream
openapi: 3.0.0
info:
  description: >-
    REST API for accessing and managing your Nex data. Generate API keys from
    the Nex web UI and use them to authenticate requests.
  title: Nex Developer API
  contact: {}
  version: '1.0'
servers:
  - url: https://app.nex.ai/api/developers
security: []
paths:
  /v1/insights/stream:
    get:
      tags:
        - Insights
      summary: Stream insights (SSE)
      description: >-
        Stream real-time insights via Server-Sent Events (SSE). On connect,
        recent insights are replayed as 'insight.replay' events (up to 20). New
        insights arrive as 'insight.batch.created' events. Keepalive comments
        are sent every 30 seconds.
      operationId: streamInsights
      responses:
        '200':
          description: SSE event stream of insights
          content:
            text/event-stream:
              schema:
                type: string
                description: >-
                  Server-Sent Events stream. Events: 'insight.batch.created'
                  (real-time new insights), 'insight.replay' (historical replay
                  on connect). Each event's data field contains a JSON object
                  with workspace, insights array, insight_count, and emitted_at.
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/httpx.APIError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/httpx.APIError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    httpx.APIError:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
  securitySchemes:
    ApiKeyAuth:
      description: 'API key for authentication (format: "Bearer YOUR_API_KEY")'
      type: apiKey
      name: Authorization
      in: header

````