telemetry-dev-openrouter 0.1.8__tar.gz → 0.2.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telemetry-dev-openrouter
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: OpenRouter integration for telemetry.dev Python SDK
5
5
  Keywords: telemetry,opentelemetry,openrouter,llm,genai,tracing
6
6
  Author: telemetry.dev
@@ -44,6 +44,10 @@ import telemetry_dev
44
44
  telemetry_dev.init(service_name="my-service")
45
45
  ```
46
46
 
47
+ Versions of `telemetry-dev` before 0.3.0 sent data to `https://ingest.telemetry.dev` by default.
48
+ That hostname reaches the same service and stays supported: if a firewall allows only it, set
49
+ `TELEMETRY_DEV_BASE_URL` to it.
50
+
47
51
  ## Per-client wrapping
48
52
 
49
53
  ```py
@@ -98,6 +102,11 @@ When OpenRouter returns cost information, the integration records `gen_ai.usage.
98
102
  `usage.cost_details.upstream_inference_cost`. The cost attribute is omitted when neither value is
99
103
  available.
100
104
 
105
+ When `usage.is_byok` is `True`, the request uses your own provider key. Your provider bills the
106
+ inference, and `usage.cost` is only the OpenRouter fee. The integration then records the sum of
107
+ `usage.cost` and `usage.cost_details.upstream_inference_cost`. If the response has no
108
+ `upstream_inference_cost`, the integration records no cost.
109
+
101
110
  ## Streaming
102
111
 
103
112
  Chat and Responses API streams are traced for sync and async callers. The integration accumulates
@@ -21,6 +21,10 @@ import telemetry_dev
21
21
  telemetry_dev.init(service_name="my-service")
22
22
  ```
23
23
 
24
+ Versions of `telemetry-dev` before 0.3.0 sent data to `https://ingest.telemetry.dev` by default.
25
+ That hostname reaches the same service and stays supported: if a firewall allows only it, set
26
+ `TELEMETRY_DEV_BASE_URL` to it.
27
+
24
28
  ## Per-client wrapping
25
29
 
26
30
  ```py
@@ -75,6 +79,11 @@ When OpenRouter returns cost information, the integration records `gen_ai.usage.
75
79
  `usage.cost_details.upstream_inference_cost`. The cost attribute is omitted when neither value is
76
80
  available.
77
81
 
82
+ When `usage.is_byok` is `True`, the request uses your own provider key. Your provider bills the
83
+ inference, and `usage.cost` is only the OpenRouter fee. The integration then records the sum of
84
+ `usage.cost` and `usage.cost_details.upstream_inference_cost`. If the response has no
85
+ `upstream_inference_cost`, the integration records no cost.
86
+
78
87
  ## Streaming
79
88
 
80
89
  Chat and Responses API streams are traced for sync and async callers. The integration accumulates
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-openrouter"
3
- version = "0.1.8"
3
+ version = "0.2.0"
4
4
  description = "OpenRouter integration for telemetry.dev Python SDK"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-openrouter"
3
- version = "0.1.8"
3
+ version = "0.2.0"
4
4
  description = "OpenRouter integration for telemetry.dev Python SDK"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -12,7 +12,7 @@ from openrouter.chat import Chat
12
12
  from openrouter.embeddings import Embeddings
13
13
  from openrouter.responses import Responses
14
14
 
15
- __version__ = "0.1.8"
15
+ __version__ = "0.2.0"
16
16
 
17
17
  RequestMapper = Callable[[Mapping[str, Any]], tuple[str, dict[str, Any]]]
18
18
  ResponseMapper = Callable[[Any], dict[str, Any]]
@@ -163,10 +163,15 @@ def _clean_fields(fields: Mapping[str, Any]) -> dict[str, Any]:
163
163
 
164
164
 
165
165
  def _cost_usd(raw_usage: Any) -> float | None:
166
+ # `cost` is the OpenRouter charge. For a request with the user's own provider key
167
+ # (BYOK), the provider bills the inference, and the charge is only the OpenRouter
168
+ # fee. The cost of such a request is the fee and the provider's inference cost.
169
+ # Without the inference cost, the span has no cost.
166
170
  cost = _number(_field(raw_usage, "cost"))
167
- if cost is not None:
168
- return cost
169
- return _number(_field(_field(raw_usage, "cost_details"), "upstream_inference_cost"))
171
+ upstream_cost = _number(_field(_field(raw_usage, "cost_details"), "upstream_inference_cost"))
172
+ if _field(raw_usage, "is_byok") is True:
173
+ return None if upstream_cost is None else upstream_cost + (cost or 0)
174
+ return cost if cost is not None else upstream_cost
170
175
 
171
176
 
172
177
  def _chat_request(params: Mapping[str, Any]) -> tuple[str, dict[str, Any]]: