> ## Documentation Index
> Fetch the complete documentation index at: https://sferadev.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# keycloak-api

> Type-safe Keycloak Admin & Account API client

A type-safe API client for the [Keycloak](https://www.keycloak.org/) Admin and Account APIs, auto-generated from the official OpenAPI specification with full TypeScript support.

## Features

* **Type-Safe** - Full TypeScript support with auto-generated types from OpenAPI spec
* **Admin API** - Complete Keycloak Admin REST API coverage
* **Account API** - User account management endpoints
* **Auto-Updated** - Daily regeneration from upstream OpenAPI specs

## Installation

<CodeGroup>
  ```bash pnpm theme={null}
  pnpm add keycloak-api
  ```

  ```bash npm theme={null}
  npm install keycloak-api
  ```

  ```bash yarn theme={null}
  yarn add keycloak-api
  ```
</CodeGroup>

## Usage

### Admin API Usage

```typescript theme={null}
import { createClient } from "keycloak-api";

const client = createClient({
  baseUrl: "https://keycloak.example.com/admin/realms",
  headers: {
    Authorization: `Bearer ${process.env.KEYCLOAK_ADMIN_TOKEN}`,
  },
});

// List all realms
const realms = await client.getRealms();

// Get users in a realm
const users = await client.getUsers({
  realm: "my-realm",
});

// Create a new user
const user = await client.createUser({
  realm: "my-realm",
  body: {
    username: "newuser",
    email: "user@example.com",
    enabled: true,
  },
});
```

### Type Exports

```typescript theme={null}
import type { Types } from "keycloak-api";

// Use TypeScript types
type Realm = Types.RealmRepresentation;
type User = Types.UserRepresentation;
type Client = Types.ClientRepresentation;
```

## API Reference

The client exposes Keycloak API endpoints including:

### Admin API

* **Realms** - Realm management and configuration
* **Users** - User CRUD operations and management
* **Clients** - OAuth/OIDC client configuration
* **Roles** - Role management and assignment
* **Groups** - Group management and membership
* **Identity Providers** - Federation configuration
* **Authentication** - Authentication flow configuration
* **And more...**

### Account API

* **Profile** - User profile management
* **Credentials** - Credential management
* **Sessions** - Active session management

For the complete API reference, see the [Keycloak Admin REST API documentation](https://www.keycloak.org/docs-api/latest/rest-api/).
