metergraph-core 0.8.25__tar.gz → 0.8.26__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {metergraph_core-0.8.25/src/metergraph_core.egg-info → metergraph_core-0.8.26}/PKG-INFO +1 -1
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/pyproject.toml +1 -1
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/calls.py +11 -6
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/catalog.py +37 -3
- metergraph_core-0.8.26/src/metergraph_core/providers/__init__.py +13 -0
- metergraph_core-0.8.26/src/metergraph_core/providers/google.py +14 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/responses.py +8 -5
- {metergraph_core-0.8.25 → metergraph_core-0.8.26/src/metergraph_core.egg-info}/PKG-INFO +1 -1
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core.egg-info/SOURCES.txt +3 -1
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/MANIFEST.in +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/README.md +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/setup.cfg +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/__init__.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/billing.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/catalog_delta.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/data/models.yaml +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/data/prices.yaml +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/data/sources.yaml +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/extractors.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/families.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/loader.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/models.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/refresh.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/reliability.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/retrieval.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core/sources.py +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core.egg-info/dependency_links.txt +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core.egg-info/requires.txt +0 -0
- {metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: metergraph-core
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.26
|
|
4
4
|
Summary: Open, effective-dated LLM pricing catalog and deterministic cost calculator for popular models across major providers and gateways, including OpenAI, Anthropic, Google Gemini, AWS Bedrock, OpenRouter, Vercel AI Gateway, and more.
|
|
5
5
|
Author: Metergraph
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "metergraph-core"
|
|
3
|
-
version = "0.8.
|
|
3
|
+
version = "0.8.26"
|
|
4
4
|
description = "Open, effective-dated LLM pricing catalog and deterministic cost calculator for popular models across major providers and gateways, including OpenAI, Anthropic, Google Gemini, AWS Bedrock, OpenRouter, Vercel AI Gateway, and more."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -6,8 +6,9 @@ from decimal import Decimal
|
|
|
6
6
|
import re
|
|
7
7
|
from typing import Any, Mapping, Sequence
|
|
8
8
|
|
|
9
|
-
from .catalog import CostResult, ModelUsage, direct_channel_for_provider, normalize_provider
|
|
9
|
+
from .catalog import CostResult, ModelUsage, direct_channel_for_provider, normalize_provider, _supports_flex
|
|
10
10
|
from .loader import LoadedCatalog
|
|
11
|
+
from .providers import model_identity
|
|
11
12
|
from .responses import _as_mapping, _bundled_catalog, _first, cost_from_response, response_format, _native_input_tokens
|
|
12
13
|
|
|
13
14
|
_ZERO = Decimal('0')
|
|
@@ -275,21 +276,25 @@ def price_call_from_record(
|
|
|
275
276
|
"""
|
|
276
277
|
loaded = catalog if catalog is not None else _bundled_catalog()
|
|
277
278
|
provider = row.get('provider')
|
|
279
|
+
model, channel = model_identity(provider, row.get('model'))
|
|
280
|
+
identity_changed = (model, channel) != (row.get('model'), direct_channel_for_provider(provider))
|
|
278
281
|
when = at if at is not None else token_cost.effective_at if token_cost is not None and token_cost.effective_at is not None else row.get('ts')
|
|
279
282
|
agent = normalize_provider(provider or '') in {'perplexity-ai', 'perplexity-agent'} and (
|
|
280
283
|
row.get('retrieval_api') == 'agent' or provider == 'perplexity-agent')
|
|
281
|
-
|
|
282
|
-
|
|
284
|
+
if agent:
|
|
285
|
+
channel = 'perplexity-agent-api'
|
|
286
|
+
tier = row.get('service_tier')
|
|
287
|
+
if token_cost is None or token_cost.effective_at is None or agent or identity_changed or tier == 'flex':
|
|
283
288
|
values = {key: row.get(key) for key in ('input_tokens', 'output_tokens', 'cache_read_tokens',
|
|
284
289
|
'cache_write_tokens', 'cache_write_5m_tokens', 'cache_write_1h_tokens')}
|
|
285
290
|
def cost(**usage):
|
|
286
|
-
return loaded.calculate_cost(model=
|
|
291
|
+
return loaded.calculate_cost(model=model, usage=ModelUsage(**usage, batch=row.get('batch') is True, service_tier=tier),
|
|
287
292
|
at=when, provider=provider, channel=channel, region=region)
|
|
288
293
|
if row.get('input_tokens_include_cache') is True:
|
|
289
294
|
values['input_tokens'] = _native_input_tokens(values, cost)
|
|
290
295
|
token_cost = cost(**values)
|
|
291
|
-
|
|
292
|
-
if tier is not None and tier not in ('standard', 'default', 'auto', 'batch'):
|
|
296
|
+
flex_priced = tier == 'flex' and _supports_flex(token_cost.price)
|
|
297
|
+
if tier is not None and tier not in ('standard', 'default', 'auto', 'batch') and not flex_priced:
|
|
293
298
|
token_cost = replace(token_cost, status='partial',
|
|
294
299
|
missing_dimensions=tuple(dict.fromkeys((*token_cost.missing_dimensions, 'service_tier'))))
|
|
295
300
|
model = token_cost.canonical_model or row.get('model')
|
|
@@ -359,6 +359,8 @@ class ModelUsage:
|
|
|
359
359
|
cache_write_5m_tokens: int | None = None
|
|
360
360
|
cache_write_1h_tokens: int | None = None
|
|
361
361
|
batch: bool = False
|
|
362
|
+
# Actual provider-reported tier, never the requested preference.
|
|
363
|
+
service_tier: str | None = None
|
|
362
364
|
|
|
363
365
|
|
|
364
366
|
@dataclass(frozen=True, slots=True)
|
|
@@ -534,6 +536,13 @@ def _cached_count(value: Any, name: str, reasons: list[str]) -> int | None:
|
|
|
534
536
|
return count
|
|
535
537
|
|
|
536
538
|
|
|
539
|
+
def _supports_flex(price: Price | None) -> bool:
|
|
540
|
+
return price is not None and (
|
|
541
|
+
(price.publisher == "openai" and price.pricing_channel == "openai-api") or
|
|
542
|
+
(price.publisher == "google" and price.pricing_channel in {"google-api", "google-vertex-ai"})
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
|
|
537
546
|
def _price_tokens(
|
|
538
547
|
price: Price,
|
|
539
548
|
rules: Mapping[str, Any],
|
|
@@ -546,6 +555,7 @@ def _price_tokens(
|
|
|
546
555
|
cache_write_5m_tokens: Any,
|
|
547
556
|
cache_write_1h_tokens: Any,
|
|
548
557
|
batch: bool,
|
|
558
|
+
service_tier: str | None = None,
|
|
549
559
|
) -> tuple[Decimal, list[str], CostComponents]:
|
|
550
560
|
"""Cost a token usage against one already-selected price and its merged
|
|
551
561
|
rules. Every token entry point reaches it through ``_cost_result`` so all
|
|
@@ -599,7 +609,30 @@ def _price_tokens(
|
|
|
599
609
|
cache_read_rate = price.cache_read_per_mtok
|
|
600
610
|
cache_write_5m_rate = price.cache_write_5m_per_mtok
|
|
601
611
|
cache_write_1h_rate = price.cache_write_1h_per_mtok
|
|
602
|
-
|
|
612
|
+
flex = service_tier == "flex"
|
|
613
|
+
google_flex = flex and price.publisher == "google" and price.pricing_channel in {
|
|
614
|
+
"google-api", "google-vertex-ai",
|
|
615
|
+
}
|
|
616
|
+
openai_flex = flex and price.publisher == "openai" and price.pricing_channel == "openai-api"
|
|
617
|
+
if service_tier not in (None, "standard", "default", "standard_only", "auto", "on_demand", "batch") and not (google_flex or openai_flex):
|
|
618
|
+
reasons.append("unsupported_service_tier")
|
|
619
|
+
if google_flex:
|
|
620
|
+
# Google publishes Flex at half the standard token rates, including cache reads.
|
|
621
|
+
# https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing
|
|
622
|
+
input_rate, output_rate, cache_read_rate = (
|
|
623
|
+
rate / 2 if rate is not None else None
|
|
624
|
+
for rate in (input_rate, output_rate, cache_read_rate)
|
|
625
|
+
)
|
|
626
|
+
if openai_flex:
|
|
627
|
+
# OpenAI Flex uses Batch token pricing. Preserve the served tier separately.
|
|
628
|
+
# https://developers.openai.com/api/docs/guides/flex-processing
|
|
629
|
+
if price.batch_cache_read_per_mtok is None and cache_read_rate is not None:
|
|
630
|
+
cache_read_rate /= 2
|
|
631
|
+
if price.batch_cache_write_5m_per_mtok is None and cache_write_5m_rate is not None:
|
|
632
|
+
cache_write_5m_rate /= 2
|
|
633
|
+
if price.batch_cache_write_1h_per_mtok is None and cache_write_1h_rate is not None:
|
|
634
|
+
cache_write_1h_rate /= 2
|
|
635
|
+
if (batch and not google_flex) or openai_flex:
|
|
603
636
|
if price.batch_input_per_mtok is None or price.batch_output_per_mtok is None:
|
|
604
637
|
reasons.append("batch_rate_unavailable")
|
|
605
638
|
else:
|
|
@@ -633,8 +666,8 @@ def _price_tokens(
|
|
|
633
666
|
prompt_count += cache_read_count
|
|
634
667
|
if not rules.get("input_includes_cache_write"):
|
|
635
668
|
prompt_count += cache_write_count
|
|
636
|
-
#
|
|
637
|
-
applies = not batch or long_context.get("applies_to_batch", True)
|
|
669
|
+
# OpenAI Flex shares Batch rates, including its long-context exceptions.
|
|
670
|
+
applies = not (batch or openai_flex) or long_context.get("applies_to_batch", True)
|
|
638
671
|
if applies and threshold is not None and prompt_count > threshold:
|
|
639
672
|
input_multiplier = _decimal(long_context.get("input_multiplier")) or Decimal("1")
|
|
640
673
|
output_multiplier = _decimal(
|
|
@@ -736,6 +769,7 @@ def _cost_result(
|
|
|
736
769
|
cache_write_5m_tokens=usage.cache_write_5m_tokens,
|
|
737
770
|
cache_write_1h_tokens=usage.cache_write_1h_tokens,
|
|
738
771
|
batch=usage.batch,
|
|
772
|
+
service_tier=usage.service_tier,
|
|
739
773
|
)
|
|
740
774
|
reasons = [f"missing_{dimension}" for dimension in missing] + reasons
|
|
741
775
|
partial = bool(reasons)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Resolve provider-native model identities before catalog lookup."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from ..catalog import direct_channel_for_provider, normalize_provider
|
|
6
|
+
from . import google
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def model_identity(provider: Any, model: Any) -> tuple[Any, str | None]:
|
|
10
|
+
channel = direct_channel_for_provider(provider)
|
|
11
|
+
if normalize_provider(provider or '') in {'google', 'vertex-ai'}:
|
|
12
|
+
return google.model_identity(model, channel)
|
|
13
|
+
return model, channel
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Native Google model identity conventions."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
_VERTEX_MODEL = re.compile(
|
|
7
|
+
r'projects/[^/]+/locations/[^/]+/publishers/google/models/([^/]+)'
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def model_identity(model: Any, channel: str | None) -> tuple[Any, str | None]:
|
|
12
|
+
"""A Vertex resource name identifies both the model and its native channel."""
|
|
13
|
+
match = _VERTEX_MODEL.fullmatch(model) if isinstance(model, str) else None
|
|
14
|
+
return (match.group(1), 'google-vertex-ai') if match else (model, channel)
|
|
@@ -12,7 +12,7 @@ from datetime import datetime, timezone
|
|
|
12
12
|
from functools import lru_cache
|
|
13
13
|
from typing import Any, Callable, Mapping
|
|
14
14
|
|
|
15
|
-
from .catalog import CostResult, ModelUsage, _coerce_datetime
|
|
15
|
+
from .catalog import CostResult, ModelUsage, _coerce_datetime, _supports_flex
|
|
16
16
|
from .loader import LoadedCatalog, load_catalog
|
|
17
17
|
|
|
18
18
|
_STANDARD_TIERS = frozenset({"default", "standard", "standard_only", "auto", "on_demand"})
|
|
@@ -151,6 +151,8 @@ def _openai_chat_completions(response: Mapping[str, Any]) -> _Facts:
|
|
|
151
151
|
|
|
152
152
|
def _gemini(response: Mapping[str, Any]) -> _Facts:
|
|
153
153
|
usage = _object(_first(response, "usage_metadata", "usageMetadata"))
|
|
154
|
+
traffic = _text(_first(usage, "traffic_type", "trafficType"))
|
|
155
|
+
tier = {"ON_DEMAND_FLEX": "flex", "ON_DEMAND": "standard", "ON_DEMAND_PRIORITY": "priority"}.get(traffic, traffic)
|
|
154
156
|
return _Facts(
|
|
155
157
|
model=_text(_first(response, "model_version", "modelVersion")),
|
|
156
158
|
usage={
|
|
@@ -169,6 +171,7 @@ def _gemini(response: Mapping[str, Any]) -> _Facts:
|
|
|
169
171
|
),
|
|
170
172
|
},
|
|
171
173
|
input_includes_cache=True,
|
|
174
|
+
service_tier=tier,
|
|
172
175
|
at=_iso(_first(response, "create_time", "createTime")),
|
|
173
176
|
)
|
|
174
177
|
|
|
@@ -308,8 +311,8 @@ def cost_from_response(
|
|
|
308
311
|
Fees outside token usage, such as web search, are not included.
|
|
309
312
|
``service_tier`` overrides the tier the response reports, for responses
|
|
310
313
|
that do not state it, such as an OpenAI batch output line. A tier other
|
|
311
|
-
than standard or
|
|
312
|
-
|
|
314
|
+
than standard, batch, or supported OpenAI/Google Flex turns the result
|
|
315
|
+
``partial`` with ``service_tier`` missing.
|
|
313
316
|
"""
|
|
314
317
|
data = _as_mapping(response)
|
|
315
318
|
if format is not None and format not in _READERS:
|
|
@@ -337,7 +340,7 @@ def cost_from_response(
|
|
|
337
340
|
def cost(**usage: Any) -> CostResult:
|
|
338
341
|
return loaded.calculate_cost(
|
|
339
342
|
model=model_id,
|
|
340
|
-
usage=ModelUsage(**usage, batch=batch),
|
|
343
|
+
usage=ModelUsage(**usage, batch=batch, service_tier=tier),
|
|
341
344
|
at=when,
|
|
342
345
|
channel=channel,
|
|
343
346
|
provider=provider,
|
|
@@ -348,7 +351,7 @@ def cost_from_response(
|
|
|
348
351
|
if facts.input_includes_cache:
|
|
349
352
|
usage["input_tokens"] = _native_input_tokens(usage, cost)
|
|
350
353
|
result = cost(**usage)
|
|
351
|
-
if tier is None or tier in _STANDARD_TIERS or batch or result.status == "unpriced":
|
|
354
|
+
if tier is None or tier in _STANDARD_TIERS or batch or (tier == "flex" and _supports_flex(result.price)) or result.status == "unpriced":
|
|
352
355
|
return result
|
|
353
356
|
return replace(
|
|
354
357
|
result,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: metergraph-core
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.26
|
|
4
4
|
Summary: Open, effective-dated LLM pricing catalog and deterministic cost calculator for popular models across major providers and gateways, including OpenAI, Anthropic, Google Gemini, AWS Bedrock, OpenRouter, Vercel AI Gateway, and more.
|
|
5
5
|
Author: Metergraph
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -22,4 +22,6 @@ src/metergraph_core.egg-info/requires.txt
|
|
|
22
22
|
src/metergraph_core.egg-info/top_level.txt
|
|
23
23
|
src/metergraph_core/data/models.yaml
|
|
24
24
|
src/metergraph_core/data/prices.yaml
|
|
25
|
-
src/metergraph_core/data/sources.yaml
|
|
25
|
+
src/metergraph_core/data/sources.yaml
|
|
26
|
+
src/metergraph_core/providers/__init__.py
|
|
27
|
+
src/metergraph_core/providers/google.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{metergraph_core-0.8.25 → metergraph_core-0.8.26}/src/metergraph_core.egg-info/top_level.txt
RENAMED
|
File without changes
|