Metadata-Version: 2.4
Name: metrecept-sdk
Version: 0.2.0
Summary: OpenAI base_url helper and receipt verifier for Metrecept: signed Ed25519 receipts for AI agent calls (api.metrecept.co.uk)
License: MIT
Project-URL: Homepage, https://metrecept.co.uk
Project-URL: Documentation, https://metrecept.co.uk/docs
Project-URL: Repository, https://github.com/iwasinnam2/metrecept-opensource
Keywords: metrecept,openai,llm,receipts,ed25519,jws,agents
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: openai
Requires-Dist: openai>=1.40.0; extra == "openai"
Dynamic: license-file

# metrecept-sdk (Python)

Thin helper so the official OpenAI SDK becomes a one-line `base_url` swap for **Metrecept**, which returns a signed Ed25519 receipt for every call.


## Install (editable)

```bash
cd sdks/python
pip install -e ".[openai]"
```

## Publish to PyPI

Every real call needs a Metrecept API key; the default base URL is `https://api.metrecept.co.uk/v1`.

```bash
cd sdks/python
python -m build
twine upload dist/*
```

## Usage

```python
from metrecept_sdk import openai_client, LOCAL_BASE_URL, DEFAULT_BASE_URL

client = openai_client("sk-at-dev", base_url=LOCAL_BASE_URL)
# After cutover:
# client = openai_client("sk-at-...", base_url=DEFAULT_BASE_URL)
```

### The receipt as a link

Every receipted response carries `X-Metrecept-Verify`, a public link that
checks the signature in the reader's browser — no account. Append it to
whatever the agent already produced (PR body, ticket, email):

```python
from metrecept_sdk import receipt_trailer

body = body + "\n\n" + receipt_trailer(response.headers)
# -> "Receipt: https://metrecept.co.uk/verify#eyJ..."
```

It also accepts the JSON of `GET /v1/sessions/{id}`. Returns `""` when
there is nothing to link. The JWS rides the URL fragment, so it never
reaches a server log.

A streamed MISS cannot carry its receipt in a header (the headers leave
before the provider has finished), so it rides as the last `data:` chunk
before `[DONE]`, with empty `choices`. Read it out of the stream you kept:

```python
from metrecept_sdk import receipt_from_sse_lines, verify_url

jws = receipt_from_sse_lines(captured.splitlines())   # "" when the stream did not finish
link = verify_url(jws) if jws else ""
```
