Skip to main content

bingart is an unofficial async API wrapper for Bing Image & Video Creator

Project description

bingart

bingart is an unofficial async API wrapper for Bing Image & Video Creator. It allows you to programmatically generate AI-powered images and videos using Bing's creation tools with support for multiple models and aspect ratios.

Warning: The _U auth cookie should be changed every 2-4 weeks for proper functionality.

Description

This module uses web scraping and engineering techniques to interface with Bing's internal image and video creation APIs. It is not an official API client.

Key Features

  • Fully asynchronous — built on curl_cffi AsyncSession and asyncio
  • Generate images with multiple AI models (DALL-E, GPT-4O, MAI1)
  • Generate videos from text prompts
  • Custom aspect ratios (Square, Landscape, Portrait)
  • Get image URLs — up to 4 generated images per request
  • Flexible authentication via cookies or auto-fetched from browsers
  • Enhanced prompts — get AI-improved versions of your prompts
  • Async context manager support (async with)
  • Custom exceptions for common error handling

Installation

pip install bingart

Usage

Basic Setup

Import and instantiate the BingArt class with a valid _U cookie value:

import asyncio
from bingart import BingArt

async def main():
    bing_art = BingArt(auth_cookie_U='your_cookie_value_here')
    try:
        result = await bing_art.generate('sunset over mountains')
        print(result)
    finally:
        await bing_art.close()

asyncio.run(main())

Using Async Context Manager (Recommended)

import asyncio
from bingart import BingArt

async def main():
    async with BingArt(auth_cookie_U='your_cookie_value_here') as bing_art:
        result = await bing_art.generate('sunset over mountains')
        print(result)

asyncio.run(main())

Auto Cookie Detection

Let bingart automatically fetch cookies from your installed browsers:

from bingart import BingArt

# Auto-fetch cookies from Chrome, Edge, Firefox, Brave, Opera, Vivaldi, or Chromium
bing_art = BingArt(auto=True)

Supported browsers for auto-detection:

  • Chrome
  • Edge
  • Firefox
  • Brave
  • Opera
  • Vivaldi
  • Chromium

Advanced Usage with Models and Aspect Ratios

import asyncio
from bingart import BingArt, Model, Aspect

async def main():
    async with BingArt(auth_cookie_U='your_cookie_value') as bing_art:
        # Generate with GPT-4O model in portrait aspect
        result = await bing_art.generate(
            'a futuristic cityscape',
            model=Model.GPT4O,
            aspect=Aspect.PORTRAIT
        )
        print(result)

        # Generate with MAI1 model in landscape aspect
        result = await bing_art.generate(
            'serene mountain landscape',
            model=Model.MAI1,
            aspect=Aspect.LANDSCAPE
        )
        print(result)

        # Generate with DALL-E (default) in square aspect
        result = await bing_art.generate(
            'abstract art composition',
            model=Model.DALLE,
            aspect=Aspect.SQUARE
        )
        print(result)

asyncio.run(main())

Available Models

from bingart import Model

Model.DALLE    # DALL-E 3 (default)
Model.GPT4O    # GPT-4O image generation
Model.MAI1     # MAI1 model

Available Aspect Ratios

from bingart import Aspect

Aspect.SQUARE      # 1:1 (default)
Aspect.LANDSCAPE   # 7:4 (wide)
Aspect.PORTRAIT    # 4:7 (tall)

Video Generation

import asyncio
from bingart import BingArt

async def main():
    async with BingArt(auth_cookie_U='your_cookie_value') as bing_art:
        result = await bing_art.generate(
            'a dancing robot in a futuristic city',
            content_type='video'
        )
        print(result)

asyncio.run(main())

Output Format

Image Generation Response

{
  "images": [
    {"url": "https://th.bing.com/th/id/OIG.xxx?pid=ImgGn"},
    {"url": "https://th.bing.com/th/id/OIG.yyy?pid=ImgGn"},
    {"url": "https://th.bing.com/th/id/OIG.zzz?pid=ImgGn"},
    {"url": "https://th.bing.com/th/id/OIG.www?pid=ImgGn"}
  ],
  "prompt": "enhanced version of your original prompt",
  "model": "GPT4O",
  "aspect": "PORTRAIT"
}

Video Generation Response

{
  "video": {
    "video_url": "https://..."
  },
  "prompt": "your original prompt"
}

Exception Handling

import asyncio
from bingart import BingArt, AuthCookieError, PromptRejectedError

async def main():
    try:
        async with BingArt(auth_cookie_U='your_cookie_value') as bing_art:
            result = await bing_art.generate('your prompt here')
            print(result)
    except AuthCookieError:
        print("Invalid authentication cookie or session expired")
    except PromptRejectedError:
        print("Prompt was rejected due to content policy violation")

asyncio.run(main())

Available Exceptions

  • AuthCookieError: Raised when authentication cookie is invalid or expired
  • PromptRejectedError: Raised when prompt violates content policy or is rejected as unethical

Getting Your Cookie

  1. Open your browser and go to Bing Image Creator
  2. Log in with your Microsoft account
  3. Open Developer Tools (F12)
  4. Go to Application/Storage → Cookies → https://www.bing.com
  5. Find the _U cookie and copy its value

Complete Example

import asyncio
from bingart import BingArt, Model, Aspect, AuthCookieError, PromptRejectedError

async def main():
    try:
        async with BingArt(auto=True) as bing_art:
            # Generate multiple images with different settings
            prompts = [
                {
                    "query": "cyberpunk cityscape at night",
                    "model": Model.GPT4O,
                    "aspect": Aspect.LANDSCAPE
                },
                {
                    "query": "portrait of a mystical wizard",
                    "model": Model.DALLE,
                    "aspect": Aspect.PORTRAIT
                },
                {
                    "query": "abstract geometric patterns",
                    "model": Model.MAI1,
                    "aspect": Aspect.SQUARE
                }
            ]

            for config in prompts:
                print(f"\nGenerating: {config['query']}")
                result = await bing_art.generate(
                    config['query'],
                    model=config['model'],
                    aspect=config['aspect']
                )

                print(f"Model: {result['model']}")
                print(f"Aspect: {result['aspect']}")
                print(f"Enhanced prompt: {result['prompt']}")
                print(f"Generated {len(result['images'])} images")

                for idx, img in enumerate(result['images'], 1):
                    print(f"  Image {idx}: {img['url']}")

            # Generate a video
            print("\nGenerating video...")
            video_result = await bing_art.generate(
                'a cat playing piano',
                content_type='video'
            )
            print(f"Video URL: {video_result['video']['video_url']}")

    except AuthCookieError as e:
        print(f"Authentication error: {e}")
    except PromptRejectedError as e:
        print(f"Prompt rejected: {e}")

asyncio.run(main())

Requirements

  • Python >= 3.6
  • curl_cffi
  • rookiepy

Contributing

Pull requests are welcome! Please open an issue to discuss major changes before submitting.

License

MIT License - see LICENSE file for details

Disclaimer

This is an unofficial API wrapper and is not affiliated with Microsoft or Bing. Use responsibly and in accordance with Bing's terms of service.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bingart-1.5.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bingart-1.5.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file bingart-1.5.1.tar.gz.

File metadata

  • Download URL: bingart-1.5.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for bingart-1.5.1.tar.gz
Algorithm Hash digest
SHA256 97d517be8fd61ac7a90247ecdae0c513af7ef781a2c5c581554f4d89f271d18d
MD5 45965356cd48b77a2cedca116c7e7c00
BLAKE2b-256 75cab892f99dc9ab5ef77720d9e3a6f3f896c8a10f1bfac1e347986d1291944d

See more details on using hashes here.

File details

Details for the file bingart-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: bingart-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for bingart-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7747fc7ae4ddb58a34741327cb025043f357922982552dcb88037edd185e4409
MD5 bd13f28c5c1d4b310a775d9509dcca69
BLAKE2b-256 bff21d8252005fa8ebf66d9563ae9ddd2a5c8069b835fc86dfb4074060366eba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page