Here’s an improved version of the README, with the announcement included and without the star history section:
An unofficial Python API for Character AI using curl-cffi.
This project is scheduled to be discontinued. However, a new and improved version, PyCAI3
, will be released soon in a different repository. Stay tuned for updates here: PyCAI3 Repository.
Join our Discord server for updates and support: https://discord.gg/xxaA8eKMvM.
pip install PyCAI2
- Download FFmpeg: https://www.ffmpeg.org/download.html
- Follow the installation guide: FFmpeg Installation Guide
Do not share your token. The token is needed for authorization and operation of requests from your account.
- Open DevTools in your browser.
- Go to Storage -> Local Storage ->
char_token
. - Copy the
value
.
- Open a character chat in
chat2
. - Example URL:
https://beta.character.ai/chat2?char=piwvxvcMQFwbQXCQpJdzbqPMg9ck4FaYi4NWM86ERXo&source=recent-chats
. - Copy from
char=
until&source=
. - Example:
piwvxvcMQFwbQXCQpJdzbqPMg9ck4FaYi4NWM86ERXo
.
- Go to:
neo.character.ai/chats/recent/<CHAR ID>
. - Example URL:
neo.character.ai/chats/recent/piwvxvcMQFwbQXCQpJdzbqPMg9ck4FaYi4NWM86ERXo
. - Look for the following JSON key:
{"chats": [{"chat_id": "8880583d-fa2c-47f8-89e6-4fcf09c14a38",
. - Copy the
chat_id
.
- Follow the steps to get the Chat ID.
- Look for the following JSON key:
"creator_id": "474480773"
. - Copy the
creator_id
.
from PyCAI2 import PyAsyncCAI2
owner_id = '54dbda---------'
char = "piwvxvcMQFwb----------"
room_id = "TiqLm-------------"
voice_target = "E:\\FOLDER\\FOLDER\\FOLDER\\FOLDER\\FOLDER"
client = PyAsyncCAI2(owner_id)
async def main():
message = input("You: ")
# TRANSLATE FROM INDONESIAN TO ENGLISH
await client.chat2.transl(text=message, target='en', source='id')
# GET HISTORIES
await client.chat2.get_histories(char=char)
# GET HISTORY
await client.chat2.get_history(char=char)
# GET AVATAR
await client.chat2.get_avatar(char=char)
# CREATE IMAGE
async with client.connect(owner_id) as chat2:
# RETURN MESSAGE + IMAGE LINK
await chat2.create_img(char=char, text=message, author_name='FALCO', Return_all=True)
# RETURN IMAGE LINK ONLY
await chat2.create_img(char=char, text=message, author_name='FALCO', Return_img=True)
# SEND MESSAGE
async with client.connect(owner_id) as chat2:
# RETURN MESSAGE WITH NAME
await chat2.send_message(char=char, text=message, author_name="FALCO", Return_name=True)
# RETURN MESSAGE WITHOUT NAME
await chat2.send_message(char=char, text=message, author_name="FALCO", Return_name=False)
# START A NEW CHAT
async with client.connect(owner_id) as chat2:
# WITH GREETING
await chat2.new_chat(char=char, with_greeting=True)
# WITHOUT GREETING
await chat2.new_chat(char=char, with_greeting=False)
# DELETE MESSAGE
async with client.connect(owner_id) as chat2:
# GET TURN ID FROM HISTORY FUNCTION
await chat2.delete_message(char=char, turn_ids=turn_id)