Summary

  • Type: tRPC subscription (WebSocket)
  • Path: wss://api.kontext.dev/trpc (tRPC WS endpoint), procedure: data.contextUpdates
  • Auth: x-api-key sent as a WS connectionParams value (not an HTTP header)
  • Input: { userId: string }
  • Emits: { type: 'facts_updated' | 'profile_changed' | 'data_synced', userId: string, timestamp: string, metadata?: { factCount?: number; source?: string; changeType?: string } }

Notes

  • Transport: WebSocket only. Subscriptions are not available over HTTP POST.
  • Availability: WebSocket server is enabled only when the backend has REDIS_HOST configured.
  • Stability: metadata may evolve; treat as opaque unless documented.

Client example (JavaScript)

import { createTRPCClient, createWSClient, wsLink } from '@trpc/client'
import superjson from 'superjson'

const ws = createWSClient({
  url: 'wss://api.kontext.dev/trpc',
  connectionParams: async () => ({ 'x-api-key': process.env.KONTEXT_API_KEY }),
})

const trpc = createTRPCClient({
  links: [wsLink({ client: ws, transformer: superjson })],
})

const sub = trpc.data.contextUpdates.subscribe(
  { userId: 'user_abc123' },
  {
    onData(event) {
      console.log('Context update:', event)
    },
    onError(err) {
      console.error('Subscription error:', err)
    },
  },
)

// later: sub.unsubscribe(); ws.close()

React example (Kontext SDK)

  • useRealtimeContext() creates a WS client that sets x-api-key in connectionParams.
  • It subscribes with { userId } and updates state on new events.

What to remove/change

  • Do not POST to /trpc/data.contextUpdates — subscriptions won’t work over HTTP.
  • Replace any “Request Body” section with “Subscribe with input { userId } via WS”.

Optional

  • If REDIS_HOST is not set on the server, WS is disabled and clients should fall back to polling (usePollingContext).
  • Auth on WS is passed via connectionParams (not standard headers).

Get the Kontext SDK

Install from npm and view release history.