- Published on
How to use Google Bard Unofficial API in JavaScript
- Authors
- Name
- Ashik Nesin
- @AshikNesin
Recently, we've talked about using Bard AI using Python
And here is how to do using it in a JavaScript environment.
It doesn't have any Node.js dependency and uses native fetch for fetching API calls. So it should work on any environment like browser/node/deno.
FYI: This is a community package reverse-engineering Google Bard web app so don't use it in any production environments
Getting Auth Cookie from Bard web app
As for the authentication part, we'll be using cookie value from the Bard web app.
We'll need to get __Secure-1PSID
cookie value from Bard
Dependency
We need to install bard-ai
using pip
npm install bard-ai
Snippet - Google Bard API
import Bard, { askAI } from "bard-ai";
const COOKIE_KEY = '...' // Your __Secure-1PSID here
console.log(await askAI("Say hello in Tamil"));
For other advanced use cases, you can refer to their docs
Happy chatting-with Bard!