originate-run-sdk 0.1.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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,281 @@
1
+ Metadata-Version: 2.4
2
+ Name: originate-run-sdk
3
+ Version: 0.1.0
4
+ Summary: Backend SDK for Run, Originate's managed service: request metrics, calls to outside services, AI call telemetry, health, deploy and backup reports, policies and consent. No prompts, completions or request bodies ever leave the process.
5
+ Author: Originate, Inc.
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://www.originatetech.com
8
+ Keywords: originate,run,monitoring,metrics,asgi,fastapi
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Framework :: FastAPI
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ # originate-run-sdk
20
+
21
+ The Python backend SDK for Run, Originate's managed service. It reports what Originate needs to operate your application (request metrics, calls to outside services, AI call telemetry, health, deploys, backups, metered external calls, audit events) and reads the policies and consent decisions you configured in the Originate dashboard.
22
+
23
+ It never sends prompts, completions, request bodies, headers or user content. See "What is sent" below.
24
+
25
+ Python 3.9 or newer. No dependencies. A Node application uses `@originatedev/run-sdk`, which reports the same things.
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ pip install originate-run-sdk
31
+ ```
32
+
33
+ ## The server key
34
+
35
+ The SDK reports with the application's **server key**. It starts with `osk_` and it is a secret: it says that a report comes from your server.
36
+
37
+ 1. In Originate, open the application's settings, then Run, then Backend SDK, and choose Create the server key (an administrator of the organization can). The same key serves every server of the application, the deploy step in your pipeline and the Originate server agent.
38
+ 2. Put it in the server's environment as `ORIGINATE_RUN_SERVER_KEY`, the way you keep any other secret. Never commit it.
39
+
40
+ The SDK sends it as a bearer token over HTTPS, never in an address or a request body, and never writes it to a log. It refuses to send it over a connection that is not encrypted, except to the machine it runs on, and it never follows a redirect with it.
41
+
42
+ The key that starts with `opk_` is the public one in the website tag. The SDK does not accept it: anyone can read it in your pages.
43
+
44
+ ## Init
45
+
46
+ ```python
47
+ import os
48
+ import originate_run as run
49
+
50
+ run.init(
51
+ release=os.environ.get("GIT_SHA"), # or ORIGINATE_RUN_RELEASE
52
+ service="api", # optional, when you run several processes
53
+ )
54
+ ```
55
+
56
+ `init` reads the key from `ORIGINATE_RUN_SERVER_KEY`; pass `server_key=` to give it yourself. Other options: `api_base` (defaults to `https://api.platform.originatetech.com`, or `ORIGINATE_API_BASE`), `flush_interval` (seconds, 5), `heartbeat_interval` (seconds, 60; `0` sends none), `request_timeout` (seconds, 10), `on_error` (a function that receives each delivery problem), `disabled` (every call becomes a no-op).
57
+
58
+ `init()` returns the client and also makes it the module-level one, so the same functions work anywhere:
59
+
60
+ ```python
61
+ import originate_run as run
62
+
63
+ run.track("order_placed", {"total_cents": 4200})
64
+ ```
65
+
66
+ Before `init()` ran, calls are no-ops and nothing raises.
67
+
68
+ How it behaves in your process:
69
+
70
+ - **Nothing raises into your code.** A delivery problem goes to `on_error`; without one it is logged as a warning on the `originate_run` logger.
71
+ - **Nothing waits on the network in a request.** Reports are queued in memory and sent by one background thread. The exceptions are the calls that answer you: `deploy.report`, `backup.report`, `policy.check`, `consent.allows`, `heartbeat` and `flush`.
72
+ - **The thread never keeps the process alive**, and what is queued is sent when the process exits (one short attempt, so a slow network cannot hold the exit up). Call `run.shutdown()` from your own shutdown hook to send sooner.
73
+ - **Memory is bounded.** Queues drop their oldest rows on a long outage. Every delivery is tried three times with backoff; a refusal (4xx) is not retried.
74
+ - **Pre-forking servers work.** In a worker forked after `init()` (gunicorn with `--preload`), the SDK starts its thread again on the first report and sends only that worker's rows.
75
+
76
+ ## Request metrics
77
+
78
+ Every response is counted per minute and per route (`METHOD route`), with 5xx errors and p50, p95 and p99 latency. Only the route template and timings are sent: no addresses with ids, no query strings, no headers.
79
+
80
+ ### FastAPI, Starlette and other ASGI applications
81
+
82
+ ```python
83
+ from fastapi import FastAPI
84
+ from originate_run.asgi import RunMiddleware
85
+
86
+ app = FastAPI()
87
+ app.add_middleware(RunMiddleware, ignore=["/health", "/static/*"])
88
+ ```
89
+
90
+ The route is the framework's template (`/entries/{entry_id}`), with the prefix of a mounted sub-application. Where there is none (static files, a framework that does not say), the path is used with UUIDs, numbers and long hex ids replaced by `:id`. An address that matches no route and answers 404 is counted under one route, `(not found)`, so a scanner walking made-up addresses does not become a thousand routes. Latency ends when the response is complete; background tasks that run afterwards are not counted.
91
+
92
+ `ignore` takes whole paths, prefixes ending in `*`, and compiled regular expressions. Leave out static files and health probes.
93
+
94
+ ### Flask, Django and other WSGI applications
95
+
96
+ ```python
97
+ from originate_run.wsgi import RunWSGIMiddleware
98
+
99
+ app.wsgi_app = RunWSGIMiddleware(app.wsgi_app, ignore=["/health"]) # Flask
100
+ application = RunWSGIMiddleware(get_wsgi_application()) # Django, in wsgi.py
101
+ ```
102
+
103
+ WSGI does not say which route matched, so the path is used with ids replaced by `:id`. To name routes yourself, pass `route=`, a function that takes the WSGI environ and returns the template or `None`.
104
+
105
+ ### Anything else
106
+
107
+ ```python
108
+ run.metrics.record("GET", "/users/{user_id}", 200, duration_ms, True) # True: already a template
109
+ ```
110
+
111
+ ## Outside services
112
+
113
+ Time the calls your application makes to the services it depends on (its database, its file storage, another API), and Originate shows how each one is going next to what the vendor reports about itself: how many calls, how many failed, how slow.
114
+
115
+ ```python
116
+ # Around a call. An exception passes through untouched and counts as a failure.
117
+ with run.dependency.time("postgres"):
118
+ rows = conn.execute(sql).fetchall()
119
+
120
+ # As a decorator, on plain and async functions. `failed` judges a call that returns instead of raising.
121
+ @run.dependency.time("billing-api", failed=lambda response: response.status_code >= 500)
122
+ def charge(order): ...
123
+
124
+ # Or record it yourself: name, milliseconds, whether it worked.
125
+ run.dependency.record("resend", 182, True)
126
+ ```
127
+
128
+ Inside a `with` block, `call.fail()` marks the call as failed without an exception (`with run.dependency.time("drive") as call:`). `async with` works too.
129
+
130
+ To cover every call made through `requests` or `httpx` in one line, time them by host. Calls to hosts of vendors Originate recognizes (Anthropic, OpenAI, Resend, SendGrid, Stripe, Supabase, Slack, Hugging Face and others, see `KNOWN_VENDOR_HOSTS`) are timed under the vendor's name; add your own hosts by name. A response with a 5xx status or a 429, and a call that raises, count as failed.
131
+
132
+ ```python
133
+ run.dependency.instrument_requests(hosts={"www.googleapis.com": "google_workspace", "billing.internal.example.com": "billing-api"})
134
+ run.dependency.instrument_httpx() # sync and async clients
135
+ ```
136
+
137
+ Call them after `init()`. Each returns a function that undoes it. A host name starting with a dot matches every subdomain. Only the host, the status code and the duration are read: never the path, the query string, headers or bodies.
138
+
139
+ A name is a short lower case token (letters, digits, dot, dash, underscore, 40 at most); use a vendor's name where there is one (`neon`, `resend`, `anthropic`) so the row also carries that vendor's status. Calls are added up per minute and sent with the other batches. A database driver (psycopg, SQLAlchemy) is timed with `dependency.time()` around the query, or in the driver's own hook.
140
+
141
+ ## Events, metering and audit
142
+
143
+ ```python
144
+ run.track("order_placed", {"total_cents": 4200, "channel": "web"}, account_id="acct_123", session_id="sess_9")
145
+
146
+ run.meter("twilio_sms", 1, "message", cost_usd=0.0079) # an external_call event
147
+ run.meter("deepgram", 2.5, "minute", cost_usd=0.0108, props={"tier": "nova"})
148
+
149
+ run.audit.log("export_requested", "account:acct_123", {"by": "admin:42"}) # an audit_event
150
+ ```
151
+
152
+ Event names are lower snake case (`^[a-z][a-z0-9_]{1,63}$`). Properties are dimensions, not content: strings, numbers, booleans and `None`; anything else is serialized to JSON and truncated. Never put emails, names or message text in properties.
153
+
154
+ ## AI calls
155
+
156
+ ```python
157
+ run.ai.record(
158
+ provider="google",
159
+ model="gemini-2.5-flash",
160
+ operation="generate_content",
161
+ input_tokens=1200,
162
+ cached_tokens=0,
163
+ output_tokens=310,
164
+ duration_ms=840,
165
+ finish_reason="STOP",
166
+ feature="lead_summary",
167
+ account_id="acct_123", # your own id, never an email
168
+ )
169
+ ```
170
+
171
+ All arguments: `provider`, `model`, `operation` (`chat` by default), `input_tokens`, `cached_tokens`, `output_tokens`, `duration_ms`, `ttft_ms`, `finish_reason`, `error_type`, `cost_usd`, `feature`, `account_id`, `source`, `guardrail_mode`, `guardrail_decision`, `guardrail_categories`, `batch`, `schema_version`, `occurred_at`. There is no argument for a prompt or a completion.
172
+
173
+ This version has no wrappers for the OpenAI and Anthropic clients: record each call from the usage the response carries.
174
+
175
+ ## Health
176
+
177
+ ```python
178
+ run.health.register("postgres", lambda: conn.execute("select 1") is not None)
179
+ run.health.register("drive", check_drive, critical=False)
180
+
181
+ @app.get("/health")
182
+ def health():
183
+ status_code, body = run.health.handler()
184
+ return JSONResponse(body, status_code=status_code)
185
+ ```
186
+
187
+ A check returns `True` or nothing (ok), `False` (down), a status (`"ok"`, `"degraded"`, `"down"`) or `{"status": ..., "detail": ...}`; an exception or a timeout (3 seconds by default, `timeout=`) counts as down. It may be an `async` function. A critical check (the default) that is down takes the service down (HTTP 503); one that is not critical degrades it. The body is `{"status", "checks", "release", "service", "uptimeSeconds"}`.
188
+
189
+ `handler()` runs the checks and waits for them, so in FastAPI declare the endpoint with `def` (it then runs off the event loop), or call it with `await asyncio.to_thread(run.health.handler)`.
190
+
191
+ The same results ride on every heartbeat, which is sent at init and then every `heartbeat_interval`, so Originate sees your dependencies without probing them. A check named like one of the application's components in Originate (one that has no probe of its own) sets that component's state.
192
+
193
+ ## Deploy reports
194
+
195
+ From code:
196
+
197
+ ```python
198
+ run.deploy.report(version="1.4.0", commit=os.environ.get("GIT_SHA"), summary="Checkout fixes", pr_url=pr_url, deployer="github-actions", outcome="success")
199
+ ```
200
+
201
+ From a pipeline or a deploy script, without touching the application:
202
+
203
+ ```bash
204
+ ORIGINATE_RUN_SERVER_KEY=osk_... python -m originate_run deploy --version 1.4.0 --commit "$GIT_SHA" --summary "Checkout fixes" --deployer deploy-script --outcome success
205
+ ```
206
+
207
+ The installed command `originate-run` is the same thing. It exits with 0 when the report was accepted.
208
+
209
+ Each report becomes a change record. A report whose version matches a release already prepared in Originate marks that release as shipped.
210
+
211
+ A deploy report says that a version went live. It is not how a release is created:
212
+
213
+ - Send one only from the pipeline that performed the deploy, after the deploy. A report for a deploy that did not happen records one that did.
214
+ - A report whose version matches no prepared release is still recorded, as a release that has already shipped and was not announced. It holds only the fields above, with no summary for customers, no tickets, no highlights and no approval, and a shipped release cannot be deleted.
215
+ - To prepare a release (name, summary, tickets, highlights, approval), use the Originate connector (the `release_get`, `release_update` and `release_highlight` tools of the Originate MCP server) or the Releases page of the application in the dashboard. An agent asked to "create a release" that has no connector should say so and stop, not send a deploy report.
216
+
217
+ ## Backup reports
218
+
219
+ Run never takes backups. It records that yours happened, and works out from the reports how much data a failure could lose and how long a restore takes.
220
+
221
+ ```python
222
+ run.backup.report("Primary database", size_bytes=18_500_000_000, duration_seconds=312)
223
+ run.backup.report("Primary database", kind="restore_test", status="ok", duration_seconds=840)
224
+ ```
225
+
226
+ From the backup script or cron job:
227
+
228
+ ```bash
229
+ python -m originate_run backup --datastore "Primary database" --status ok --size-bytes 18500000000
230
+ ```
231
+
232
+ `kind` is `backup` (the default) or `restore_test`; `status` is `ok` (the default), `failed` or `partial`; `taken_at` defaults to now.
233
+
234
+ ## Policies and consent
235
+
236
+ ```python
237
+ decision = run.policy.check(data_classes=["pii"], purpose="marketing", region="eu", feature="newsletter")
238
+ # {"allowed": ..., "effect": "allow" | "deny" | "mask" | None, "policy_key": ..., "reason": ...}
239
+
240
+ answer = run.consent.allows("analytics", account.id)
241
+ # {"allowed": ..., "reason": "implicit" | "granted" | "withdrawn" | "unknown" | "no_policy" | "unavailable"}
242
+ ```
243
+
244
+ Policies are the ones you manage in the dashboard. A policy matches when every dimension its rule lists intersects the input; deny wins over mask, mask over allow; no matching policy allows. The subject id passed to `consent.allows` is SHA-256 hashed before it leaves the process. Results are cached for five minutes; `run.policy.refresh()` clears the cache.
245
+
246
+ Both read over the network when the cache is cold, so in an `async` handler call them with `asyncio.to_thread`. An application that is not on Run gets `{"allowed": True, "reason": "no_policy"}`. When the answer cannot be read the reason is `unavailable`: allowed for `policy.check` (fail open on your own rules), not allowed for `consent.allows` (fail closed on a person's choice).
247
+
248
+ ## Short-lived processes
249
+
250
+ A script, a cron job or a task worker that ends soon after its work should send before it ends:
251
+
252
+ ```python
253
+ run.init(flush_interval=0, heartbeat_interval=0) # no background thread
254
+ do_the_work()
255
+ run.flush(all=True) # sends everything, the minute in progress included; never raises
256
+ ```
257
+
258
+ ## What is sent, and what is not
259
+
260
+ Sent:
261
+
262
+ - Request metrics: route template, method, count, 5xx count, latency percentiles, per minute.
263
+ - Calls to outside services: the name you gave or the vendor a host belongs to, count, failed count, latency percentiles, per minute.
264
+ - AI calls: provider, model, operation, token counts, duration, time to first token, finish reason, error type, feature, your account id when you pass one.
265
+ - Events: the name, timestamp, your account and session ids when you pass them, and the properties you give.
266
+ - Heartbeats: SDK version, release, service name, health status per check (not the detail).
267
+ - Deploy and backup reports: what you put in them.
268
+
269
+ Never sent: prompts, completions, messages, request or response bodies, headers, cookies, IP addresses, emails, full addresses with ids. The middleware drops query strings and ids, and the `requests` and `httpx` timing reads the host and the status code only.
270
+
271
+ ## Development
272
+
273
+ Changes per version are in [CHANGELOG.md](CHANGELOG.md). The tests use the standard library only:
274
+
275
+ ```bash
276
+ python3 -m unittest discover -s tests -t tests
277
+ ```
278
+
279
+ ## License
280
+
281
+ Apache-2.0. Copyright 2026 Originate, Inc. See [LICENSE](LICENSE).