Skip to content

mbaker-ipcg/bingchat-api

 
 

Repository files navigation

Bing Chat API

Deployment

Deploy natively

  git clone https://github.com/tuhinpal/bingchat-api.git
  cd bingchat-api
  npm run build
  npm start

Deploy with Docker

  git clone https://github.com/tuhinpal/bingchat-api.git
  cd bingchat-api
  docker build -t bingchat-api .
  docker run -it -d -p 8080:8080 bingchat-api

Or, You can fork this repository and connect it to any provider which supports Docker/NodeJS.

Post Deploy

This api need your cookie to generate conversation. So, you should have beta access. After deployment login to that bing account and open developer console. Then paste the code (replace your serverUrl).

const cookie = document.cookie;
const serverUrl = "http://localhost:8080";

fetch(`${serverUrl}/set-cookie`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ cookie }),
})
  .then((res) => res.json())
  .then((res) => console.log(res))
  .catch((err) => console.log(err));

API Reference

Create a conversation

  POST /create-conversation

Generate

  GET /generate
Query Parameter Type Description
conversationId string Required. Get it after /create-conversation
clientId string Required. Get it after /create-conversation
conversationSignature string Required. Get it after /create-conversation
text string Required. Text prompt

Note: It uses EventSource stream to send content upon generation.

Client library

Use the client library to implement these with ease.

npm install bing-chatai-client
import { createConversation, Generate } from "bing-chatai-client";

const conversation = await createConversation("http://localhost:8080");

console.log(conversation);

const gen = new Generate(conversation.conversationUrl);

gen.generate("Hello bing what is an ai?");

gen.onMessage((data) => {
  console.log(data);
});

gen.onFinished((message) => {
  console.info(message);
});

gen.onError((message) => {
  console.error(message);
});

Author

Feedback

If you have any feedback, please reach me out at me[at]thetuhin.com.

Contributing

Contributions are always welcome!

License and Leagal

This project is licensed under MIT. This project is made as a proof of concept and doesnot meant to harm microsoft.

About

Bing Chat unofficial API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 68.7%
  • JavaScript 23.9%
  • HTML 5.4%
  • Dockerfile 2.0%