CAIDeno
A lighweight Unofficial Character.AI API using Deno, It does not require a puppeteer to interact with c.ai because the interaction is done with websocket and HTTPS Request.
Table of contents
- Example usage
- Client
- login
- logout
- User
- image
- persona
- explore
- character
- character.votes
- character.votes_array
- character.vote
- character.search
- character.search_suggest
- character.info
- character.recent_list
- character.connect
- character.disconnect
- character.send_message
- character.generate_turn
- character.generate_turn_candidate
- character.reset_conversation
- character.delete_message
- character.edit_message
- group_chat
- group_chat.list
- group_chat.connect
- group_chat.disconnect
- group_chat.create
- group_chat.delete
- group_chat.rename
- group_chat.join_group_invite
- group_chat.char_add
- group_chat.char_remove
- group_chat.send_message
- group_chat.generate_turn
- group_chat.generate_turn_candidate
- group_chat.reset_conversation
- group_chat.delete_message
- group_chat.edit_message
- group_chat.select_turn
- chat
- Issues
Example usage
import CAIDeno from "https://deno.land/x/caideno/mod.ts";
const client = new CAIDeno();
async function start() {
await client.login("Your token")
console.log("Logged in!")
client.logout()
}
start()
Client
Import client from module
import CAIDeno from "https://deno.land/x/caideno/mod.ts";
const client = new CAIDeno();
login()
Start client initialization with login, make sure your token is valid so that the login session can run properly.
This is the tutorial of how to get C.AI sessionToken
On PC:
- Open the Character.AI website in your browser (https://beta.character.ai)
- Open the developer tools (F12, Ctrl+Shift+I, or Cmd+J)
- Go to the
Application
tab - Go to the
Storage
section and click onLocal Storage
- Look for the
char_token
key - Open the object, right click on value and copy your session token.
On Mobile:
- Open the Character.AI website in your browser (https://beta.character.ai)
- Open the URL bar, write
javascript:
(case sensitive) and paste the following:
(function(){let e=window.localStorage["char_token"];if(!e){alert("You need to log in first!");return;}let t=JSON.parse(e).value;document.documentElement.innerHTML=`<div><i><p>provided by node_characterai - <a href="https://github.com/realcoloride/node_characterai?tab=readme-ov-file#using-an-access-token">click here for more information</a></p></i><p>Here is your session token:</p><input value="${t}" readonly><p><strong>Do not share this with anyone unless you know what you are doing! Those are your personal session token. If stolen or requested by someone you don't trust, they could access your account without your consent; if so, please close the page immediately.</strong></p><button id="copy" onclick="navigator.clipboard.writeText('${t}'); alert('Copied to clipboard!')">Copy session token to clipboard</button><button onclick="window.location.reload();">Refresh the page</button></div>`;localStorageKey=null;storageInformation=null;t=null;})();
- The following page should appear:
- Click the respective buttons to copy your access token or id token to your clipboard.
await client.login("YOUR_CHARACTER_AI_TOKEN");
Param | Require | Type | Description |
---|---|---|---|
Token | true |
String |
Your character ai token used for client login. |
logout()
Logout from the client
await client.logout();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Used for client logout from character ai. |
user.info()
Get your account information data.
client.user.info;
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Get user information account. |
user.settings()
Get your account settings information data.
await client.user.settings();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Get user settings information. |
image.generate_avatar()
Generate avatar image using prompt.
await client.image.generate_avatar(prompt_name);
Param | Require | Type | Description |
---|---|---|---|
prompt_name | true |
String |
Prompt used for generating avatar image. |
image.generate_image()
Generate image using prompt.
await client.image.generate_image(prompt_name);
Param | Require | Type | Description |
---|---|---|---|
prompt_name | true |
String |
Prompt used for generating AI image. |
persona.create()
Create your personality for your character.
await client.persona.create(name, description);
Param | Require | Type | Description |
---|---|---|---|
name | true |
String |
Your persona name |
description | true |
String |
Description of your personality, this section is used to describe yourself so that your AI character knows who you are. |
persona.set_default()
Set your default personality specifically.
await client.persona.set_default(external_persona_id);
Param | Require | Type | Description |
---|---|---|---|
external_persona_id | true |
String |
External personality id that you have. |
persona.list()
Get all your personality data.
await client.persona.list();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Get all your personality data. |
persona.info()
Get your personality information.
await client.persona.info(external_persona_id);
Param | Require | Type | Description |
---|---|---|---|
external_persona_id | true |
String |
External personality id that you have. |
persona.update()
Update your personality specifically.
await client.persona.update(external_persona_id, name, description);
Param | Require | Type | Description |
---|---|---|---|
external_persona_id | true |
String |
External personality id that you have. |
name | true |
String |
Your new personality name. |
description | true |
String |
Your new personality detail. |
persona.delete()
Used for deleting your personality spesifically.
await client.persona.delete(external_persona_id);
Param | Require | Type | Description |
---|---|---|---|
external_persona_id | true |
String |
External personality id that you have. |
persona.set_character()
Set a custom personality for your character specifically.
await client.persona.set_character(character_id, external_persona_id);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
A character id that you want to set a custom personality. |
external_persona_id | true |
String |
Your personality id that you use to let AI characters know who you are. |
explore.featured()
Get the list of characters displayed by the character.ai server.
await client.explore.featured();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Get all featured data. |
explore.for_you()
Get a list of characters recommended by the character.ai server.
await client.explore.for_you();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Get all for you data. |
explore.character_categories()
Get the list of characters from the character category exploration.
await client.explore.character_categories();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Get all character categories data. |
character.votes()
Get character vote information.
await client.character.votes(character_id);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
The character id you are aiming for. |
character.votes_array()
Get character vote information in array.
await client.character.votes_array(character_id);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
The character id you are aiming for. |
character.vote()
Used for vote the character.
await client.character.vote(character_id, vote);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
The character id you are aiming for. |
vote | true |
Boolean |
Character vote options, true = like , false = dislike , and null = cancel |
character.search()
Search for a character by name or query.
await client.character.search(name);
Param | Require | Type | Description |
---|---|---|---|
name | true |
String |
Search queries to find characters. |
character.search_suggest()
Search character by name and suggested by Character.AI Server
await client.character.search_suggest(name);
Param | Require | Type | Description |
---|---|---|---|
name | true |
String |
Character name query. |
character.info()
Get detailed information about characters.
await client.character.info(character_id);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
Your character id. |
character.recent_list()
Get a list of recent chat activity
await client.character.recent_list();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Get recent character chats. |
character.connect()
Connect client to character chat
await client.character.connect(character_id);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
Your character id. |
character.disconnect()
Disconnecting client from character chat
await client.character.disconnect();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Disconnecting client from character chat. |
character.send_message()
Send message to character.
await client.character.send_message(message, manual_turn, image_url);
Param | Require | Type | Description |
---|---|---|---|
message | true |
String |
Message content. |
manual_turn | false |
Boolean |
If the value of manual_turn is set to true then the message that the client receives must be generated with character.generate_turn() so that the message is obtained by the client. |
image_url | false |
String |
The image content that the character will see, must be a url and not a file type or a file with a type other than image. |
character.generate_turn()
Generating message response from character.
await client.character.generate_turn();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Generate message response |
character.generate_turn_candidate()
Regenerate character message.
await client.character.generate_turn_candidate(turn_id);
Param | Require | Type | Description |
---|---|---|---|
turn_id | true |
String |
turn_id or message_id from the character. |
character.reset_conversation()
Reset the conversation between you and the character.
await client.character.reset_conversation();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
none |
character.delete_message()
Delete character message.
await client.character.delete_message(turn_id);
Param | Require | Type | Description |
---|---|---|---|
turn_id | true |
String |
turn_id or message_id from the character. |
character.edit_message()
Edit the character message.
await client.character.edit_message(candidate_id, turn_id, new_message);
Param | Require | Type | Description |
---|---|---|---|
candidate_id | true |
String |
|
turn_id | true |
String |
turn_id or message_id from the character. |
new_message | true |
String |
New character message |
group_chat.list()
Get all list available group chat in account.
await client.group_chat.list();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
none |
group_chat.connect()
Connecting to group chat by the room_id
, btw you can’t connect the group chat before you create it.
await client.group_chat.connect(room_id);
Param | Require | Type | Description |
---|---|---|---|
room_id | true |
String |
Your group chat id. |
group_chat.disconnect()
Disconnecting from group chat by the room_id
.
await client.group_chat.disconnect(room_id);
Param | Require | Type | Description |
---|---|---|---|
room_id | true |
String |
Your group chat id. |
group_chat.create()
Create a custom room chat.
await client.group_chat.create(title_room, character_id);
Param | Require | Type | Description |
---|---|---|---|
title_room | true |
String |
Your custom title room name. |
character_id | true |
String |
Your character id will be added to the group chat. |
group_chat.delete()
Delete group chat.
await client.group_chat.delete(room_id);
Param | Require | Type | Description |
---|---|---|---|
room_id | true |
String |
Your group chat id. |
group_chat.rename()
Rename group chat.
await client.group_chat.rename(new_name, room_id);
Param | Require | Type | Description |
---|---|---|---|
new_name | true |
String |
New name for your group chat. |
room_id | true |
String |
Your group chat id. |
group_chat.join_group_invite()
Joining group chat using invite code.
await client.group_chat.join_group_invite(invite_code);
Param | Require | Type | Description |
---|---|---|---|
invite_code | true |
String |
The group chat miinvite code. |
group_chat.char_add()
Add a character with character_id
to the group chat.
await client.group_chat.char_add(character_id);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
Character id to be added to the group chat. |
group_chat.char_remove()
Remove a character with character_id
from the group chat.
await client.group_chat.char_remove(character_id);
Param | Require | Type | Description |
---|---|---|---|
character_id | true |
String |
Character id to be removed from the group chat. |
group_chat.send_message()
Send message to character in group chat.
await client.character.send_message(message, image_url);
Param | Require | Type | Description |
---|---|---|---|
message | true |
String |
Message content. |
image_url | false |
String |
The image content that the character will see, must be a url and not a file type or a file with a type other than image. |
group_chat.generate_turn()
Generating message response character from group chat.
await client.group_chat.generate_turn();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Generate message response |
group_chat.generate_turn_candidate()
Regenerate character message.
await client.group_chat.generate_turn_candidate(turn_id);
Param | Require | Type | Description |
---|---|---|---|
turn_id | true |
String |
turn_id or message_id from the character. |
group_chat.reset_conversation()
Reset conversation in group chat.
await client.group_chat.reset_conversation();
Param | Require | Type | Description |
---|---|---|---|
none | false |
null |
Reset conversation. |
group_chat.delete_message()
Delete character message.
await client.group_chat.delete_message(turn_id);
Param | Require | Type | Description |
---|---|---|---|
turn_id | true |
String |
turn_id or message_id from the character. |
group_chat.edit_message()
Edit character message in group chat.
await client.group_chat.edit_message(candidate_id, turn_id, new_message);
Param | Require | Type | Description |
---|---|---|---|
candidate_id | true |
String |
|
turn_id | true |
String |
turn_id or message_id from the character. |
new_message | true |
String |
New character message |
group_chat.select_turn()
Select the turn of character chat by yourself.
await client.group_chat.select_turn(turn_id);
Param | Require | Type | Description |
---|---|---|---|
turn_id | true |
String |
turn_id or message_id from the character. |
chat.history_chat_turns()
Get a history chat from group or single chat.
await client.chat.history_chat_turns(chat_id);
Param | Require | Type | Description |
---|---|---|---|
chat_id | true |
String |
Group chat or single chat ID. |
Issues
Feel free to open the issue, I hope this documentation can help you maximally and make it easier for you to use this package.
Documentation written by ZTRdiamond