Basics
Ask AI

askAI Function

Make sure you read through the Authentication page first, if you haven't already.

A function under the overarching Bard object, used for one-time queries to Bard.

Example

import Bard, { askAI } from "bard-ai";
 
await Bard.init(COOKIE_KEY);
 
console.log(await askAI("Hello world!"));

Parameters

ParameterTypeDescription
messagestringThe message you are querying Bard with. Required.
useJSONbooleanWhether or not to receive JSON response format. Default is false

Usage

The most simple usage simply involves passing your message into askAI, and calling it async. The response of askAI is a string in Markdown format, and it includes images, codeblocks, and other Markdown accessories.

💡

Notice how askAI is imported alongside the Bard object, with a deconstructuring import. Essentially, I am importing the askAI method of the Bard object separately, so that it is more concise to use. Feel free to also import Bard normally, and call askAI with Bard.askAI() instead.

You may also choose to pass in a secondary parameter to opt into recieving a JSON response. Read more about the JSON response here.