Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bc2/core/common/azure_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ def _estimate_document_intelligence(
) -> dict[str, Any]:
model = str(call.get("model") or "")
features = call.get("features") or []
if model != "prebuilt-read":
meter_names = {
"prebuilt-read": "S0 Read Pages",
"prebuilt-layout": "S0 Pre-built Pages",
}
meter_name = meter_names.get(model)
if meter_name is None:
raise AzurePricingUnavailable(
f"unsupported Document Intelligence model: {model or '<unknown>'}"
)
Expand All @@ -158,11 +163,11 @@ def _estimate_document_intelligence(
matches = [
item
for item in items
if item.get("meterName") == "S0 Read Pages"
if item.get("meterName") == meter_name
and item.get("type") == "Consumption"
and float(item.get("tierMinimumUnits") or 0) == 0
]
meter = _select_unique_price(matches, "S0 Read Pages")
meter = _select_unique_price(matches, meter_name)
component = _price_quantity(pages, meter, "pages")
return _cost_result([component], fetched_at)

Expand Down
4 changes: 2 additions & 2 deletions bc2/core/common/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ def _openai_provider(client: OpenAI | AsyncOpenAI) -> str:
host = (parsed.hostname or "").lower()
if (
"/openai/" in parsed.path
or host == "openai.azure.com"
or host.endswith(".openai.azure.com")
or host in ("openai.azure.com", "openai.azure.us")
or host.endswith((".openai.azure.com", ".openai.azure.us"))
):
return "azure"
return "openai"
Expand Down
27 changes: 27 additions & 0 deletions bc2/core/common/test_azure_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,33 @@ def test_estimate_document_intelligence_read_cost(monkeypatch):
assert estimate["estimated_cost"] == pytest.approx(0.0375)


def test_estimate_document_intelligence_layout_cost(monkeypatch):
pricing = AzureRetailPricing()
meter = {
"skuName": "S0",
"meterName": "S0 Pre-built Pages",
"retailPrice": 10.0,
"unitOfMeasure": "1K",
"tierMinimumUnits": 0,
"type": "Consumption",
}
monkeypatch.setattr(
pricing, "_get_prices", lambda _: ([meter], "2026-07-10T00:00:00+00:00")
)

estimate = pricing.estimate(
{
"service": "document_intelligence",
"model": "prebuilt-layout",
"features": [],
"usage": {"pages": 25},
},
{"azure_region": "eastus"},
)

assert estimate["estimated_cost"] == pytest.approx(0.25)


def test_estimate_embedding_cost(monkeypatch):
pricing = AzureRetailPricing()
meter = _meter("text-embedding-3-large-glbl", 0.00013, "1K")
Expand Down
15 changes: 15 additions & 0 deletions bc2/core/common/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@
OpenAIChatPromptInline,
OpenAIChatTurn,
OpenAIClientConfig,
_openai_provider,
)
from .usage import create_usage_tracker, usage_operation, usage_tracking


@pytest.mark.parametrize(
"base_url",
[
"https://example.openai.azure.com/",
"https://example.openai.azure.us/",
],
)
def test_openai_provider_recognizes_azure_clouds(base_url):
client = MagicMock()
client.base_url = base_url

assert _openai_provider(client) == "azure"


def test_fix_azure_endpoint():
cfg = OpenAIClientConfig(
api_key="my-api-key",
Expand Down
Loading