翻篇收录说明
翻篇网页快照

Embed a chat agent | Kadmo Docs

https://docs.kadmo.ai/chat-agents/embed

最近抓取:2026-12-03 14:06:41(北京时间)

最近内容变化:2026-12-03 14:06:41(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Documentation for Kadmo: the app at app.kadmo.ai, agents, workflows, skill packs, integrations, MCP and the Kadmo provider

正文摘录

Embed a chat agent ​Put a Kadmo chat agent on your own site: a chat dock in the corner, a panel you place yourself, an inline thread, or a ⌘K palette that searches your own data and answers questions in the same box. This page is the whole integration contract: with a publishable key and what is below, a developer can ship the widget on their own origin. It covers installing the packages, the three rules that keep an integration safe, signed sessions, your Content Security Policy, origins, caps, key rotation and every error code.What you need ​A chat agentCreated and activated in the app under Chat agents (app.kadmo.ai/chat-agents) by an account adminA publishable keykc_pk_…, minted on the agent's Keys & embed tab and locked to the origins you nameAn originThe scheme and host your page is served from. A key allows nothing until it lists oneA second key type exists: kc_sk_…, a secret key. It is only for signed sessions, and only your backend ever uses it; it must never appear in a browser. The Keys & embed tab mints publishable keys only. Skip the secret key entirely unless you need signed sessions.A chat agent's answers are model calls on the Kadmo provider, paid from your account's credit.Mint a key ​Open Chat agents, pick the agent, and open the Keys & embed tab.Under Publishable keys, click Mint a key.Give it a Label that tells two live keys apart during a rotation, for example Production — example.com.Under Allowed origins — one per line, list every origin that serves the widget (see Allowed origins).Click Mint the key.The key is shown once, together with the install snippet with this key already in it. Copy both, then click I have copied it — close. The key cannot be shown again; if you lose it, mint another.The tab's Install the widget block always shows the snippet (with a placeholder instead of a key) and the Content security policy line your site needs, each with a Copy button.Install ​bashpnpm add @kadmo/chat @kadmo/core react react-domThe snippet the Keys & embed tab hands you does three things:StepWhat1Import @kadmo/core/styles.css first: the tokens and every part.2Import @kadmo/chat/styles.css second: the boxes those parts sit in.3Render the KadmoChat component from @kadmo/chat with one prop, token, set to your kc_pk_… key.That is the whole integration: a token, two stylesheets and one element. The stylesheet order matters, because core's tokens must be in the document before the shell that uses them.The @kadmo packages are not on the public npm registry yetThe pnpm add line above does not resolve today. The snippet is the shape your integration takes; ask Kadmo for a tarball in the meantime. Nothing else on this page changes when the packages are published.react and react-dom are required peers of @kadmo/chat. They are optional peers of @kadmo/core, whose root entry is a framework-free client (createKadmo) you can drive yourself; its options are publishableKey, apiBase, entry, endUser, host, session and onSessionExpired.The token is the configuration ​There is nothing else to configure. The agent's name, avatar, welcome message, suggested questions, language, theme, feature flags and caps all arrive at boot from the gateway, keyed on the token. Changing any of them is an action in the app, not a redeploy of your site.The widget talks to exactly one host, the gateway at https://gw.kadmo.ai, under /embed/v1, and it sends exactly three headers:HeaderWhat it carriesAuthorizationBearer kc_pk_…, the publishable keyContent-Typeapplication/jsonX-Kadmo-UserWho is asking. See the end-user descriptorThat list is the gateway's CORS allowlist. A fourth header fails the browser's preflight with no useful error anywhere, which is why everything contextual rides in the request body or the query string, and why a signed session travels inside X-Kadmo-User instead of a header of its own.Three rules ​Everything else on this page is mechanics. These three are easy to get wrong, and each is a real failure rather than a style preference.1. The publishable key is not a secret ​It is designed to sit in a frontend bundle. Anyone who opens the developer tools on your site can read it, and that is fine: it is not what protects your account. Four things are:It binds one agent. The key resolves to a single chat agent and cannot reach another, or any other part of your account.It is origin-locked. In a browser it works only on the origins you listed.It is capped. Rate caps at the edge, and turn, volume and spend caps on the agent, bound what it can cost you. See Caps and what the visitor sees.It is revocable. One click, effective immediately, with no grace period.So publish it freely, and keep the allowlist tight and the caps honest. Do not extend that reasoning to kc_sk_…: the secret key mints sessions for any end user of the agent, so in a bundle it is an impersonation key.2. The origin allowlist binds browsers, not scripts ​The gateway compares the Origin header with your key's allowlist. A browser sets that header itself and a page cannot forge it, so for real visitors on real sites the allowlist is a hard control: a stolen key pasted into someone else's page gets 403 origin_not_allowed on its first call.Outside a browser, Origin is free text. curl, a server or a scraper can send any origin it likes, including one of yours. The allowlist does not stop that and was never able to.What bounds a key in the wrong hands is the caps and the revoke button. Size the caps for the traffic you expect, watch the agent's Monitoring tab, and revoke on suspicion. Rotating a leaked key is a five-minute job.3. The end-user id must be opaque and unguessable ​In its unsigned form, X-Kadmo-User is a label your site asserts, not a credential. Nothing signs or verifies it. What it does is select a thread list: conversations are scoped by agent and end user and nothing more, and a thread belonging to another end user answers exactly the same 404 as a thread that does not exist.Together these mean: anyone holding the publishable key, which is anyone at all, who can guess an end-user id can read that person's conversation history. So the id must be opaque and unguessable:IdVerdictalex@example.comNo: an address is guessable from a business card4172No: a sequential database id is guessable by countingalex.tanNo: a username is shown in many placesusr_8Kd2vQ1nPzR7…Yes: an HMAC of your own user id under a server-side secretCompute it on your server, never in the page: an HMAC-SHA-256 of your identity provider's subject claim (prefixed, for example, with end-user:) under the secret you already use for sessions, base64url-encoded and cut to 32 characters (about 192 bits), with a prefix such as usr_.Key it on the subject claim, not the e-mail address. An address is re-assignable, and a change would silently split a person's history into two thread lists.Use your existing session secret, so the mapping is unguessable outside your servers and rotates when that secret does.Keep the id stable for that person forever. It is their history.When an unguessable id is not enough, for example when conversations contain the person's own account data, do not invent a stronger label: prove the identity with signed sessions.The shells ​@kadmo/chat is one component with three shells:variantWhat it isdock (default)A launcher fixed to the corner, opening a 420×680 panel in a dialog: focus is trapped, Esc closes it, and it fills the screen on phonespanelThe same panel without a launcher, sized by your containerinlineThe thread and the composer, filling your container. No header, no historyPropTypeWhat it doesvariant'dock' | 'panel' | 'inline'Which shell. Default docktokenstringThe kc_pk_… publishable key. Omit it only when a KadmoProvider is aboveapiBasestringThe gateway. Defaults to https://gw.kadmo.aiuserEndUserDescriptor | nullThe signed-in visitor. null is an explicit anonymous visitorlocale'de' | 'en'Pin the interface language. Omit it to follow the agent's owncontextHostContext | (() => HostContext)The page, reported on every turn. A function is read again on each turnthemeRecord<string, string>--kadmo-* overrides on top of the agent's themeopen / onOpenChangeboolean / (open) => voidControl the dock yourselfonError(event) => voidEvery refusal, boot included: { code, message, retryAfterSeconds? }onThreadChange(event) => voidThe conversation the visitor is in: { threadId, entry }paletteHintbooleanForce the ⌘K hint on or off. Omitted, it follows what is mountedclassNamestringAdded to the shell's own root elementPass context as a function if your app navigates without full page loads, so each turn reports the page the question was actually asked from.A visitor who never opens the chat downloads only the launcher: about 3 KB gzipped plus the framework-free client. The conversation runtime loads on the first click. The package's own build enforces this.Once opened, the dock stays mounted between opens, so closing and reopening returns the visitor to the same thread. Only the header's new chat starts a fresh one.One provider, two shells ​Given a token, a shell builds a client of its own. Mount KadmoProvider yourself when two shells should share one client and therefore one conversation, so a thread opened in the palette continues in the dock. Give the provider the publishableKey (and endUser), and give neither shell a token: the token is exactly what tells a shell to make its own provider.KadmoProvider is exported from the @kadmo/core/react subpath, the React half of the core package; it is not exported from @kadmo/chat or from @kadmo/core's root.The trade: a provider you mount has already loaded the conversation runtime, so the deferred launcher no longer applies. On an internal staff surface that is fine. On a public marketing page, mount the dock alone with a token and let it defer.The command palette ​@kadmo/palette is the ⌘K box: one input that is both your quick-search field and the composer, one list that carries your own rows above the assistant's.bashnpm i @kadmo/p