|
| 1 | +# kapi-kit · Kick Public API toolkit for Node.js 22 🚀 |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/kapi-kit) |
| 4 | +[](#requirements) |
| 5 | +[](LICENSE) |
| 6 | +[](docs/coverage.md) |
| 7 | + |
| 8 | +`kapi-kit` is a batteries-included SDK for the [Kick Public API](https://github.com/KickEngineering/KickDevDocs). It is designed for modern Node.js runtimes (22+) and ships with everything you need to build bots, dashboards, or broadcaster tooling: |
| 9 | + |
| 10 | +- 🔐 **OAuth 2.1 helpers** with PKCE utilities, refresh rotation, and token revocation |
| 11 | +- 💬 **Chat client** ready for bot *and* broadcaster messages, including replies |
| 12 | +- 📺 **Livestream, channel, moderation, kicks, and users** endpoints behind a unified client |
| 13 | +- 🪝 **Webhook receivers** complete with signature verification and shared-secret support |
| 14 | +- 🧪 **Drop-in examples** for every endpoint, from quick scripts to production-ready bots |
| 15 | +- 🧰 **Multi-tenant bot framework** so multiple streamers can adopt your bot with a single deployment |
| 16 | + |
| 17 | +> **Status** – The codebase mirrors Kick’s public documentation as of 2025-10-27. Keep an eye on the [Kick Engineering announcements](https://github.com/KickEngineering/KickDevDocs) for new endpoints; extending `kapi-kit` is intentionally straightforward. |
| 18 | +
|
| 19 | +--- |
| 20 | + |
| 21 | +## Table of contents |
| 22 | + |
| 23 | +1. [Requirements](#requirements) |
| 24 | +2. [Installation](#installation) |
| 25 | +3. [Quick start](#quick-start) |
| 26 | +4. [Authentication flows](#authentication-flows) |
| 27 | +5. [API tour](#api-tour) |
| 28 | +6. [Example gallery](#example-gallery) |
| 29 | +7. [Multi-stream bot architecture](#multi-stream-bot-architecture) |
| 30 | +8. [Endpoint coverage](#endpoint-coverage) |
| 31 | +9. [Roadmap](#roadmap) |
| 32 | +10. [Contributing](#contributing) |
| 33 | +11. [License](#license) |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Requirements |
| 38 | + |
| 39 | +- **Node.js 22.0.0 or newer** (built-in `fetch` is used throughout) |
| 40 | +- **npm** or any compatible package manager |
| 41 | +- A registered [Kick developer application](https://kick.com/apps) with the scopes you plan to use |
| 42 | + |
| 43 | +Check your environment quickly: |
| 44 | + |
| 45 | +```bash |
| 46 | +npm run lint |
| 47 | +``` |
| 48 | + |
| 49 | +The command verifies Node.js version and `fetch` availability. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Installation |
| 54 | + |
| 55 | +```bash |
| 56 | +npm install kapi-kit |
| 57 | +``` |
| 58 | + |
| 59 | +or with pnpm: |
| 60 | + |
| 61 | +```bash |
| 62 | +pnpm add kapi-kit |
| 63 | +``` |
| 64 | + |
| 65 | +`kapi-kit` ships as native ESM – just use standard `import` syntax. |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## Quick start |
| 70 | + |
| 71 | +```js |
| 72 | +import { KickApiClient } from 'kapi-kit'; |
| 73 | + |
| 74 | +const client = new KickApiClient({ |
| 75 | + accessToken: process.env.KICK_ACCESS_TOKEN, // must include chat:write to send messages |
| 76 | +}); |
| 77 | + |
| 78 | +await client.sendChatMessage({ |
| 79 | + type: 'bot', |
| 80 | + content: 'Hello Kick! 👋', |
| 81 | +}); |
| 82 | +``` |
| 83 | + |
| 84 | +> Need scopes? Head to **Kick Dev Portal → Your App → Scopes** and grant `chat:write`. |
| 85 | +
|
| 86 | +--- |
| 87 | + |
| 88 | +## Authentication flows |
| 89 | + |
| 90 | +| Scenario | Helper | Notes | |
| 91 | +| --- | --- | --- | |
| 92 | +| App-to-app calls (Client Credentials) | `KickAuthClient#getAppAccessToken` | Use when no broadcaster auth is required. | |
| 93 | +| Interactive login (Authorization Code + PKCE) | `createPkcePair`, `createAuthorizationUrl`, `KickAuthClient#exchangeCodeForToken` | Guides end-users through the consent screen. | |
| 94 | +| Refreshing access tokens | `KickAuthClient#refreshAccessToken` | Returns a *new* access and refresh token. Persist it! | |
| 95 | +| Revoking tokens | `KickAuthClient#revokeToken` | Works with either access or refresh tokens. | |
| 96 | +| Token introspection | `KickApiClient#introspectToken` | Confirms validity, scope, and expiry. | |
| 97 | + |
| 98 | +🚦 **First time implementing OAuth?** Run `node examples/token-rotation.js`. It walks through the PKCE flow, stores the refresh token, and keeps rotating it so it never expires. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## API tour |
| 103 | + |
| 104 | +`kapi-kit` exposes a single high-level client plus targeted helpers: |
| 105 | + |
| 106 | +```js |
| 107 | +import { |
| 108 | + KickApiClient, |
| 109 | + KickChatClient, |
| 110 | + KickAuthClient, |
| 111 | + createAuthorizationUrl, |
| 112 | + createPkcePair, |
| 113 | + KickApiError, |
| 114 | +} from 'kapi-kit'; |
| 115 | +``` |
| 116 | + |
| 117 | +| Area | Methods | Example | |
| 118 | +| --- | --- | --- | |
| 119 | +| **Chat** | `client.sendChatMessage`, `chat.sendMessage` | `examples/chat-send.js` | |
| 120 | +| **Channels** | `client.getChannels`, `client.updateChannelMetadata` | `examples/channels-get.js`, `examples/channels-update.js` | |
| 121 | +| **Livestreams** | `client.getLivestreams`, `client.getLivestreamStats` | `examples/livestreams-list.js` | |
| 122 | +| **Events** | `client.list/create/deleteEventSubscriptions` | `examples/events.js` | |
| 123 | +| **Moderation** | `client.banUser`, `client.unbanUser` | `examples/moderation.js` | |
| 124 | +| **Kicks** | `client.getKicksLeaderboard` | `examples/kicks-leaderboard.js` | |
| 125 | +| **Users** | `client.getUsers` | `examples/users.js` | |
| 126 | +| **Public key** | `client.getPublicKey` | `examples/public-key.js` | |
| 127 | + |
| 128 | +Every method accepts an optional `AbortSignal` and raises a `KickApiError` with `status`, `statusText`, `body`, and `requestId` fields on failure. |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## Example gallery |
| 133 | + |
| 134 | +| Script | What it teaches | Typical use case | |
| 135 | +| --- | --- | --- | |
| 136 | +| `chat-send.js` | Send bot/broadcaster messages, replies, emotes | Simple bot posting updates | |
| 137 | +| `token-rotation.js` | Persistent refresh rotation + sample call | Long-running services | |
| 138 | +| `full-bot.js` | Single-channel bot with webhooks, `!ping`, `!title`, keep-alives | Bots for a single broadcaster | |
| 139 | +| `multi-stream-bot.js` | Multi-tenant bot with onboarding endpoint & webhook verification | SaaS bot adopted by many streamers | |
| 140 | +| `events.js` | Subscribe/unsubscribe/list webhook events | Dashboards & analytics | |
| 141 | +| `oauth-*` scripts | Client credentials, PKCE, refresh, revoke | Bootstrapping authentication flows | |
| 142 | + |
| 143 | +All scripts can be launched directly: |
| 144 | + |
| 145 | +```bash |
| 146 | +node examples/full-bot.js |
| 147 | +``` |
| 148 | + |
| 149 | +Each script documents the environment variables it reads—search for `process.env` inside the file for a cheat-sheet. |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## Multi-stream bot architecture |
| 154 | + |
| 155 | +`examples/multi-stream-bot.js` contains everything you need to run a “click to add bot” experience: |
| 156 | + |
| 157 | +1. **User clicks “Add Bot”** on your website → Kick redirects back with `code` + `code_verifier`. |
| 158 | +2. Your frontend POSTs `{ code, code_verifier }` (and the optional `redirect_uri`) to `POST /kick/streamers/add`, sending `Kick-App-Secret` in the header. |
| 159 | +3. The server exchanges the code for tokens, stores the refresh token in `multi-streamers.json`, subscribes to `chat.message.sent`, and schedules token refreshes + keep-alive messages for that broadcaster. |
| 160 | +4. Kick delivers chat events to `POST /kick/webhook`. The bot validates the signature *and* shared secret, then responds to commands: |
| 161 | + - `!ping` → `!pong` |
| 162 | + - `!title The New Title` updates the stream title |
| 163 | + - Keep-alive messages post every 5 minutes as both bot and broadcaster. |
| 164 | + |
| 165 | +Token refreshes are automatically persisted. If a broadcaster revokes access, refresh attempts will start failing—handle that by removing them from the store or prompting them to re-authorize. |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +## Endpoint coverage |
| 170 | + |
| 171 | +See [docs/coverage.md](docs/coverage.md) for the full matrix mapping each Kick endpoint to SDK methods and runnable examples. It mirrors the official [Kick Dev Docs](https://github.com/KickEngineering/KickDevDocs). |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## Roadmap |
| 176 | + |
| 177 | +- [ ] Streaming consumer for real-time chat without webhooks |
| 178 | +- [ ] Lightweight HTTP client plug-in (Axios/undici swap) |
| 179 | +- [ ] TypeScript type declarations (today we rely on JSDoc) |
| 180 | +- [ ] Optional Redis-backed token stores for multi-stream bots |
| 181 | + |
| 182 | +Got ideas or find a gap in Kick’s evolving API? Open an issue or PR—feedback is welcome! |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## Contributing |
| 187 | + |
| 188 | +1. Fork the repository. |
| 189 | +2. Install dependencies and run the lint check: |
| 190 | + ```bash |
| 191 | + npm install |
| 192 | + npm run lint |
| 193 | + ``` |
| 194 | +3. Add tests or examples if your change affects behaviour. |
| 195 | +4. Open a pull request against `main` describing the change and relevant Kick docs. |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +## License |
| 200 | + |
| 201 | +MIT © [Wydoyolo](https://github.com/Wydoyolo) |
| 202 | + |
| 203 | +Kick API documentation is owned by Kick. See the official docs for the latest platform terms. |
0 commit comments