# ccat-api

> API Client to communicate with the Cheshire Cat AI

Latest version **0.12.1** (published 2025-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install ccat-api
pnpm add ccat-api
yarn add ccat-api
bun add ccat-api
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.1 |
| Published | 2025-01-22 |
| First published | 2023-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 135.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | zAlweNy26 |
| Maintainers | danyalwe |
| Keywords | ccat, cheshire-cat, api, client, fastapi, openapi, ai, llm, chat, bot |

## Links

- npm: https://www.npmjs.com/package/ccat-api
- Repository: https://github.com/zAlweNy26/ccat-api
- Issues: https://github.com/zAlweNy26/ccat-api/issues
- npm.io page: https://npm.io/package/ccat-api

## Dependencies (5)

- [ws](https://npm.io/package/ws.md) ^8.18.0
- [axios](https://npm.io/package/axios.md) ^1.7.9
- [@types/ws](https://npm.io/package/@types/ws.md) ^8.5.13
- [form-data](https://npm.io/package/form-data.md) ^4.0.1
- [isomorphic-ws](https://npm.io/package/isomorphic-ws.md) ^5.0.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.12.1 (latest) — 2025-01-22
- 0.12.0 — 2025-01-21
- 0.11.3 — 2024-10-15
- 0.11.2 — 2024-10-07
- 0.11.1 — 2024-10-04
- 0.11.0 — 2024-07-24
- 0.10.6 — 2024-03-26
- 0.10.5 — 2024-03-26
- 0.10.4 — 2024-03-26
- 0.10.3 — 2024-03-06
- 0.10.2 — 2024-03-02
- 0.10.1 — 2024-03-01
- 0.10.0 — 2024-02-28
- 0.9.3 — 2024-02-13
- 0.9.2 — 2024-01-19
- … 27 more at https://npm.io/package/ccat-api/versions

## README

<a href="https://github.com/cheshire-cat-ai/api-client-ts">
  <img alt="GitHub Stars" src="https://img.shields.io/github/stars/cheshire-cat-ai/api-client-ts?logo=github&style=flat-square">
</a>
<a href="https://discord.gg/bHX5sNFCYU">
  <img alt="Discord Server" src="https://img.shields.io/discord/1092359754917089350?logo=discord&style=flat-square">
</a>
<a href="https://npmjs.com/package/ccat-api">
  <img alt="NPM Version" src="https://img.shields.io/npm/v/ccat-api?logo=npm&style=flat-square">
</a>
<a href="https://npmjs.com/package/ccat-api">
  <img alt="NPM Downloads" src="https://img.shields.io/npm/dw/ccat-api?logo=npm&style=flat-square">
</a>
<a href="https://bundlephobia.com/package/ccat-api">
  <img alt="Bundle Size" src="https://img.shields.io/bundlephobia/minzip/ccat-api?logo=npm&style=flat-square">
</a>

# Cheshire Cat AI API Client

API Client made in TypeScript to communicate with the [Cheshire Cat AI](https://github.com/cheshire-cat-ai/core).\
The package provides a class to interface with the Cheshire Cat AI backend.\
It can be used both in Browser and NodeJS environments.

Every endpoint is a `CancelablePromise`, which means you can cancel the request if you want.

## Installation

```bash
npm i ccat-api
# OR
yarn add ccat-api
# OR
pnpm i ccat-api
# OR
bun i ccat-api
```

## Getting started

To set up the client, you must first import the `CatClient` class:

```ts
import { CatClient } from 'ccat-api'

const cat = new CatClient({
    host: 'localhost',
    userId: 'user',
    //... other settings
})

cat.send('Hello from a user!') // this will send a message to the /ws/user

cat.userId = 'new_user'

cat.send('Hello from a new user!') // this will send a message to the /ws/new_user
```

## Client settings

**CCAT_API_KEY**, **CCAT_CORE_HOST**, **CCAT_CORE_PORT** and **CCAT_CORE_USE_SECURE_PROTOCOLS** refer to the CCAT Core [.env file](https://github.com/cheshire-cat-ai/core/blob/main/.env.example).

| **Property**   | **Type** | **Default**  | **Description**                                                                  |
|:--------------:|:--------:|:------------:|:--------------------------------------------------------------------------------:|
| **host**       | string   | **Required** | The same of **CCAT_CORE_HOST**                                                   |
| **credential** | string   | undefined    | The same of **CCAT_API_KEY** or the JWT token                                    |
| **port**       | number   | 1865         | The same of the **CCAT_CORE_PORT**                                               |
| **secure**     | boolean  | false        | The same of the **CCAT_CORE_USE_SECURE_PROTOCOLS**                               |
| **user**       | string   | 'user'       | The user ID to use for the WebSocket and the API client                          |
| **instant**    | boolean  | true         | Instantly initialize the WebSocket and the API client, or later with **.init()** |
| **timeout**    | number   | 10000        | Timeout for the endpoints, in milliseconds                                       |
| **ws**         | string   | undefined    | An object of type [WebSocketSettings](#websocket-settings)                       |

### WebSocket settings

| **Property** | **Type** | **Default** | **Description**                                           |
|:------------:|:--------:|:-----------:|:---------------------------------------------------------:|
| **retries**  | number   | 3           | The maximum number of retries before calling **onFailed** |
| **delay**    | number   | 3000        | The delay for reconnect, in milliseconds                  |
| **onFailed** | function | undefined   | The function to call after failing all the retries        |

Then, for example, you can configure the LLM like this:

```ts
cat.api.llm.upsertLlmSetting('LLMOpenAIConfig', {
    openai_api_key: 'OPEN_API_KEY'
})
```

To send a message to the cat, you can:

```ts
cat.send('Hello my friend!')
```

You can listen to the WebSocket events:

```ts
cat.onConnected(() => {
    console.log('Socket connected')
}).onMessage(msg => {
    console.log(msg)
}).onError((err, e) => {
    console.error(err, e)
}).onDisconnected(() => {
    console.log('Socket disconnected')
})
```

For example, you can get the list of plugins like this:

```ts
cat.api.plugins.listAvailablePlugins().then(plugins => {
    console.log(plugins)
})
```

## Credits

Made for the [Cheshire Cat AI](https://github.com/cheshire-cat-ai) organization.

This was possible thanks to [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen).

---
_Source: https://npm.io/package/ccat-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
