Metadata-Version: 2.4
Name: origina
Version: 0.1.1
Summary: Official Python SDK for Origina: license verification, usage reporting, and agent calls for licensed AI assets.
Author: Origina
License: Proprietary
Project-URL: Homepage, https://origina.cloud
Project-URL: Documentation, https://origina.cloud/whitepaper
Project-URL: Repository, https://github.com/hendrixoziegbe-007/Origina-Ai
Keywords: origina,ai,licensing,usage,metering,gateway
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# Origina Python SDK

The official Python client for [Origina](https://origina.cloud). It drops into
your training or inference pipeline and does three things, all with a single
Machine Identity credential and no third-party dependencies:

1. **Verify** that a running deployment still holds an active license.
2. **Report** the downstream usage it actually consumed, so it is metered and billed correctly.
3. **Call** a licensed agent through the Gateway.

## Install

```bash
pip install origina
```

## Get a key

In Origina, go to **Developers → Machine Identities**, create an identity, and
grant it the scopes for what you plan to call:

| You call | Scope needed |
| --- | --- |
| `verify(...)` | `gateway.stream` |
| `report_usage(...)` | `usage.write` |
| `call_agent(...)` | `gateway.invoke` |
| `open_session(...)` / `dataset_session(...)` | `gateway.stream` |

Then **Issue a credential** from that identity and use the key it shows you
(shown once). Credential scopes are fixed when issued: if you add a scope to
the identity later, issue a fresh credential to pick it up.

## Quick start

```python
from origina import Origina

client = Origina(api_key="origina_machine_...")

# 1. Verify a deployment (returns a short-lived token and the license picture)
result = client.verify(
    asset_id="asset-uuid",
    deployment_id="prod-eu-1",     # a stable id for THIS running deployment
    env_label="prod-eu-gke",
)
print(result.licensed, result.over_deployed, result.active_deployments)

# 2. Report what you consumed (idempotent on request_id)
client.report_usage(
    asset_id="asset-uuid",
    event_type="training",         # training | inference | api_request
    quantity=1,                    # count of billable units, not tokens
    request_id="training-run-42",  # reuse on retry so you are never double-billed
)

# 3. Call a licensed agent
answer = client.call_agent(asset_id="agent-uuid", input="Summarize this ticket")
print(answer)
```

## Metered training run

The `training_run` context manager verifies on entry, keeps a background
heartbeat while your code runs (so a revoked license is noticed quickly), and
lets you report what you used:

```python
from origina import Origina

client = Origina(api_key="origina_machine_...")

with client.training_run(
    asset_id="dataset-uuid",
    deployment_id="prod-eu-1",
    env_label="prod-eu-gke",
) as run:
    train_my_model()               # your pipeline
    run.report(quantity=1)         # records one 'training' event

    if run.entitlement_error:      # license was revoked mid-run
        stop_and_clean_up()
```

## Declare an AI Bill of Materials

Tell Origina what your agent was built from, so it can answer "what data
touches which model" and flag the whole chain the moment a linked licence
lapses. You must own the agent asset; the model and datasets are referenced by
their Origina asset ids.

```python
bom = client.bind(
    agent="agent-uuid",
    model="model-uuid",                 # fine-tuned from
    datasets=["dataset-a", "dataset-b"] # trained on
)
print(bom["compliant"], bom["flaggedCount"])

# Check compliance any time (each dependency is owned / licensed / unlicensed):
bom = client.get_bom(agent="agent-uuid")
for dep in bom["dependencies"]:
    print(dep["childAssetName"], dep["compliance"])
```

## Just-in-time agent sessions

For autonomous agents: open a short-lived, purpose-scoped grant with a blast
radius (a total spend cap), call the agent through it, and it revokes itself
when the block ends. A runaway or prompt-injected agent can only ever spend up
to the cap before its own session refuses it — and you can revoke instantly.

```python
with client.agent_session(
    agent="agent-uuid",
    purpose="process monthly invoices",
    max_seconds=1800,
    blast_radius_cents=5000,   # this session may spend at most $50
) as sess:
    answer = sess.call("Summarize invoice 42")
```

## Export the audit trail

One chronological list of every credential, verify, usage, and licence event
for your organization — hand it to an auditor or pull it into your own SOC/ISO
evidence. Requires the `audit.read` scope.

```python
rows = client.export_audit(organization_id="org-uuid", since_days=90)
for r in rows:
    print(r["timestamp"], r["category"], r["action"])
```

## Pull licensed files

Open a session, get a delivery URL per file, and the session closes itself
(recording the usage) when the block exits. Uses the same key as everything
else:

```python
with client.dataset_session(asset_id="dataset-uuid") as sess:
    info = sess.deliver(file_id="file-uuid")
    # On S3-backed storage: {"method": "signed_url", "url": "https://..."}
    # Fetch info["url"] directly to retrieve the bytes.
```

## Errors

```python
from origina import OriginaError, OriginaAuthError

try:
    client.call_agent(asset_id="agent-uuid", input="hi")
except OriginaAuthError as e:
    # Bad key, missing scope, or no active license.
    print(e.code, e.message)
except OriginaError as e:
    print("Request failed:", e.message)
```

## A note on honesty

The SDK meters by cooperation: it reports the usage your pipeline hands it. It
is not tamper-proof, the same way any analytics SDK is not. Your license
agreement is what makes the reporting binding, and Origina retains audit
rights. For control rather than cooperation you would need a clean-room
delivery model, which this SDK does not attempt.
