Skip to content

Bing Chat API: An Exciting Node.js Client for Chat Interfaces

Artificial Intelligence (AI) has revolutionized communication, and the Bing Chat API is a testament to this revolution. Similar to ChatGPT but with enhanced capabilities, it offers a seamless chat experience, particularly when implemented with Node.js.

Be cautious, it's not meant for use in production as this package is reverse-engineered and unsupported by Microsoft officially.


Introduction to Bing Chat API

Bing Chat API is a Node.js wrapper around Bing Chat, developed by Microsoft. It has included TypeScript batteries for better functionality. The API acts as an interface for creating a chatbot. However, it's an unofficial, reverse-engineered package that might not continue working long-term. Despite this, its performance and capabilities are commendable and continue to attract developers.

Bing Chat API Demonstration

The Bing Chat API allows for dynamic conversations with a virtual assistant, and the 30-second demo showcases this feature brilliantly. The conversation flows naturally, and the responses are accurate and relevant, giving a glimpse of the API's power.

Installation Process

Installing the Bing Chat API is straightforward. Simply run npm install bing-chat. However, ensure you're using Node.js version 18 or above so that fetch is available.

Bing Chat API Usage

To use Bing Chat API, you require access to Bing Chat or a valid cookie from someone who has access. The _U cookie or all cookies concatenated together will suffice. Once this is done, you can easily import the package, initiate the Bing Chat instance using the cookie, and begin sending messages.

import { BingChat } from 'bing-chat'
async function example() {
  const api = new BingChat({
    cookie: process.env.BING_COOKIE
  const res = await api.sendMessage('Hello World!')

Bing Chat API allows follow-up messages to continue the conversation. Keep in mind, Bing Chat conversations expire after about 20 minutes. They're not meant to be long-term objects.

The API also supports streaming through the onProgress handler:

const res = await api.sendMessage('Write a 500 word essay on frogs.', {
  // print the partial response as the AI is "typing"
  onProgress: (partialResponse) => console.log(partialResponse.text)
// print the full text at the end

Moreover, you can change the variant of the AI through the variant parameter in the sendMessage function. The default variant is 'Balanced', but 'Precise' or 'Creative' can be chosen as well.

Projects and Compatibility

The Bing Chat API is an excellent tool for developing innovative chat interfaces. If you create a cool integration, you're encouraged to open a PR and add it to the list. In terms of compatibility, the package supports Node.js version 18 and above and assumes that fetch is installed globally. It is ESM-only and recommended to be used only from your backend API if you aim to build a website using it.

The Bing Chat API is undoubtedly an interesting tool in the world of AI and chatbots. While it's not meant for production use, its functionality and performance make it worth exploring for those interested in AI-powered communication.

You can check out the GitHub project here (opens in a new tab).

Wrapping It Up: The Power and Potential of Bing Chat API

In conclusion, Bing Chat API emerges as a promising Node.js client for building dynamic and engaging chat interfaces. With its straightforward installation process, ease of usage, and capabilities like streaming and AI variant control, it undoubtedly stands as a testament to how far AI-powered communication has come. Even as it's not intended for production use, its current capabilities serve as a beacon for the future of AI in communication. With continued advancements, we can expect to see even more refined, robust, and reliable solutions in the future, revolutionizing how we interact with technology.