Skip to content

levi6769/janitorai.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

janitorai.js

Unofficial Node.js library for JanitorAI

npm version ^ 24hr cooldown i will publish it soon😭

⚠️ Disclaimer

This is an unofficial library and is not affiliated with or endorsed by JanitorAI. Use at your own risk. This library is for educational and personal use only.


Install

npm install janitorai.js

Requires Node.js 18+


Getting Your Token

  1. Open janitorai.com in your browser
  2. Open DevTools → Network tab → Filter by Fetch/XHR
  3. Click any character or do any action
  4. Find any /hampter/ request → Headers tab → copy the Authorization: Bearer xxxxx value (without "Bearer ")

⚠️alert: Tokens expire every ~30 minutes. You'll need to refresh it periodically.


Quick Start

const { JanitorClient } = require('janitorai.js');

const client = new JanitorClient({ token: 'YOUR_BEARER_TOKEN' });

async function main() {
  // initialize (launches a stealth browser to bypass Cloudflare)
  await client.login();

  // browse trending characters
  const trending = await client.getTrending({ mode: 'weekly' });
  console.log(trending[0].name); // "Some Character"

  // start a chat
  const chat = await client.createChat(trending[0].id);

  // set your profile (required for generating replies)
  chat.setProfile({
    id: 'YOUR_USER_ID',
    name: 'YOUR_NAME',
    user_name: 'YOUR_USERNAME'
  });

  // wait for the bot's greeting
  const greeting = await chat.waitForGreeting();
  console.log('Bot:', greeting);

  // send a message and get a reply
  const reply = await chat.sendMessage('Hello!');
  console.log('Bot:', reply);

  await client.destroy();
}

main();

API Reference

new JanitorClient(options)

Option Type Required Description
token string yes Your JanitorAI Bearer token

client.login()

Initializes the stealth browser. Must be called before anything else.

client.destroy()

Closes the browser. Call when done.

client.getTrending(options?)

Returns an array of Character objects.

Option Type Default Description
page number 1 Page number
mode string 'weekly' 'weekly' or '24hr'

client.getCharacter(characterId)

Returns a single Character object by ID.

client.searchCharacters(query, options?)

Search for characters by name.

client.createChat(characterId, personaId?)

Creates a new chat session. Returns a Chat object.


Character

Property Type Description
id string Character UUID
name string Character name
description string Character description
tags string[] Character tags

Chat

chat.setProfile(profile)

Set your user profile for generating replies. Required before sendMessage().

chat.setProfile({
  id: 'your-user-id',
  name: 'Your Name',
  user_name: 'your_username'
});

chat.setPersonas(personas)

Optionally set your persona.

chat.sendMessage(text)

Send a message and returns the bot's reply as a string.

chat.waitForGreeting(options?)

Waits for the bot's opening message after chat creation. Returns the greeting string.

Option Type Default Description
timeout number 15000 Max wait time in ms

chat.getMessages()

Returns all messages in the chat as an array.


Examples

Discord Bot

See examples/discord-bot.js for a full Discord bot implementation.

Simple Chat Script

const { JanitorClient } = require('janitorai.js');
const readline = require('readline');

const client = new JanitorClient({ token: 'YOUR_TOKEN' });

const rl = readline.createInterface({ input: process.stdin, output: process.stdout });

async function main() {
  await client.login();

  const trending = await client.getTrending();
  const char = trending[0];
  console.log(`Starting chat with: ${char.name}`);

  const chat = await client.createChat(char.id);
  chat.setProfile({ id: 'user-id', name: 'User', user_name: 'user' });

  const greeting = await chat.waitForGreeting();
  console.log(`\n${char.name}: ${greeting}\n`);

  const ask = () => {
    rl.question('You: ', async (input) => {
      const reply = await chat.sendMessage(input);
      console.log(`\n${char.name}: ${reply}\n`);
      ask();
    });
  };
  ask();
}

main();

Known Limitations & Technical Notes

Token Expiry

  • Bearer tokens expire every 30 minutes
  • You need to manually grab a fresh one from devtools each time
  • Auto-refresh is on the roadmap

Supabase Backend

JanitorAI uses Supabase for auth. Some technical details for contributors:

  • Project URL: https://mcmzxtzommpnxkynddbo.supabase.co
  • Refresh token flow: POST to /auth/v1/token?grant_type=refresh_token
  • Tokens expire at: roughly August 2026 based on the JWT exp field

Contact

Discord: sidecharactered feel free to DM for questions or contributions or custom orders.

License

MIT

About

Unofficial Node.js library for JanitorAI ; browse characters, create chats, and send messages programmatically.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors