metergraph-core 0.8.27__tar.gz → 0.8.28__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.
Files changed (30) hide show
  1. {metergraph_core-0.8.27/src/metergraph_core.egg-info → metergraph_core-0.8.28}/PKG-INFO +10 -1
  2. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/README.md +9 -0
  3. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/pyproject.toml +1 -1
  4. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/calls.py +12 -1
  5. metergraph_core-0.8.28/src/metergraph_core/providers/anthropic.py +29 -0
  6. {metergraph_core-0.8.27 → metergraph_core-0.8.28/src/metergraph_core.egg-info}/PKG-INFO +10 -1
  7. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core.egg-info/SOURCES.txt +1 -0
  8. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/MANIFEST.in +0 -0
  9. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/setup.cfg +0 -0
  10. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/__init__.py +0 -0
  11. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/billing.py +0 -0
  12. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/catalog.py +0 -0
  13. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/catalog_delta.py +0 -0
  14. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/data/models.yaml +0 -0
  15. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/data/prices.yaml +0 -0
  16. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/data/sources.yaml +0 -0
  17. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/extractors.py +0 -0
  18. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/families.py +0 -0
  19. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/loader.py +0 -0
  20. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/models.py +0 -0
  21. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/providers/__init__.py +0 -0
  22. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/providers/google.py +0 -0
  23. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/refresh.py +0 -0
  24. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/reliability.py +0 -0
  25. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/responses.py +0 -0
  26. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/retrieval.py +0 -0
  27. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core/sources.py +0 -0
  28. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core.egg-info/dependency_links.txt +0 -0
  29. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/src/metergraph_core.egg-info/requires.txt +0 -0
  30. {metergraph_core-0.8.27 → metergraph_core-0.8.28}/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.27
3
+ Version: 0.8.28
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
@@ -336,6 +336,15 @@ rate, count, search type, or processing tier stays partial or unpriced.
336
336
  `search_units` and `retrieval_cost_usd` expose the resolved components for storage.
337
337
  `known_subtotal_usd` remains separate from a complete total.
338
338
 
339
+ For failed calls, missing usage is not evidence of a free request. Anthropic
340
+ Messages HTTP rejections with no observed usage are priced at zero with reason
341
+ `provider_failure_not_billable`. This rule excludes batch operations and unknown
342
+ endpoints: a failed result download can follow already-billed inference. Failed
343
+ streams or `usage_complete: false` remain partial; any observed-usage estimate is
344
+ separate from the final charge. Qualified gateway billing evidence retains its
345
+ existing precedence.
346
+
347
+
339
348
  A receiver that already resolved tokens against the same catalog may pass
340
349
  `token_cost=`. Explicit API identity can select a different token channel; other
341
350
  resolved token results are preserved. Qualified gateway totals can still be
@@ -306,6 +306,15 @@ rate, count, search type, or processing tier stays partial or unpriced.
306
306
  `search_units` and `retrieval_cost_usd` expose the resolved components for storage.
307
307
  `known_subtotal_usd` remains separate from a complete total.
308
308
 
309
+ For failed calls, missing usage is not evidence of a free request. Anthropic
310
+ Messages HTTP rejections with no observed usage are priced at zero with reason
311
+ `provider_failure_not_billable`. This rule excludes batch operations and unknown
312
+ endpoints: a failed result download can follow already-billed inference. Failed
313
+ streams or `usage_complete: false` remain partial; any observed-usage estimate is
314
+ separate from the final charge. Qualified gateway billing evidence retains its
315
+ existing precedence.
316
+
317
+
309
318
  A receiver that already resolved tokens against the same catalog may pass
310
319
  `token_cost=`. Explicit API identity can select a different token channel; other
311
320
  resolved token results are preserved. Qualified gateway totals can still be
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "metergraph-core"
3
- version = "0.8.27"
3
+ version = "0.8.28"
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,9 +6,10 @@ 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, _supports_flex
9
+ from .catalog import CostComponents, CostResult, ModelUsage, direct_channel_for_provider, normalize_provider, _supports_flex
10
10
  from .loader import LoadedCatalog
11
11
  from .providers import model_identity
12
+ from .providers.anthropic import rejected_without_usage
12
13
  from .responses import _as_mapping, _bundled_catalog, _first, cost_from_response, response_format, _native_input_tokens
13
14
 
14
15
  _ZERO = Decimal('0')
@@ -293,6 +294,16 @@ def price_call_from_record(
293
294
  if row.get('input_tokens_include_cache') is True:
294
295
  values['input_tokens'] = _native_input_tokens(values, cost)
295
296
  token_cost = cost(**values)
297
+ if normalize_provider(provider or '') == 'anthropic' and rejected_without_usage(row):
298
+ free = replace(token_cost, cost_usd=_ZERO, status='priced',
299
+ reasons=('provider_failure_not_billable',), missing_dimensions=(),
300
+ components=CostComponents(_ZERO, _ZERO, _ZERO, _ZERO))
301
+ return CallCostResult(free, (), _ZERO, _ZERO, None, 'priced', 'exact', (), loaded.content_hash)
302
+ failed_stream = row.get('stream') is True and (
303
+ row.get('error') is True or row.get('status') in {'error', 'failed', 'abandoned'})
304
+ if row.get('usage_complete') is False or failed_stream:
305
+ token_cost = replace(token_cost, status='partial',
306
+ missing_dimensions=tuple(dict.fromkeys((*token_cost.missing_dimensions, 'incomplete_usage'))))
296
307
  flex_priced = tier == 'flex' and _supports_flex(token_cost.price)
297
308
  if tier is not None and tier not in ('standard', 'default', 'auto', 'batch') and not flex_priced:
298
309
  token_cost = replace(token_cost, status='partial',
@@ -0,0 +1,29 @@
1
+ """Anthropic failure billing evidence, independent of model token rates."""
2
+ from collections.abc import Mapping
3
+ from typing import Any
4
+
5
+
6
+ # Provider HTTP rejections are free; client disconnects/timeouts can still be
7
+ # charged. Never infer a free call from an exception name or absent counters.
8
+ # https://support.claude.com/en/articles/8977456-how-do-i-pay-for-my-claude-api-usage
9
+
10
+ def rejected_without_usage(row: Mapping[str, Any]) -> bool:
11
+ # A rejected result download says nothing about the already-submitted job.
12
+ if row.get('batch') is True or row.get('endpoint') not in {'messages', 'messages.create', 'messages.stream'}:
13
+ return False
14
+ status = row.get('http_status_code')
15
+ if not (row.get('error') is True or row.get('status') in {'error', 'failed'}):
16
+ return False
17
+ if type(status) is not int or not 400 <= status <= 599:
18
+ return False
19
+ counters = [row.get(key) for key in (
20
+ 'input_tokens', 'output_tokens', 'cache_read_tokens', 'cache_write_tokens',
21
+ 'cache_write_5m_tokens', 'cache_write_1h_tokens', 'reasoning_tokens',
22
+ 'web_search_calls', 'grounding_queries', 'search_queries', 'search_units',
23
+ )]
24
+ native = row.get('server_tool_use')
25
+ if native is not None:
26
+ if not isinstance(native, Mapping):
27
+ return False
28
+ counters.extend(native.values())
29
+ return all(value is None or (type(value) is int and value == 0) for value in counters)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: metergraph-core
3
- Version: 0.8.27
3
+ Version: 0.8.28
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
@@ -336,6 +336,15 @@ rate, count, search type, or processing tier stays partial or unpriced.
336
336
  `search_units` and `retrieval_cost_usd` expose the resolved components for storage.
337
337
  `known_subtotal_usd` remains separate from a complete total.
338
338
 
339
+ For failed calls, missing usage is not evidence of a free request. Anthropic
340
+ Messages HTTP rejections with no observed usage are priced at zero with reason
341
+ `provider_failure_not_billable`. This rule excludes batch operations and unknown
342
+ endpoints: a failed result download can follow already-billed inference. Failed
343
+ streams or `usage_complete: false` remain partial; any observed-usage estimate is
344
+ separate from the final charge. Qualified gateway billing evidence retains its
345
+ existing precedence.
346
+
347
+
339
348
  A receiver that already resolved tokens against the same catalog may pass
340
349
  `token_cost=`. Explicit API identity can select a different token channel; other
341
350
  resolved token results are preserved. Qualified gateway totals can still be
@@ -24,4 +24,5 @@ src/metergraph_core/data/models.yaml
24
24
  src/metergraph_core/data/prices.yaml
25
25
  src/metergraph_core/data/sources.yaml
26
26
  src/metergraph_core/providers/__init__.py
27
+ src/metergraph_core/providers/anthropic.py
27
28
  src/metergraph_core/providers/google.py