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
_Uauth cookie should be changed every 2-4 weeks for proper functionality.
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.
- Fully asynchronous — built on
curl_cffiAsyncSessionandasyncio - 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
pip install bingartImport 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())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())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
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())from bingart import Model
Model.DALLE # DALL-E 3 (default)
Model.GPT4O # GPT-4O image generation
Model.MAI1 # MAI1 modelfrom bingart import Aspect
Aspect.SQUARE # 1:1 (default)
Aspect.LANDSCAPE # 7:4 (wide)
Aspect.PORTRAIT # 4:7 (tall)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()){
"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": {
"video_url": "https://..."
},
"prompt": "your original prompt"
}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())AuthCookieError: Raised when authentication cookie is invalid or expiredPromptRejectedError: Raised when prompt violates content policy or is rejected as unethical
- Open your browser and go to Bing Image Creator
- Log in with your Microsoft account
- Open Developer Tools (F12)
- Go to Application/Storage → Cookies →
https://www.bing.com - Find the
_Ucookie and copy its value
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())- Python >= 3.6
- curl_cffi
- rookiepy
Pull requests are welcome! Please open an issue to discuss major changes before submitting.
MIT License - see LICENSE file for details
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.