Docs/Use it in your stack

Plain HTML and JavaScript

A static page, a PHP site, anything that serves HTML.

Load the script once, then call charge.ai.chat() from any event handler.

index.html
<script src="https://cdn.chargemy.ai/v1/charge.js"></script>

<input id="q" placeholder="Ask anything" />
<button id="ask">Ask</button>
<div id="answer"></div>

<script>
  document.getElementById('ask').addEventListener('click', async () => {
    const q = document.getElementById('q').value
    const reply = await charge.ai.chat(q)
    document.getElementById('answer').textContent = reply.text
  })
</script>

Show replies with textContent, not innerHTML, so a reply can never inject HTML into your page.

Read next

Still stuck? Talk to us and we'll help.