diff --git a/CHANGELOG.md b/CHANGELOG.md index 341ec62..ca9f3d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.0] + +### Added + +- `client.monitor.bing_aimode()` for Bing AI Mode, + `POST /v1/monitor/bing/aimode`. It accepts `prompt`, `country`, `state` (US + only) and `include` (`markdown`, `html`). +- The `BING_AIMODE` task type for `client.async_tasks`. +- The Bing AI Mode path, its request and response schemas, the `BING_AIMODE` + task type and the `bing_aimode` countries model in the vendored + `openapi.json`. + ## [0.3.0] ### Removed diff --git a/README.md b/README.md index d67db38..ba61e78 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The official Python SDK for [**cloro**](https://cloro.dev), the API for Google Search and AI answers. It gives you a Google SERP API, a Google News API, and answers from -ChatGPT, Gemini, Google AI Mode and Google AI Overview. cloro +ChatGPT, Gemini, Google AI Mode, Bing AI Mode and Google AI Overview. cloro also runs an [MCP server](https://cloro.dev/docs/integrations/mcp) that exposes its monitor endpoints as tools for Claude, Codex, Cursor or your own agent. @@ -52,6 +52,7 @@ Google Search and Google News take a `query`. client.monitor.chatgpt(prompt="...", country="US") client.monitor.gemini(prompt="...", country="US") client.monitor.aimode(prompt="...", country="US") # Google AI Mode +client.monitor.bing_aimode(prompt="...", country="US") # Bing AI Mode client.monitor.google(query="best crm", country="US", pages=1) client.monitor.google_news(query="acme corp", country="US") @@ -60,6 +61,32 @@ client.monitor.google_news(query="acme corp", country="US") Pass `include={...}` to request extra formats: `markdown`, `html`, `searchQueries`, `shopping`, and more, depending on the engine. +### Bing AI Mode + +`bing_aimode()` gets the answer from Bing AI Mode. The +result has `text`, `sources` and `citationPills`. Set `include` to get +`markdown`, or `html` (a URL to the HTML of the page that Bing shows). Use +`state` to target a US state. `state` is valid only with `country="US"`. + +```python +res = client.monitor.bing_aimode( + prompt="best running shoes for flat feet", + country="US", + state="CA", + include={"markdown": True, "html": True}, +) + +print(res["result"]["text"]) +for pill in res["result"]["citationPills"]: + print(pill["citationPillId"], pill["domain"], pill["url"]) +``` + +The prompt can have a maximum of 3,500 characters after URL encoding. Non-Latin +scripts take more characters when encoded, so the limit for them is lower. A +request costs 4 credits, plus 2 credits for a sync request and 2 credits when +you set `state`. An async task (`BING_AIMODE`) does not have the 2-credit sync +charge. `client.countries(model="bing_aimode")` gives the supported countries. + ## Async task queue For high-volume or long-running work, enqueue tasks and poll them to completion. @@ -106,8 +133,8 @@ Queue-wide status: client.async_tasks.status() # queued / processing counts, concurrency usage ``` -Valid `task_type` values: `CHATGPT`, `GEMINI`, `AIMODE`, `GOOGLE`, -`GOOGLE_NEWS`. +Valid `task_type` values: `CHATGPT`, `GEMINI`, `AIMODE`, `BING_AIMODE`, +`GOOGLE`, `GOOGLE_NEWS`. ## Configuration @@ -154,6 +181,7 @@ with `TaskFailedError` / `TaskTimeoutError` from the poller and ```python client.countries() # supported countries client.countries(model="chatgpt") +client.countries(model="bing_aimode") client.states() # US states for location-targeted Google ``` diff --git a/openapi.json b/openapi.json index 2d9b2dc..34d3d11 100644 --- a/openapi.json +++ b/openapi.json @@ -990,6 +990,200 @@ } } }, + "/v1/monitor/bing/aimode": { + "post": { + "summary": "Monitor Bing AI Mode Responses", + "description": "Extract structured data from Bing AI Mode about your brand, products, or any topic across various regions. Costs 4 credits, plus 2 credits for a sync request and 2 credits for US state targeting.", + "operationId": "monitorBingAiMode", + "requestBody": { + "description": "Request parameters for monitoring Bing AI Mode responses", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/BingAiModeMonitorRequest" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "successful Bing AI Mode monitoring response", + "headers": { + "X-Concurrent-Limit": { + "description": "Maximum number of concurrent requests allowed", + "schema": { + "type": "integer", + "example": 10 + } + }, + "X-Concurrent-Current": { + "description": "Current number of concurrent requests", + "schema": { + "type": "integer", + "example": 3 + } + }, + "X-Concurrent-Remaining": { + "description": "Number of remaining concurrent slots available", + "schema": { + "type": "integer", + "example": 7 + } + }, + "X-Credits-Remaining": { + "description": "Number of credits remaining in user account", + "schema": { + "type": "integer", + "example": 4 + } + }, + "X-Credits-Charged": { + "description": "Number of credits charged for this request", + "schema": { + "type": "integer", + "example": 5 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/BingAiModeMonitorResponse" + } + } + } + }, + "400": { + "description": "Bad Request - Validation error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationError" + } + } + } + }, + "401": { + "description": "Unauthorized - Authentication error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AuthenticationError" + } + } + } + }, + "403": { + "description": "Forbidden - Insufficient permissions or credits", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenError" + } + } + } + }, + "404": { + "description": "Not Found - Route not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotFoundError" + } + } + } + }, + "409": { + "description": "Conflict - Resource conflict", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ConflictError" + } + } + } + }, + "429": { + "description": "Too Many Requests", + "headers": { + "X-Concurrent-Limit": { + "description": "Maximum number of concurrent requests allowed", + "schema": { + "type": "integer", + "example": 10 + } + }, + "X-Concurrent-Current": { + "description": "Current number of concurrent requests", + "schema": { + "type": "integer", + "example": 11 + } + }, + "X-Concurrent-Remaining": { + "description": "Number of remaining concurrent slots available", + "schema": { + "type": "integer", + "example": 0 + } + }, + "X-Credits-Remaining": { + "description": "Number of credits remaining in user account", + "schema": { + "type": "integer", + "example": 4 + } + }, + "X-Credits-Charged": { + "description": "Number of credits charged for this request", + "schema": { + "type": "integer", + "example": 0 + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ConcurrentLimitError" + } + } + } + }, + "499": { + "description": "Client Closed Request - Request was canceled", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CanceledError" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InternalError" + } + } + } + }, + "502": { + "description": "Bad Gateway - External service error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ExternalServiceError" + } + } + } + } + } + } + }, "/v1/countries": { "get": { "summary": "List of countries", @@ -1004,6 +1198,7 @@ "type": "string", "enum": [ "aimode", + "bing_aimode", "chatgpt", "gemini", "google" @@ -1522,6 +1717,7 @@ "type": "string", "enum": [ "AIMODE", + "BING_AIMODE", "GOOGLE", "GOOGLE_NEWS", "GEMINI", @@ -1699,6 +1895,7 @@ "type": "string", "enum": [ "AIMODE", + "BING_AIMODE", "GOOGLE", "GOOGLE_NEWS", "GEMINI", @@ -5574,6 +5771,194 @@ } } }, + "BingAiModeMonitorRequest": { + "required": [ + "prompt", + "country" + ], + "type": "object", + "properties": { + "prompt": { + "description": "The prompt to send to Bing AI Mode. Maximum 3,500 characters after URL encoding. Non-Latin scripts take more characters when encoded, so the limit for them is lower.", + "type": "string", + "minLength": 1, + "maxLength": 3500, + "example": "What are the best laptops for programming?" + }, + "country": { + "description": "Country/region code (ISO 3166-1 alpha-2) for localized response. All countries are supported except BY, CN, IR, RU, SY and VE. Use GET /v1/countries?model=bing_aimode to get the list.", + "type": "string", + "example": "US" + }, + "state": { + "$ref": "#/components/schemas/StateParameter" + }, + "include": { + "description": "Optional flags for including additional response formats", + "type": "object", + "properties": { + "html": { + "description": "Include a URL to the full HTML of Bing's rendered page", + "type": "boolean", + "default": false, + "example": true + }, + "markdown": { + "description": "Include markdown-formatted response in the result", + "type": "boolean", + "default": false, + "example": true + } + }, + "default": { + "html": false, + "markdown": false + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "BingAiModeMonitorResponse": { + "required": [ + "success", + "result" + ], + "type": "object", + "properties": { + "success": { + "type": "boolean", + "example": true + }, + "result": { + "description": "Bing AI Mode response data", + "type": "object", + "required": [ + "text", + "sources", + "citationPills" + ], + "properties": { + "text": { + "type": "string", + "description": "Bing AI Mode's response text", + "example": "Here are some excellent laptop recommendations for programming..." + }, + "sources": { + "type": "array", + "description": "Array of sources referenced in the response", + "items": { + "type": "object", + "properties": { + "position": { + "type": "number", + "description": "The position index of the source in the response", + "example": 1 + }, + "url": { + "type": "string", + "description": "The URL of the source", + "example": "https://example.com/article" + }, + "label": { + "type": "string", + "description": "The display label for the source", + "example": "AI Source" + }, + "description": { + "type": "string", + "description": "A description of the source content", + "example": "AI-generated recommendations" + } + } + }, + "example": [ + { + "position": 1, + "url": "https://example.com/ai-recommendations", + "label": "AI Source", + "description": "AI-curated laptop recommendations" + } + ] + }, + "citationPills": { + "type": "array", + "description": "Inline citation pills extracted from the Bing AI Mode answer. Each entry is one (pill, source) pair. Entries from the same pill share a `citationPillId`. Group by `citationPillId` to recover the pill-level structure.", + "items": { + "type": "object", + "required": [ + "label", + "citationPillId", + "url", + "domain", + "position" + ], + "properties": { + "label": { + "type": "string", + "description": "Title of the cited source.", + "example": "Best Laptops 2026 — Reuters" + }, + "citationPillId": { + "type": "integer", + "description": "1-based ordinal shared by all entries from the same pill.", + "example": 1 + }, + "url": { + "type": "string", + "description": "Direct URL of the cited source.", + "example": "https://example.com/best-laptops-2026" + }, + "domain": { + "type": "string", + "description": "Host extracted from `url`, for grouping and display.", + "example": "example.com" + }, + "description": { + "type": "string", + "description": "Source description, when Bing supplies one.", + "example": "A guide to the top laptops for software development this year." + }, + "position": { + "type": "integer", + "description": "1-based position of this source in the sibling `result.sources` array.", + "example": 1 + } + } + }, + "example": [ + { + "label": "Best Laptops 2026 — Reuters", + "citationPillId": 1, + "url": "https://example.com/best-laptops-2026", + "domain": "example.com", + "description": "A guide to the top laptops for software development this year.", + "position": 1 + }, + { + "label": "MacBook Pro M4 Hands-On Review", + "citationPillId": 1, + "url": "https://example.com/macbook-pro-review", + "domain": "example.com", + "position": 3 + } + ] + }, + "markdown": { + "type": "string", + "description": "Bing AI Mode's response formatted in Markdown (included when include.markdown is true)", + "example": "Here are some excellent laptop recommendations for programming..." + }, + "html": { + "type": "string", + "format": "uri", + "description": "A URL to the full HTML of Bing's rendered page (included when include.html is true)", + "example": "https://storage.cloro.dev/results/c45a5081-808d-4ed3-9c86-e4baf16c8ab8/page-1.html" + } + } + } + } + }, "ShoppingCard": { "type": "object", "description": "Shopping product card with detailed product information", diff --git a/pyproject.toml b/pyproject.toml index 8e78650..193136e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "cloro" dynamic = ["version"] -description = "Official Python SDK for the cloro API: one API for Google Search and every AI answer engine (ChatGPT, Gemini, AI Overview, AI Mode)." +description = "Official Python SDK for the cloro API: one API for Google Search and every AI answer engine (ChatGPT, Gemini, AI Overview, Google AI Mode, Bing AI Mode)." readme = "README.md" requires-python = ">=3.8" license = { text = "MIT" } @@ -17,6 +17,7 @@ keywords = [ "ai search", "chatgpt", "gemini", + "bing", "google search", "web scraping", "seo", diff --git a/src/cloro/__init__.py b/src/cloro/__init__.py index eedae3a..16ee7f2 100644 --- a/src/cloro/__init__.py +++ b/src/cloro/__init__.py @@ -1,7 +1,7 @@ """cloro — the official Python SDK. One API for Google Search and every AI answer engine (ChatGPT, Gemini, -AI Overview, AI Mode). Real-time, structured JSON. +AI Overview, Google AI Mode, Bing AI Mode). Real-time, structured JSON. from cloro import Cloro diff --git a/src/cloro/_client.py b/src/cloro/_client.py index 0a16172..45d9a9b 100644 --- a/src/cloro/_client.py +++ b/src/cloro/_client.py @@ -87,7 +87,7 @@ class Cloro: """Client for the cloro API. One API for Google Search and every AI answer engine (ChatGPT, Gemini, - AI Overview, AI Mode). Real-time, structured JSON. + AI Overview, Google AI Mode, Bing AI Mode). Real-time, structured JSON. Args: api_key: Your cloro API key (``sk_live_...``). Falls back to the diff --git a/src/cloro/_version.py b/src/cloro/_version.py index 493f741..6a9beea 100644 --- a/src/cloro/_version.py +++ b/src/cloro/_version.py @@ -1 +1 @@ -__version__ = "0.3.0" +__version__ = "0.4.0" diff --git a/src/cloro/resources/async_tasks.py b/src/cloro/resources/async_tasks.py index d098046..317fc81 100644 --- a/src/cloro/resources/async_tasks.py +++ b/src/cloro/resources/async_tasks.py @@ -87,8 +87,8 @@ def create( """Enqueue a single task. ``POST /v1/async/task``. Args: - task_type: One of ``CHATGPT``, ``GEMINI``, ``AIMODE``, ``GOOGLE``, - ``GOOGLE_NEWS``. + task_type: One of ``CHATGPT``, ``GEMINI``, ``AIMODE``, ``BING_AIMODE``, + ``GOOGLE``, ``GOOGLE_NEWS``. payload: Provider-specific body (e.g. ``{"prompt": ..., "country": ...}``, or ``{"query": ..., "country": ...}`` for Google Search). priority: 1-10, higher runs first (default 1). diff --git a/src/cloro/resources/monitor.py b/src/cloro/resources/monitor.py index 53bc67f..4eac144 100644 --- a/src/cloro/resources/monitor.py +++ b/src/cloro/resources/monitor.py @@ -51,6 +51,26 @@ def aimode( {"prompt": prompt, "country": country, "include": include, **extra}, ) + def bing_aimode( + self, + prompt: str, + country: str, + *, + state: Optional[str] = None, + include: Optional[Dict[str, bool]] = None, + **extra: Any, + ) -> Any: + """Monitor Bing AI Mode. ``POST /v1/monitor/bing/aimode``. + + The prompt can have a maximum of 3,500 characters after URL encoding. + ``state`` is a US state code and is valid only with ``country="US"``. + ``include`` accepts ``markdown`` and ``html``. + """ + return self._run( + "/v1/monitor/bing/aimode", + {"prompt": prompt, "country": country, "state": state, "include": include, **extra}, + ) + # -- Google Search (query-based) ------------------------------------ def google( diff --git a/tests/test_client.py b/tests/test_client.py index 925308c..41e347a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,6 +1,8 @@ """Unit tests — no network; all HTTP is served by httpx.MockTransport.""" from __future__ import annotations +import json + import httpx import pytest @@ -65,6 +67,91 @@ def handler(request: httpx.Request) -> httpx.Response: assert seen["url"].endswith("/v1/monitor/google") +def test_monitor_bing_aimode_request_and_response(): + seen = {} + + def handler(request: httpx.Request) -> httpx.Response: + seen["url"] = str(request.url) + seen["body"] = json.loads(request.content) + return httpx.Response( + 200, + json={ + "success": True, + "result": { + "text": "hi", + "sources": [{"position": 1, "label": "A", "url": "https://a.example"}], + "citationPills": [ + {"position": 1, "label": "A", "url": "https://a.example", + "domain": "a.example", "citationPillId": 1} + ], + }, + }, + ) + + client = make_client(handler) + res = client.monitor.bing_aimode( + prompt="hello", country="US", state="CA", include={"markdown": True, "html": True} + ) + + assert seen["url"] == "https://api.cloro.dev/v1/monitor/bing/aimode" + assert seen["body"] == { + "prompt": "hello", + "country": "US", + "state": "CA", + "include": {"markdown": True, "html": True}, + } + assert res["result"]["citationPills"][0]["citationPillId"] == 1 + + +def test_monitor_bing_aimode_drops_unset_state(): + seen = {} + + def handler(request: httpx.Request) -> httpx.Response: + seen["body"] = json.loads(request.content) + return httpx.Response(200, json={"success": True, "result": {}}) + + client = make_client(handler) + client.monitor.bing_aimode(prompt="x", country="GB") + assert seen["body"] == {"prompt": "x", "country": "GB"} + + +def test_async_create_bing_aimode_task(): + seen = {} + + def handler(request: httpx.Request) -> httpx.Response: + seen["url"] = str(request.url) + seen["body"] = json.loads(request.content) + return httpx.Response( + 200, + json={ + "success": True, + "task": {"id": "t-2", "taskType": "BING_AIMODE", "status": "QUEUED", + "priority": 1, "createdAt": "2026-11-07T12:00:00.000Z"}, + "credits": {"creditsToCharge": 4, "creditsCharged": None}, + }, + ) + + client = make_client(handler) + task = client.async_tasks.create( + task_type="BING_AIMODE", payload={"prompt": "x", "country": "US"} + ) + assert seen["url"] == "https://api.cloro.dev/v1/async/task" + assert seen["body"] == {"taskType": "BING_AIMODE", "payload": {"prompt": "x", "country": "US"}} + assert task.task_type == "BING_AIMODE" + + +def test_countries_for_bing_aimode(): + seen = {} + + def handler(request: httpx.Request) -> httpx.Response: + seen["url"] = str(request.url) + return httpx.Response(200, json=["US", "GB"]) + + client = make_client(handler) + client.countries(model="bing_aimode") + assert seen["url"] == "https://api.cloro.dev/v1/countries?model=bing_aimode" + + def test_discontinued_engines_are_not_exposed(): client = Cloro(api_key="sk_test") assert not hasattr(client.monitor, "copilot")