https://github.com/tuhinpal/bingchat-api
Bing Chat unofficial API
https://github.com/tuhinpal/bingchat-api
ai bing bing-api bing-chat
Last synced: 5 months ago
JSON representation
Bing Chat unofficial API
- Host: GitHub
- URL: https://github.com/tuhinpal/bingchat-api
- Owner: tuhinpal
- License: mit
- Archived: true
- Created: 2023-02-24T15:41:52.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-18T14:11:32.000Z (over 1 year ago)
- Last Synced: 2024-11-07T23:47:57.969Z (11 months ago)
- Topics: ai, bing, bing-api, bing-chat
- Language: TypeScript
- Homepage:
- Size: 85.9 KB
- Stars: 163
- Watchers: 4
- Forks: 37
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

## Deployment
Deploy natively
```bash
git clone https://github.com/tuhinpal/bingchat-api.git
cd bingchat-api
npm run build
npm start
```Deploy with Docker
```bash
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`).
```javascript
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](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) stream to send content upon generation.
## Client library
Use the client library to implement these with ease.
```
npm install bing-chatai-client
``````javascript
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
- [@tuhinpal](https://www.github.com/tuhinpal)
## 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](https://github.com/tuhinpal/bingchat-api/blob/master/LICENSE). This project is made as a proof of concept and doesnot meant to harm microsoft.