Metadata-Version: 2.5
Name: clovie-sdk
Version: 0.2.0
Summary: Clovie SDK — governed AI agent development with DID non-repudiation
Author-email: Clovie <prabhjot@clovie.io>
License-Expression: Apache-2.0
Requires-Python: >=3.9
Requires-Dist: cryptography>=41.0
Requires-Dist: httpx>=0.24
Provides-Extra: all
Requires-Dist: anthropic>=0.18; extra == 'all'
Requires-Dist: openai>=1.0; extra == 'all'
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.18; extra == 'anthropic'
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == 'openai'
Description-Content-Type: text/markdown

# Clovie SDK

Python SDK for governed AI agents with DID non-repudiation. Requests go through the Clovie gateway (policy, budget, audit, approvals).

## Install

```bash
pip install clovie-sdk
```

## Quickstart

1. Register the agent in Clovie (**AI Governance → Agents**). Its virtual key looks like `cv_prod_...`. If the agent has a DID, keep its base64 Ed25519 private key.
2. Configure:

```bash
export CLOVIE_API_KEY=cv_prod_...
export CLOVIE_GATEWAY_URL=https://gateway.clovie.io        # Clovie Cloud (default)
# export CLOVIE_GATEWAY_URL=https://gateway.corp.internal  # VPC / on-prem: your gateway
export CLOVIE_SIGNING_KEY=<base64-ed25519-private-key>     # optional, DID signing
export CLOVIE_DID=did:clovie:<agent-id>                    # optional
```

```python
from clovie import ClovieClient

client = ClovieClient()  # reads the env vars above

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

# Streaming
for chunk in client.chat.completions.create(model="gpt-4o", messages=[...], stream=True,
                                            stream_options={"include_usage": True}):
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="")
```

## Features

- **OpenAI-compatible.** It is a drop-in `chat.completions.create` / `acreate`. Every request field is forwarded unchanged: tools, tool_choice, parallel_tool_calls, response_format / json_schema, reasoning_effort, stream_options, max_completion_tokens, and any future field. `extra_body`, `extra_headers`, `extra_query` and `timeout` behave as they do in the OpenAI SDK.
- **DID non-repudiation.** Ed25519 signing (`X-Clovie-Signature`, `X-Clovie-DID`) covers the exact body bytes sent to the gateway.
- **Approval workflows.** When a policy requires human approval (HTTP 202), the SDK polls automatically and then resends the identical signed request.
- **`@governed` decorator.** It points existing OpenAI SDK code at the gateway, so policy, budget and audit apply. Those requests are built by the OpenAI SDK, so they are not DID-signed and approvals are not auto-polled. Use `ClovieClient` for that.

## Environment Variables

| Variable | Required | Description |
|---|---|---|
| `CLOVIE_API_KEY` | Yes | Agent virtual key (`cv_...`), sent as `Authorization: Bearer` |
| `CLOVIE_GATEWAY_URL` | No | Gateway base URL (default `https://gateway.clovie.io`; VPC/on-prem: your gateway). A trailing `/v1` is accepted. `CLOVIE_BASE_URL` is also read. |
| `CLOVIE_SIGNING_KEY` | No | Base64 Ed25519 private key for DID signing |
| `CLOVIE_DID` | No | Agent DID (`did:clovie:{agent_id}`) |
| `CLOVIE_APPROVAL_TIMEOUT` | No | Seconds to wait for an approval (default 3600) |
| `CLOVIE_APPROVAL_AUTO_POLL` | No | `false` returns the 202 body instead of polling |

For usage telemetry without routing through the gateway, see `clovie-observe`. It uses a different key (a team API key, `zo_...`) and a different endpoint.

See [CHANGELOG.md](CHANGELOG.md).

## License

Apache-2.0
