Bing AI Unofficial API

Automating Microsoft Edge & Parsing HTML for Bing AI

IMPORTANT NOTICE: This tool is intended for educational and development purposes only. The use of this unofficial API involves automating Microsoft Edge to interact with Bing AI, which is not officially supported or endorsed by Microsoft. Misuse of this tool may violate the terms of service for Bing or Microsoft Edge. By using this tool, you acknowledge and accept full responsibility for ensuring your actions comply with applicable laws and terms of use.

This unofficial API leverages Playwright and Microsoft Edge to automate the browser and intercept responses from Bing's AI chat interface. Since Bing requires Microsoft Edge to access its AI features, this approach relies on installing and running Edge headlessly (or otherwise) for programmatic control. The process is intended for educational or internal development purposes and is not an official Microsoft-supported API. This was created before the release of any publically accessible BingAI API.

Automating Edge

Since Bing AI enforces the use of Microsoft Edge, we must control an Edge instance, which we can do with Playwright. Playwright is an automation library that lets us programmatically send requests, parse the resulting DOM or network responses, and effectively build a local API for interacting with Bing AI. We must note that you need to have a Microsoft account to use Bing AI.

How to Install

Installing and running the unofficial Bing AI API server is straightforward:

  1. Install the requirements:
    pip install -r requirements.txt
  2. Install Playwright (one-time setup):
    playwright install
    # or if the 'playwright' command isn't recognized:
    ms-playwright install
    
  3. Run the server:
    python server.py
    # or specify the full file path:
    python /path/to/server.py
    
    By default, the server listens on port 5000. You can modify this port in server.py if needed.

API Documentation

The server exposes a single endpoint, /chat, which accepts GET requests:

curl -X GET "http://localhost:5000/chat?q=Write%20a%20python%20program%20to%20reverse%20a%20list"

The parameter q should contain the prompt or question you want Bing AI to answer. The response is then parsed from the automated Edge session and returned as JSON. Play around with your BingAI API!

Credits

This project's structure and boilerplate were inspired by ChatGPT Unofficial API by Tolulade Ademisoye.