Metadata-Version: 2.5
Name: fennas
Version: 0.1.0
Summary: OpenAI and Anthropic clients pointed at a Fennas gateway
Project-URL: Homepage, https://github.com/Jamal-Akhras/fennas
Project-URL: Repository, https://github.com/Jamal-Akhras/fennas
Project-URL: Changelog, https://github.com/Jamal-Akhras/fennas/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/Jamal-Akhras/fennas/issues
Project-URL: Documentation, https://github.com/Jamal-Akhras/fennas/tree/main/docs
Author: Jamal Akhras
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: anthropic,audit,budget,fennas,gateway,llm,openai,policy
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: anthropic
Requires-Dist: anthropic<3,>=2.9; extra == 'anthropic'
Provides-Extra: openai
Requires-Dist: openai<4,>=3.52; extra == 'openai'
Description-Content-Type: text/markdown

# fennas

OpenAI and Anthropic clients for Python, already pointed at a
[Fennas](https://github.com/Jamal-Akhras/fennas) gateway. Fennas is a
policy and audit gateway for LLM traffic.

```
pip install "fennas[openai]"
pip install "fennas[anthropic]"
```

Install the extra for the SDK you use. Then import it as `fennas`. Python
3.10 or later.

```python
import fennas

client = fennas.openai()
reply = client.chat.completions.create(model="qwen3", messages=[{"role": "user", "content": "Hi"}])
```

The address comes from the argument, then `FENNAS_BASE_URL`, then `http://localhost:8080`.
The key comes from the argument, then `FENNAS_API_KEY`. The library reads no
other variable, so `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` never reach Fennas.
`async_openai()` and `async_anthropic()` are the async clients.

## Headers

`data_class` and `user` on a client are sent with every call. The user goes
in `X-Fennas-User`, and is recorded when the tenant's `userHeader` names
that header. For one call, `fennas.headers()` builds the headers, and
`dry_run` asks for a cost estimate without calling the model. Costs and dry
runs are for tenants with `showCosts: true`:

```python
claude = fennas.anthropic(data_class="confidential", user="u-17")
claude.messages.create(
    model="claude-sonnet",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hi"}],
    extra_headers=fennas.headers(dry_run=True),
)
```

## Receipt

`fennas.receipt(raw)` reads what Fennas said about a call from a raw
response: `trace_id`, `cost`, `cost_max` and `output_limited`. The two costs
are `None` unless the tenant has `showCosts: true`.

```python
raw = claude.messages.with_raw_response.create(
    model="claude-sonnet", max_tokens=1024, messages=[{"role": "user", "content": "Hi"}]
)
print(fennas.receipt(raw).trace_id, raw.parse().content)
```

## Refusal

`fennas.refusal(error)` reads why Fennas refused a call from the SDK's
error: `code`, `message`, `status`, `trace_id` and `retry_after`. It returns
`None` for an error that didn't come from Fennas.

```python
try:
    client.chat.completions.create(model="qwen3", messages=[{"role": "user", "content": "Hi"}])
except Exception as error:
    why = fennas.refusal(error)
    if why is not None:
        print(why.code, why.trace_id)
```

The library retries nothing, logs nothing and decides nothing: a call made
without it gets the same guards, budget and audit.

## More

Source, documentation and the gateway itself: https://github.com/Jamal-Akhras/fennas

The client libraries are described in
https://github.com/Jamal-Akhras/fennas/blob/main/docs/client-libraries.md

Licensed under the Apache License 2.0:
https://github.com/Jamal-Akhras/fennas/blob/main/LICENSE
