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

# Stream Kg Events

> Server-Sent Events stream of `kg.session.committed` /
`kg.board.cleared` events for the given board.

The stream reads the `global_update_outbox` table for the latest events
and emits new rows at a 1-second poll cadence. This endpoint is the
backing data source for the React `useKgLiveEvents` hook (Frontend
responsibility — hook implementation lives in the sibling UI repo).

Protocol:
    event: kg.session.committed
    data: {"event_id": ..., "session_id": ..., "payload": {...}}

Filter by `since` to resume a dropped connection without replaying the
entire outbox backlog. Absence ⇒ start from now().

Bug fix (QueuePool exhaustion): este handler NÃO injeta mais
``db: AsyncSession = Depends(get_db)`` porque a session da request
ficaria viva durante toda a vida do SSE stream (loop ``while True``
forever) — cada cliente prendia 1 conexão do pool, e um pool de 15
saturava com poucas tabs/clientes (somando consolidation_worker,
outbox_worker, dispatcher e endpoints normais). Em vez disso abrimos
uma sessão **por iteração** via ``async_session_factory``, devolvendo
a conexão ao pool entre os ``sleep(1.0)``.



## OpenAPI

````yaml /openapi.json get /api/v1/kg/boards/{board_id}/events
openapi: 3.1.0
info:
  description: >-
    Okto Pulse REST API schema generated from okto-pulse-core 0.2.0 source for
    docs.oktolabs.ai.
  title: Okto Pulse
  version: 0.2.0
servers: []
security: []
paths:
  /api/v1/kg/boards/{board_id}/events:
    get:
      tags:
        - knowledge-graph
        - knowledge-graph
      summary: Stream Kg Events
      description: |-
        Server-Sent Events stream of `kg.session.committed` /
        `kg.board.cleared` events for the given board.

        The stream reads the `global_update_outbox` table for the latest events
        and emits new rows at a 1-second poll cadence. This endpoint is the
        backing data source for the React `useKgLiveEvents` hook (Frontend
        responsibility — hook implementation lives in the sibling UI repo).

        Protocol:
            event: kg.session.committed
            data: {"event_id": ..., "session_id": ..., "payload": {...}}

        Filter by `since` to resume a dropped connection without replaying the
        entire outbox backlog. Absence ⇒ start from now().

        Bug fix (QueuePool exhaustion): este handler NÃO injeta mais
        ``db: AsyncSession = Depends(get_db)`` porque a session da request
        ficaria viva durante toda a vida do SSE stream (loop ``while True``
        forever) — cada cliente prendia 1 conexão do pool, e um pool de 15
        saturava com poucas tabs/clientes (somando consolidation_worker,
        outbox_worker, dispatcher e endpoints normais). Em vez disso abrimos
        uma sessão **por iteração** via ``async_session_factory``, devolvendo
        a conexão ao pool entre os ``sleep(1.0)``.
      operationId: stream_kg_events_api_v1_kg_boards__board_id__events_get
      parameters:
        - in: path
          name: board_id
          required: true
          schema:
            title: Board Id
            type: string
        - description: ISO timestamp — only emit events created after this
          in: query
          name: since
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: ISO timestamp — only emit events created after this
            title: Since
      responses:
        '200':
          content:
            application/json:
              schema: {}
          description: Successful Response
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    ValidationError:
      properties:
        ctx:
          title: Context
          type: object
        input:
          title: Input
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object

````