# GnamiAI API examples

Four runnable scripts that hit the public GnamiAI HTTP API. Each is
under 100 lines, no dependencies, plain `fetch`.

## Setup

For the auth-required examples, create a key in
[Settings → API keys](https://gnamiai.live/app.html#/settings) and
export it:

```bash
export GNAMI_KEY=gnami_xxxxxxxxxxxxxxxxxxxxxx
```

The full key is shown exactly once at creation. Copy it then or
revoke and create a new one.

## Scripts

| File | Auth | What it does |
|---|---|---|
| `marketplace-snapshot.mjs` | none | Prints public marketplace stats + every published skill |
| `agent-turn.mjs`           | Bearer | Single chat turn through your configured provider |
| `list-skills.mjs`          | Bearer | Lists every skill in your workspace |
| `discord-bot.mjs`          | Bearer + Discord token | Production-ready Discord bot: auto-reconnect, RESUME on drop, per-channel history, queued turns, structured JSON logs, graceful shutdown. Run it under `pm2`, `systemd`, fly.io, or any process manager and it stays online. |

Each script is served as a plain `.mjs` file directly from the site:

- <https://gnamiai.live/examples/marketplace-snapshot.mjs>
- <https://gnamiai.live/examples/agent-turn.mjs>
- <https://gnamiai.live/examples/list-skills.mjs>
- <https://gnamiai.live/examples/discord-bot.mjs>

Fetch + run with Node 22+:

```bash
curl -O https://gnamiai.live/examples/agent-turn.mjs
export GNAMI_KEY=gnami_xxxxxxxxxxxxxxxxxxxxxx
node agent-turn.mjs "What did I work on yesterday?"
```

Save them all in one go:

```bash
for f in marketplace-snapshot agent-turn list-skills discord-bot; do
  curl -O "https://gnamiai.live/examples/$f.mjs"
done
```

Full API reference: <https://gnamiai.live/docs/api>
