Add the widget
1
Get an API key
Open the dashboard and select Settings. Find the API keys & embed card and select Create key. Copy the key when the dashboard shows it. The dashboard shows the full key only once.
2
Paste the tag
Paste the tag before the closing
</body> tag of your page. You can also put it in <head> if you keep the async attribute. Replace YOUR_API_KEY with your key.Paste before </body>
3
Add your site to allowed origins
In Settings, open the Widget card. Add your site to Allowed origins and select Save widget settings.
4
Load your site
Open your site in a browser. The widget launcher appears on the page.
Keys you create in the dashboard start with
pl_live_. The key is meant to be public: it sits in your page’s HTML. Allowed origins, Turnstile and rate limits are what protect it.Attributes
The tag reads these attributes from the script element.
With the tag before
</body>, the widget starts at once. If the tag is in <head>, the widget waits for DOMContentLoaded before it starts. If a page has a second tag, the second tag does nothing.
Start the widget from your code
Start the widget from your code when you need options that the tag attributes do not have. Examples are inline mode,onAnalyticsEvent and historyLimit.
1
Load the script without data-api-key
Without
data-api-key, the script starts no widget. It adds window.PaperlinkAIChat and window.PaperlinkAIChatQueue to the page.2
Call init when the script is ready
Push a function onto
window.PaperlinkAIChatQueue. The script calls the function with PaperlinkAIChat when it is ready. This example puts the widget inside a page element.init uses the same default API base URL as the tag: data-api-base-url, or else the URL of the script without /widget.js. For all options, see Attributes and init options.
Run code when the script is ready
The script loads withasync, so your code can run before window.PaperlinkAIChat exists. Use one of these two signals.
- The queue. Functions that you push onto
window.PaperlinkAIChatQueuebefore the script loads run when it is ready. Functions that you push after that run at once. Use the queue in most cases, because it works in both orders. - The
paperlinkai:readyevent. The script fires this event onwindowone time, when it is ready.event.detail.PaperlinkAIChatholds the API. Add your listener before the script loads, or the listener misses the event.
What the tag exposes
The tag adds these properties towindow.
window.PaperlinkAIChathas theinitmethod. See JavaScript API.window.PaperlinkAIChatInstanceis the widget instance that the tag creates. It exists only when the tag hasdata-api-key.window.PaperlinkAIChatQueueruns your functions when the script is ready.
TypeScript types
The API serves a type declaration file next to the script. It declares thewindow properties above and the paperlinkai:ready event. It also declares the PaperlinkAI namespace with InitOptions, ChatInstance and WidgetAnalyticsEvent.
1
Download the file
Save the file in your project, for example as
types/paperlinkai-widget.d.ts.2
Include the file
Make sure that the
include setting of your tsconfig.json contains the file. The file has no imports or exports, so its types are global.Short declarations to paste
Short declarations to paste
If you do not want to download a file, paste this block into a
.d.ts file of your project. It declares only the parts that most pages use.types/paperlinkai-widget.d.ts
The script has no version number in its address. It always matches the API that Paperlink AI runs, so you never update the tag.
Attributes and options
See every attribute and option in one place.
React, Next.js, Vue and others
Start the widget in a framework component.