Docs/Getting started

Add AI in five minutes

One script tag and one call. No API key, no server, no billing code.

ChargeMyAI works on any web page. You add one script tag, call charge.ai.chat() where you want AI, and your users pay for their own replies by UPI.

1. Add the script tag

Put it once on every page that uses AI, usually just before </body> or in your layout.

index.html
<script src="https://api.chargemyai.com/v1/charge.js"></script>

2. Ask for a reply

index.html
<textarea id="text"></textarea>
<button id="go">Summarise</button>
<p id="out"></p>

<script type="module">
  go.onclick = async () => {
    go.disabled = true
    try {
      const reply = await charge.ai.chat('Summarise in two lines: ' + text.value)
      out.textContent = reply.text
    } catch (e) {
      if (e.code !== 'cancelled') out.textContent = e.message
    } finally {
      go.disabled = false
    }
  }
</script>

3. That's it

  • The reply comes from a cloud model. The first time, your user signs in once and gets 10 free replies; after that they top up by UPI.
  • Want free replies where the browser can answer on its own (Chrome on capable laptops)? Pass mode: 'auto' and the on-device model answers first, with the cloud as the fallback.
  • ChargeMyAI shows the sign-in and payment screens itself, then sends the message. You write no extra code for it.

Never add an API key. There isn't one, and nothing secret ever sits in your page.

Read next

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