An NPM module for creating GoogleBard chatbot using Bard’s reverse-engineered API. With reverse-engineered API functionalities, it empowers developers to harness the full potential of Bard.
Table Of Contents
Features
- **Simulating Response Streaming**: The package simulates response streaming, allowing you to get the response as soon as it is available.
- **Multiple Conversations**: The package supports multiple conversations, allowing you to have multiple parallel conversations with the chatbot.
- **Proxy Support**: The package supports proxies, allowing you to use the chatbot from any location.
- **Lightweight**: The package is very lightweight, making it easy to use and integrate into your projects.
Prerequisites – How to get cookies?
1. Install Cookie-Editor extension.
2. Go to bard.google.com and login.
3. Click on the extension icon and copy a cookie starting with __Secure-account_numberPSID. For example, __Secure-1PSID.
4. Ensure you are copying the correct cookie corresponding to the account number, which can be found in the URL as bard.google.com/u/account_number. If your account number is u2, search for the cookie named __Secure-2PSID. If your account number is u3, search for the cookie named __Secure-3PSID.
5. Paste the cookie in your code.
Installation
To install the package, run the following command:
npm install googlebard
Documentation
1. How To Initialise The Bot?
import Bard from googlebard;
let cookies = __Secure-1PSID=YOUR_COOKIE;
let bot = new Bard(cookies);
2. How To Configure Bot With Optional Settings?
To configure the bot with optional settings, use the following structure:
import Bard from googlebard;
let cookies = __Secure-1PSID=YOUR_COOKIE;
let bot = new Bard(cookies, {
inMemory: false,
savePath: .conversations.json,
proxy: {
host: process.env.PROXY_HOST,
port: process.env.PROXY_PORT,
auth: {
username: process.env.PROXY_USERNAME,
password: process.env.PROXY_PASSWORD,
},
protocol: http,
}
});
3. How To Ask Bot?
To ask the bot questions, implement the following:
import Bard from googlebard;
let cookies = __Secure-1PSID=YOUR_COOKIE;
let bot = new Bard(cookies);
let conversationId = some_random_id; // optional to make it remember the conversation
let response = await bot.ask("What is my name?", conversationId);
console.log(response); // Outputs: "I don’t know your name. I am a large language model, also known as a conversational AI..."
4. How To Ask Bot And Simulate Response Streaming?
For response streaming, use the following code:
import Bard from googlebard;
let cookies = __Secure-1PSID=YOUR_COOKIE;
let bot = new Bard(cookies, {
inMemory: false,
savePath: .conversations.json,
});
let conversationId = test_id;
await bot.askStream((res) => {
console.log(res);
}, "Hello?", conversationId);
5. How To Reset A Conversation?
Resetting a conversation allows the bot to forget previous interactions:
import Bard from googlebard;
let cookies = __Secure-1PSID=YOUR_COOKIE;
let bot = new Bard(cookies, {
inMemory: false,
savePath: .conversations.json,
});
let conversationId = test_id;
let response = await bot.ask("What is my name?", conversationId);
console.log(response); // Outputs: "You told me your name is Mehul."
bot.resetConversation(conversationId);
response = await bot.ask("What is my name?", conversationId);
console.log(response); // Outputs: "I understand that you are trying to get me to say your name, but..."
6. How To Get All Your Previous Conversations?
Retrieve previous conversations using:
import Bard from googlebard;
let cookies = __Secure-1PSID=YOUR_COOKIE;
let bot = new Bard(cookies, {
savePath: .conversations.json,
});
let response = bot.getAllConversations();
console.log(response); // returns an array of different conversations
7. How To Get A Single Conversation By ID?
import Bard from googlebard;
let cookies = __Secure-1PSID=YOUR_COOKIE;
let bot = new Bard(cookies, {
inMemory: false,
savePath: .conversations.json,
});
let conversationId = test_id;
await bot.waitForLoad();
let response = bot.getConversationById(conversationId);
console.log(response); // returns an object
Examples
A simple example has been added to the examples directory, showing how GoogleBard can be used to create a CLI chatbot. More examples are yet to be added, so stay tuned!
Troubleshooting
Common Issues:
- Issue with Cookies: If your cookie isn’t working, ensure that you are copying the right cookie starting with __Secure-account_numberPSID.
- Connection Issues: If you’re having trouble connecting from certain locations, ensure your proxy settings are correctly configured.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

