aid-runtime-python 0.1.95__tar.gz → 0.1.96__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 (105) hide show
  1. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/PKG-INFO +1 -1
  2. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/pyproject.toml +1 -1
  3. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/__init__.py +5 -1
  4. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/decisions.py +38 -2
  5. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/tracing.py +26 -6
  6. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
  7. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_decisions.py +82 -1
  8. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/README.md +0 -0
  9. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/setup.cfg +0 -0
  10. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/__init__.py +0 -0
  11. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/chat_model.py +0 -0
  12. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/deep_agents.py +0 -0
  13. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/engine.py +0 -0
  14. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/guardrails.py +0 -0
  15. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/ir.py +0 -0
  16. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/loop.py +0 -0
  17. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/memory.py +0 -0
  18. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/policy.py +0 -0
  19. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/agents/state.py +0 -0
  20. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/cache.py +0 -0
  21. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/concurrency.py +0 -0
  22. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/control.py +0 -0
  23. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/cost.py +0 -0
  24. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/errors.py +0 -0
  25. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/evals/__init__.py +0 -0
  26. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/evals/dataset.py +0 -0
  27. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/evals/gate.py +0 -0
  28. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/evals/metrics.py +0 -0
  29. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/evals/predicate.py +0 -0
  30. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/evals/runner.py +0 -0
  31. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/gateway.py +0 -0
  32. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/local_trace.py +0 -0
  33. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/pipeline.py +0 -0
  34. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/prompts.py +0 -0
  35. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/providers/__init__.py +0 -0
  36. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/providers/anthropic.py +0 -0
  37. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/providers/base.py +0 -0
  38. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/providers/bedrock.py +0 -0
  39. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/providers/fake.py +0 -0
  40. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/providers/http.py +0 -0
  41. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/providers/vertex.py +0 -0
  42. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/py.typed +0 -0
  43. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/__init__.py +0 -0
  44. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/chunking.py +0 -0
  45. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/citations.py +0 -0
  46. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/connectors.py +0 -0
  47. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/embedding.py +0 -0
  48. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/gate.py +0 -0
  49. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/hybrid.py +0 -0
  50. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/metrics.py +0 -0
  51. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/pgvector.py +0 -0
  52. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/rerank.py +0 -0
  53. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/retriever.py +0 -0
  54. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/stores.py +0 -0
  55. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/retrieval/types.py +0 -0
  56. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/steps.py +0 -0
  57. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/structured.py +0 -0
  58. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/tools.py +0 -0
  59. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime/types.py +0 -0
  60. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime_python.egg-info/SOURCES.txt +0 -0
  61. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
  62. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime_python.egg-info/requires.txt +0 -0
  63. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
  64. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_agents_budget.py +0 -0
  65. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_agents_deep_agents.py +0 -0
  66. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_agents_hitl.py +0 -0
  67. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_agents_loop.py +0 -0
  68. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_agents_memory.py +0 -0
  69. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_anthropic_provider.py +0 -0
  70. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_bedrock_provider.py +0 -0
  71. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_cache.py +0 -0
  72. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_concurrency.py +0 -0
  73. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_control.py +0 -0
  74. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_cost.py +0 -0
  75. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_dataset.py +0 -0
  76. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_evals.py +0 -0
  77. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_evals_assert_gate.py +0 -0
  78. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_evals_decision.py +0 -0
  79. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_evals_gate.py +0 -0
  80. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_evals_predicate.py +0 -0
  81. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_gateway.py +0 -0
  82. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_guardrails.py +0 -0
  83. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_http_provider.py +0 -0
  84. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_local_trace.py +0 -0
  85. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_package.py +0 -0
  86. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_pipeline.py +0 -0
  87. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_prompts.py +0 -0
  88. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_chunking.py +0 -0
  89. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_citations.py +0 -0
  90. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_connectors.py +0 -0
  91. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_embedding.py +0 -0
  92. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_gate.py +0 -0
  93. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_hybrid.py +0 -0
  94. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_metrics.py +0 -0
  95. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_rerank.py +0 -0
  96. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_stores.py +0 -0
  97. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_retrieval_types.py +0 -0
  98. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_steps.py +0 -0
  99. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_streaming.py +0 -0
  100. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_structured.py +0 -0
  101. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_tool_permissions.py +0 -0
  102. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_tools.py +0 -0
  103. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_tracing.py +0 -0
  104. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_types.py +0 -0
  105. {aid_runtime_python-0.1.95 → aid_runtime_python-0.1.96}/tests/test_vertex_provider.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.95
3
+ Version: 0.1.96
4
4
  Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
5
5
  Author: The AID Framework authors
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aid-runtime-python"
7
- version = "0.1.95"
7
+ version = "0.1.96"
8
8
  description = "The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -72,6 +72,7 @@ from aid_runtime.cost import (
72
72
  )
73
73
  from aid_runtime.decisions import (
74
74
  DEFAULT_TYPESAFE_BASE_URL,
75
+ JEV_INPUT_USD_PER_MTOK,
75
76
  JEV_MOVING_ALIASES,
76
77
  TYPESAFE_API_KEY_ENVS,
77
78
  TYPESAFE_BASE_URL_ENV,
@@ -79,6 +80,7 @@ from aid_runtime.decisions import (
79
80
  DecisionClient,
80
81
  DecisionQuestion,
81
82
  DecisionResponse,
83
+ decision_cost_usd,
82
84
  decision_key,
83
85
  is_reproducible_model,
84
86
  )
@@ -295,7 +297,7 @@ from aid_runtime.types import (
295
297
  )
296
298
 
297
299
  #: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
298
- __version__ = "0.1.95"
300
+ __version__ = "0.1.96"
299
301
 
300
302
  __all__ = [
301
303
  "ANTHROPIC_VERSION",
@@ -311,6 +313,7 @@ __all__ = [
311
313
  "GEN_AI_OPERATION_CHAT",
312
314
  "INDEX_KEY",
313
315
  "ITEM_KEY",
316
+ "JEV_INPUT_USD_PER_MTOK",
314
317
  "JEV_MOVING_ALIASES",
315
318
  "LIMITER_KEY",
316
319
  "MAX_STEP_DEPTH",
@@ -499,6 +502,7 @@ __all__ = [
499
502
  "chunker_for",
500
503
  "cite",
501
504
  "create_store",
505
+ "decision_cost_usd",
502
506
  "decision_key",
503
507
  "default_bedrock_base_url",
504
508
  "default_metrics",
@@ -38,9 +38,12 @@ from typing import Any, Literal
38
38
  import httpx
39
39
 
40
40
  from aid_runtime.errors import ConfigurationError, ProviderError, ProviderResponseError
41
+ from aid_runtime.tracing import llm_span, record_attributes, record_cost, record_usage
42
+ from aid_runtime.types import TokenUsage
41
43
 
42
44
  __all__ = [
43
45
  "DEFAULT_TYPESAFE_BASE_URL",
46
+ "JEV_INPUT_USD_PER_MTOK",
44
47
  "JEV_MOVING_ALIASES",
45
48
  "TYPESAFE_API_KEY_ENVS",
46
49
  "TYPESAFE_BASE_URL_ENV",
@@ -48,6 +51,7 @@ __all__ = [
48
51
  "DecisionClient",
49
52
  "DecisionQuestion",
50
53
  "DecisionResponse",
54
+ "decision_cost_usd",
51
55
  "decision_key",
52
56
  "is_reproducible_model",
53
57
  ]
@@ -64,6 +68,11 @@ TYPESAFE_BASE_URL_ENV = "TYPESAFE_BASE_URL"
64
68
  #: ``reproducible=True``.
65
69
  JEV_MOVING_ALIASES = frozenset({"jev-latest", "jev-preview"})
66
70
 
71
+ #: Jev bills input tokens at $42 per billion ($0.042 per million) and states that
72
+ #: output tokens are free. A call therefore needs an input row only, and a
73
+ #: decision run must never be reported as unpriceable.
74
+ JEV_INPUT_USD_PER_MTOK = 0.042
75
+
67
76
  QuestionType = Literal["choice", "score", "noul"]
68
77
 
69
78
  _QUESTION_TYPES: frozenset[str] = frozenset({"choice", "score", "noul"})
@@ -93,6 +102,19 @@ def is_reproducible_model(model: str) -> bool:
93
102
  return model not in JEV_MOVING_ALIASES
94
103
 
95
104
 
105
+ def decision_cost_usd(input_tokens: int | None) -> float:
106
+ """Price one decision call from its input tokens alone.
107
+
108
+ Output tokens are free by contract, so they are deliberately not part of the
109
+ arithmetic: a caller that passed a total would overcharge the run. ``None``
110
+ means the vendor reported no usage; :meth:`DecisionClient.decide` then records
111
+ no cost at all, so the call stays unknown rather than free.
112
+ """
113
+ if input_tokens is None:
114
+ return 0.0
115
+ return (input_tokens / 1_000_000) * JEV_INPUT_USD_PER_MTOK
116
+
117
+
96
118
  @dataclass(frozen=True, slots=True)
97
119
  class DecisionQuestion:
98
120
  """One typed question.
@@ -228,8 +250,22 @@ class DecisionClient:
228
250
  "state": state,
229
251
  "questions": {key: question.as_payload() for key, question in questions.items()},
230
252
  }
231
- body = await self._post(payload)
232
- return self._parse(body, questions)
253
+ # A decision is billed like any other model call, so it gets the same
254
+ # span: `aid cost` and the eval budget read `aid.cost.usd` off it.
255
+ with llm_span(model=model, provider=self._name, operation="decision") as span:
256
+ body = await self._post(payload)
257
+ response = self._parse(body, questions)
258
+ if response.input_tokens is not None:
259
+ usage = TokenUsage(
260
+ input_tokens=response.input_tokens,
261
+ output_tokens=response.output_tokens or 0,
262
+ )
263
+ record_usage(span, usage)
264
+ record_cost(span, decision_cost_usd(usage.input_tokens))
265
+ # The vendor echoes the version that actually answered, which is the
266
+ # only record of what a moving alias resolved to.
267
+ record_attributes(span, response_model=response.model)
268
+ return response
233
269
 
234
270
  async def close(self) -> None:
235
271
  if self._closed:
@@ -14,8 +14,8 @@ that must not decide a host application's telemetry setup for it.
14
14
  from __future__ import annotations
15
15
 
16
16
  import contextlib
17
- from collections.abc import Iterator
18
- from typing import TYPE_CHECKING, Any
17
+ from collections.abc import Iterator, Sequence
18
+ from typing import Any, Protocol
19
19
 
20
20
  from opentelemetry import trace
21
21
  from opentelemetry.trace import Span, SpanKind, Status, StatusCode
@@ -23,12 +23,10 @@ from opentelemetry.trace import Span, SpanKind, Status, StatusCode
23
23
  from aid_runtime.local_trace import finish_span, wrap_span
24
24
  from aid_runtime.types import TokenUsage
25
25
 
26
- if TYPE_CHECKING:
27
- from aid_runtime.agents.guardrails import GuardrailRecord
28
-
29
26
  __all__ = [
30
27
  "ATTRIBUTES",
31
28
  "GEN_AI_OPERATION_CHAT",
29
+ "GuardrailEvent",
32
30
  "agent_span",
33
31
  "aid_attributes",
34
32
  "get_tracer",
@@ -226,7 +224,29 @@ def record_hitl(
226
224
  span.add_event("aid.hitl", attributes)
227
225
 
228
226
 
229
- def record_guardrail(span: Span, record: GuardrailRecord) -> None:
227
+ class GuardrailEvent(Protocol):
228
+ """The fields :func:`record_guardrail` reads from a fired guardrail.
229
+
230
+ Structural on purpose. Importing ``GuardrailRecord`` would close a module cycle --
231
+ ``guardrails`` imports the decision client, which imports this module, which would
232
+ import ``guardrails`` again -- and a protocol keeps the annotation honest without
233
+ the import.
234
+ """
235
+
236
+ @property
237
+ def guardrail(self) -> str: ...
238
+
239
+ @property
240
+ def stage(self) -> str: ...
241
+
242
+ @property
243
+ def action(self) -> str: ...
244
+
245
+ @property
246
+ def policies(self) -> Sequence[str]: ...
247
+
248
+
249
+ def record_guardrail(span: Span, record: GuardrailEvent) -> None:
230
250
  """Record one guardrail hit as an ``aid.guardrail`` span event."""
231
251
  span.add_event(
232
252
  "aid.guardrail",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.95
3
+ Version: 0.1.96
4
4
  Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
5
5
  Author: The AID Framework authors
6
6
  License-Expression: Apache-2.0
@@ -8,16 +8,25 @@ gone over the wire.
8
8
  from __future__ import annotations
9
9
 
10
10
  import json
11
+ from pathlib import Path
11
12
  from typing import Any
12
13
 
13
14
  import httpx
14
15
  import pytest
15
16
 
16
- from aid_runtime import ConfigurationError, ProviderError, ProviderResponseError
17
+ from aid_runtime import (
18
+ ATTRIBUTES,
19
+ TRACE_DIR_ENV,
20
+ ConfigurationError,
21
+ ProviderError,
22
+ ProviderResponseError,
23
+ )
17
24
  from aid_runtime.decisions import (
18
25
  DEFAULT_TYPESAFE_BASE_URL,
26
+ JEV_INPUT_USD_PER_MTOK,
19
27
  DecisionClient,
20
28
  DecisionQuestion,
29
+ decision_cost_usd,
21
30
  decision_key,
22
31
  is_reproducible_model,
23
32
  )
@@ -281,3 +290,75 @@ def test_aliases_are_not_reproducible() -> None:
281
290
  assert is_reproducible_model("jev-1.14.0")
282
291
  assert not is_reproducible_model("jev-latest")
283
292
  assert not is_reproducible_model("jev-preview")
293
+
294
+
295
+ def test_jev_prices_input_tokens_only() -> None:
296
+ assert JEV_INPUT_USD_PER_MTOK == 0.042
297
+ # $42 per billion: a ~430-token classification is about $0.000018.
298
+ assert decision_cost_usd(430) == pytest.approx(0.00001806)
299
+ assert decision_cost_usd(1_000_000) == pytest.approx(JEV_INPUT_USD_PER_MTOK)
300
+ assert decision_cost_usd(0) == 0.0
301
+ # No reported usage is unknown; the caller records no cost at all rather than
302
+ # claiming the call was free.
303
+ assert decision_cost_usd(None) == 0.0
304
+
305
+
306
+ def _trace_lines(directory: Path) -> list[dict[str, Any]]:
307
+ (path,) = directory.glob("trace-*.jsonl")
308
+ return [json.loads(line) for line in path.read_text(encoding="utf-8").splitlines()]
309
+
310
+
311
+ @pytest.mark.asyncio
312
+ async def test_a_decision_is_priced_on_its_span(
313
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
314
+ ) -> None:
315
+ monkeypatch.setenv(TRACE_DIR_ENV, str(tmp_path))
316
+ client = _client(
317
+ Recorder(_reply({"triage": {"choice": "billing", "confidence": 0.91}})),
318
+ )
319
+
320
+ await client.decide(
321
+ model=MODEL,
322
+ state={"message": "I was charged twice"},
323
+ questions={
324
+ "triage": DecisionQuestion(
325
+ type="choice",
326
+ instructions="Which team should handle this",
327
+ criteria=("billing", "technical"),
328
+ )
329
+ },
330
+ )
331
+
332
+ (record,) = _trace_lines(tmp_path)
333
+ attributes = record["attributes"]
334
+ assert record["name"] == f"decision {MODEL}"
335
+ assert attributes[ATTRIBUTES["system"]] == "typesafe"
336
+ assert attributes[ATTRIBUTES["operation"]] == "decision"
337
+ assert attributes[ATTRIBUTES["input_tokens"]] == 430
338
+ assert attributes[ATTRIBUTES["output_tokens"]] == 0
339
+ assert attributes[ATTRIBUTES["cost_usd"]] == pytest.approx(0.00001806)
340
+ assert attributes[ATTRIBUTES["response_model"]] == MODEL
341
+
342
+
343
+ @pytest.mark.asyncio
344
+ async def test_a_reply_without_usage_records_no_cost(
345
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
346
+ ) -> None:
347
+ monkeypatch.setenv(TRACE_DIR_ENV, str(tmp_path))
348
+ body = {
349
+ "model": MODEL,
350
+ "answers": {"urgent": {"noul": 0.2}},
351
+ }
352
+ client = _client(Recorder(httpx.Response(200, json=body)))
353
+
354
+ await client.decide(
355
+ model=MODEL,
356
+ state="x",
357
+ questions={"urgent": DecisionQuestion(type="noul", instructions="Is it urgent")},
358
+ )
359
+
360
+ (record,) = _trace_lines(tmp_path)
361
+ assert ATTRIBUTES["cost_usd"] not in record["attributes"]
362
+ assert ATTRIBUTES["input_tokens"] not in record["attributes"]
363
+ # The serving model is recorded even when the vendor omits usage.
364
+ assert record["attributes"][ATTRIBUTES["response_model"]] == MODEL