Character AI Unofficial Node API
Node.js client for the unofficial Character AI API, an awesome website which brings characters to life with AI!
Intro
This repository is cloned from RealColoride unofficial node API. Though, I found it hard to use and it was not really stable and archived. So I remade it in javascript.
This project is not affiliated with Character AI in any way! It is a community project. The purpose of this project is to bring and build projects powered by Character AI.
If you like this project, please check their website.
Features
👍 Fully written in Javascript and CommonJS (for max compatibility and ease of use)⌚ Asynchronous requests🗣️ Use conversations or use the API to fetch information🧸 Easy to use🔁 Active development👤 Guest & token login support
Installation
npm install charai
Usage
Basic guest login and conversation message:
const CharacterAI = require('charai');
const characterAI = new CharacterAI();
(async() => {
await characterAI.authenticateAsGuest();
const characterId = "8_1NyR8w1dOXmI1uWaieQcd147hecbdIK7CeEAIrdJw" // Discord moderator
const chat = await characterAI.createOrContinueChat(characterId);
const response = await chat.sendAndAwaitResponse('Hello discord mod!', true)
console.log(response);
// use response.text to use it in a string.
})();
Using an Access Token
Some parts of the API, like managing a conversation requires for you to be logged in using an accessToken
.
To get it, you can open your browser, go to the character.ai website in localStorage
.
To do so:
- Open the Character AI website in your browser
- Open the developer tools
F12
and go to theApplication
tab. - Go to the
Storage
section and click onLocal Storage
. - Look for the
@@auth0spajs@@::dyD3gE281MqgISG7FuIXYhL2WEknqZzv::https://auth0.character.ai/::openid profile email offline_access
key. - Open the body and copy the access token.
When using the package, you can:
- Login as guest using
authenticateAsGuest()
- for mass usage or testing purposes - Login with your account or a token using
authenticateWithToken()
Finding the Character ID
You can find your character ID in the URL of a Character's chat page.
For example, if you go to the chat page of the character Test Character
you will see the URL https://character.ai/chat/chat?char=5f7f9b9b9b9b9b9b9b9b9b9b
.
The last part of the URL is the character ID:
Troubleshooting
Problem | Answer |
---|---|
Make sure your token is actually valid and you copied your entire token (its pretty long). | |
Upgrade to node 18 or higher (19 is better) or try installing node-fetch . |
|
authenticateAsGuest() doesn't work
|
See issue #14. |
Sadly, guest accounts only have a limited amount of messages before they get limited and forced to login. See below for more info |
|
You can use conversations, a feature introduced in 1.0.0 , to assign to users and channels. To reproduce a conversation, use OOC (out of character) to make the AI think you're with multiple people. See an example here: (Disclaimer: on some characters, their personality will make them ignore any OOC request). |
|
This is because as of currently, the simple fetching is broken and I use puppeteer (a chromium browser control library) to go around cloudflare's restrictions. | |
No, this project is made by a fan of the website and is unofficial. To support the developers, please check out their website. | |
node_characterai ?
|
Please let me know! |
See my profile | |
Open an issue in the Issues tab | |
Open an issue in the Issues tab |
Disclaimer
❤️ This project is updated frequently, always check for the latest version for new features or bug fixes.
(real)coloride - 2023, Licensed MIT.