Connecting AI agents to the API

If you'd like to connect an AI agent to the Umami API, for example to help you analyze the events, this guide shows you how.

1. Install the Prerequisites

On the machine where the agent will run, we'll install the Latchkey tool. That will allow the agent to send authenticated HTTP requests to the API without leaking any secrets to prompts.

  1. Make sure your system has a working node installation. If not, you can download it from the official page.

  2. Install Latchkey:

    npm install -g latchkey

2. Generate and Configure the API Token

  1. Follow the authentication docs to obtain an API token or an API key.

  2. If you don't use Umami Cloud, point Latchkey to your instance. For example:

    latchkey services register my-umami \
        --service-family umami \
        --base-api-url=http://203.0.113.1:3000/api/
  3. Insert the API token:

    latchkey auth set my-umami -H "Authorization: Bearer <your_token>"

    Alternatively, for Umami Cloud:

    latchkey auth set umami -H "x-umami-api-key: <your_api_key>"

3. Configure the AI Agent

Using skills.sh:

npx skills add imbue-ai/latchkey

You can also configure the AI agent manually. The exact steps will differ depending on the agent. Taking OpenCode as an example:

mkdir -p ~/.opencode/skills/latchkey
latchkey skill-md > ~/.opencode/skills/latchkey/SKILL.md

4. Use the AI Agent

After completing the previous steps, you should now be able to use your AI agent of choice to work with Umami! Here are some example questions and tasks for the agent:

Which referrer sends the highest-quality traffic (with the highest average session duration)?

or

What does my audience look like on weekends vs. weekdays?

or even

Tell me what's working on our blog and what isn't.

From here, it's up to your imagination.