<p align="center">
  <img src="https://assets.fenra.io/public/header.png" alt="Fenra" width="100%">
</p>

# Fenra Python SDK

[![PyPI](https://img.shields.io/pypi/v/fenra.svg)](https://pypi.python.org/pypi/fenra)
[![Python](https://img.shields.io/pypi/pyversions/fenra.svg)](https://pypi.python.org/pypi/fenra)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

FinOps platform for AI cost visibility

## Usage

Install the package:

```bash
pip install fenra
```

Initialize and start tracking:

```python
import fenra
from openai import OpenAI

fenra.init(api_key="your-fenra-api-key")

# Use as normal - costs are tracked automatically
client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

Works with Anthropic (Claude) and Google (Gemini) the same way.

Set context for cost attribution:

```python
fenra.set_context(
    billable_customer_id="cust_123",  # recommended
    environment="production",
    feature="chat",
)
```

For custom providers or manual tracking:

```python
fenra.track(
    provider="custom",
    model="my-model",
    input_tokens=100,
    output_tokens=50,
)
```

To disable auto-tracking:

```bash
export FENRA_DISABLE_AUTO_TRACK=1
```

To enable debug logging:

```python
import logging
logging.getLogger("fenra").setLevel(logging.DEBUG)
```

## Support

- [Documentation](https://docs.fenra.io)
- [Contact](mailto:hello@fenra.io)

## Privacy

Fenra is privacy-first by default. No prompts or responses are stored unless explicitly enabled.

## License

The Fenra Python SDK is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
