Metadata-Version: 2.4
Name: wiv-air
Version: 0.1.2
Summary: Wiv Air agent SDK: send OpenTelemetry traces to Air and check your agent wallet before you spend.
Author: Wiv
License-Expression: Apache-2.0
Project-URL: Homepage, https://wiv.ai
Project-URL: Documentation, https://docs.wiv.ai/air
Keywords: ai,agents,opentelemetry,llm,cost,finops,wiv
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: System :: Monitoring
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: otel
Requires-Dist: opentelemetry-sdk>=1.27; extra == "otel"
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27; extra == "otel"
Dynamic: license-file

# wiv-air

The Python SDK for [Wiv Air](https://wiv.ai) agents. It does two things:

- **Traces.** Sends your agent's OpenTelemetry GenAI traces to Air, which
  shows each run, step and tool call with its estimated cost and alerts you
  when an agent loops or overspends.
- **Wallet.** Asks the agent's Air wallet before an expensive step. Air
  answers allow, deny, or ask a person.

It has no dependencies and uses only the standard library. Air never sits in front of your model
calls.

## Install

```bash
pip install wiv-air
# with OpenTelemetry, so configure_tracing() also installs a tracer provider:
pip install "wiv-air[otel]"
```

## Configure

Register the agent in Air (**Agents → Add agent**), create a key, and set it:

```bash
export AIR_AGENT_KEY="airak1...."
# optional: defaults to https://agents-air.wiv.ai
export AIR_AGENT_ENDPOINT="https://agents-air.wiv.ai"
```

## Send traces

```python
from wiv_air import Air

air = Air()
air.configure_tracing(service_name="support-triage")
air.ping()  # one test span: the agent's setup page in Air turns green
```

Call `configure_tracing()` once, before your instrumentors. It adapts to the
process, and the `mode` it returns says what it did:

| Your process | What it does | `mode` |
|---|---|---|
| Already uses the OpenTelemetry SDK (Logfire, Langfuse, your own collector) | Adds Air as one more exporter on your provider. Your exporters and `OTEL_*` settings are untouched | `attached` |
| No tracer provider yet, `wiv-air[otel]` installed | Installs a provider that sends to Air | `installed` |
| No OpenTelemetry SDK | Sets the standard `OTEL_EXPORTER_OTLP_TRACES_*` variables for an exporter you create later | `environment` |
| A non-OpenTelemetry provider | Changes nothing and warns. Add an OTLP exporter for `Air().otlp_config()` yourself | `unsupported` |

Calling it more than once is safe: Air's exporter is added to a provider
only once.

Air reads OpenTelemetry GenAI spans (`gen_ai.*`), so instrument your model
client too. One example is `opentelemetry-instrumentation-openai-v2`.

## Ask the wallet before spending

```python
from wiv_air import Air, ApprovalPending, WalletDenied

air = Air()
try:
    with air.spend(40, run_id=conversation_id, reason="draft reply") as step:
        result = call_the_model()
        step.actual_cents = cost_of(result)  # optional
except WalletDenied as denied:
    stop(denied.authorization.reason)
except ApprovalPending:
    retry_later()
```

- **Allow:** the block runs. Air reserves the estimate and releases it when
  the block ends.
- **Deny:** `WalletDenied` is raised before the block runs.
- **Ask:** a request opens in Air's Approval Center. Pass
  `ask_timeout=120` to wait for the answer. Otherwise `ApprovalPending` is
  raised.

New wallets start in observe mode. Air always allows, and counts what it would
have denied, until an admin switches the wallet to enforce.

To call the wallet directly, use `air.wallet.authorize(...)`,
`air.wallet.report(...)` and `air.wallet.status()`.

## License

Apache-2.0
