# SDKs and tools

The Kling packages for developers in Iceland. @klingis/sdk for your server, @klingis/embed for the browser, @klingis/cli to set up a project in one command and @klingis/mcp for AI agents.

Kling has four npm packages. All of them work with test keys straight away.

| Package | What it is |
|---|---|
| [`@klingis/sdk`](https://www.npmjs.com/package/@klingis/sdk) | Typed server SDK for the Kling API, generated from the OpenAPI spec |
| [`@klingis/embed`](https://www.npmjs.com/package/@klingis/embed) | The [payment window](https://kling.is/en/docs/embedded-checkout): checkout as an overlay on your site |
| [`@klingis/cli`](https://www.npmjs.com/package/@klingis/cli) | Connects a project to Kling in one command |
| [`@klingis/mcp`](https://www.npmjs.com/package/@klingis/mcp) | [MCP server](https://kling.is/en/docs/mcp) for AI agents |

## @klingis/cli

```bash
npx @klingis/cli init
```

`init` signs you in (or creates an account), detects your framework (Next.js, Remix, Astro, Express, Hono, Elysia or plain HTML), asks what you are building, can register a [webhook](https://kling.is/en/docs/webhooks), writes `KLING_SECRET_KEY`, `KLING_API_URL` and `KLING_WEBHOOK_SECRET` to `.env.local` (and adds it to `.gitignore`), and writes `KLING_INTEGRATION.md`, a prompt for your AI editor.

Other commands: `kling status`, `kling login`, `kling login --api-key <key>` (for CI), `kling logout`, `kling env [live|test]` and `kling listen --forward <url>`. With `npx`, write `npx @klingis/cli status` and so on.

## @klingis/sdk

```bash
npm install @klingis/sdk
```

```typescript
import { configure, postV1CheckoutSessions } from "@klingis/sdk";

configure({
  baseUrl: "https://api.kling.is",
  headers: { Authorization: `Bearer ${process.env.KLING_SECRET_KEY}` },
});

const res = await postV1CheckoutSessions({
  amount: 5000, // 5.000 kr.
  currency: "ISK",
  success_url: "https://example.is/thanks",
});

if (res.status === 200) console.log(res.data.id, res.data.url);
```

Function names follow the method and path: `POST /v1/checkout/sessions` is `postV1CheckoutSessions`, `GET /v1/customers/{id}` is `getV1CustomersById`. Each returns `{ data, status, headers }`. The SDK uses the global `fetch` and runs in Bun and in bundled server code (Next.js, Remix, SvelteKit, Vite). In plain Node ESM without a bundler, call the REST API with `fetch` instead.

## @klingis/embed

```bash
npm install @klingis/embed
```

Or `<script src="https://api.kling.is/v1/kling.js"></script>`. See [Payment window](https://kling.is/en/docs/embedded-checkout).

## @klingis/mcp

Lets AI agents such as Claude, ChatGPT and Cursor work with your Kling account. See [MCP server](https://kling.is/en/docs/mcp).
