JavaScript SDK
Mount the oprag chat widget, or build your own chat UI on a typed client — in a browser or on a server, from one package.
@oprag/sdk is one package with two entries. @oprag/sdk/widget mounts the same chat widget the CDN script ships, with types and programmatic control. @oprag/sdk gives you the typed client the widget uses internally, and imports cleanly on a server because nothing in it touches a DOM global at module scope.
Pick a path
Script tagA working bot on a page with no build step. Two minutes.npm widgetTyped control over the same widget: open, send, theme, teardown.ServerChat, leads, and escalation from your backend with an integration key.
Where each key goes
| Runtime | Key kind | Prefix | Env var | Rule |
|---|---|---|---|---|
| Browser | Embed key | embed_test_… / embed_live_… | PUBLIC_OPRAG_EMBED_KEY | Ships in the bundle. Locked to the origins you allowlist on the project. |
| Server | Integration key | sk_test_… / sk_live_… | OPRAG_SECRET_KEY | Read from the process environment. Never sent to, or through, a browser. |
What the two entries export
| Entry | Runtime | Exports |
|---|---|---|
@oprag/sdk | Browser or server | createClient, isBrowser, citationDisplayLabel, statusToCode, OpragError, OpragConfigError, CreateClientOptions, OpragClient, ChatInput, ChatAskOptions, ChatStreamOptions, ChatResponse, CitationSource, LeadCreateInput |
@oprag/sdk/widget | Browser only | mountWidget, MountWidgetOptions, WidgetHandle, WidgetTheme |
Every symbol is listed with its signature on the API reference. Looking for the REST endpoints underneath? They are in the REST API tree.
Ready to ship?
Get started free