Integrate via Script

Install the SnippetAI web component via a script tag. This is useful for doc providers that don’t allow you to add your own script tags but do allow custom JS.

If you are in a react environment or can add a custom script tag, take a look at Integrate via React or Integrate via Web Component are preferred.

Required Steps

Add the two components to your documentation site;

  1. A button with an HTML ID that you want to trigger the component
  2. The script tag to mount the web component

Below is an example minimal HTML installation.

<script>
const script = document.createElement('script')
script.type = 'module'
script.src = 'https://snippet-ai.speakeasy-cloud.com/assets/index.es.js'
document.head.appendChild(script)
script.addEventListener('load', async () => {
const snippetAI = document.createElement('snippet-ai')
// Replace values here with your own
// ---------------------------------
snippetAI.setAttribute('publishingToken', '<your token>')
snippetAI.setAttribute('suggestions', JSON.stringify([
'<suggestion 1>'
]))
snippetAI.setAttribute('triggerelementid', 'your-element-ID')
// ---------------------------------
document.body.appendChild(snippetAI)
})
</script>
<button id="your-element-ID">
My trigger
</button>

In the above script you can configure your component by adjusting the following HTML attributes

AttributeDescriptionRequiredDefault
publishingtokenYour public API key for authenticationYes-
codelangProgramming language for code generation (typescript, python, go, java, csharp, php)No-
triggerelementidCustom ID attribute for a button element that will open SnippetAI when clickedNo-
toggleshortcutKeyboard shortcut to open the Command BarNo"$mod+k" (cmd+k / ctrl+k)
zindexZ-index of the command barNo"1000"
suggestionsSearchable list of suggestions for the command barNo"[]"