Metadata-Version: 2.1
Name: apikeylogger
Version: 1.1.1
Summary: This library allows you to log the OpenAI api usage *by key* without having to change your code
Home-page: https://github.com/federicoromeo/apikeylogger
Author: Federico Romeo
Author-email: federico.romeo.98@gmail.com
License: MIT
Project-URL: Source, https://github.com/federicoromeo/apikeylogger
Keywords: openai,apikey,api,logger,tracker
Platform: UNKNOWN
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: beautifulsoup4
Requires-Dist: openai >=1.6.0
Requires-Dist: python-dotenv >=0.18.0
Requires-Dist: tiktoken

# apikeylogger

Track your *OpenAI* api usage **by key**, without any code change.

#### Installation

```bash
pip install apikeylogger
```

#### Setup
Create a *.env* file with your OpenAI *api key* and *organization id* ([find yours here](https://platform.openai.com/account/organization)), like this:
```bash
OPENAI_API_KEY = ""
OPENAI_ORG_ID = ""
```


#### Usage
```python
# This call will transparently log your API usage by key in a local json file *apikeylogs.json*
from apikeylogger import track_openai
track_openai()

# Your normal code that uses openai
from openai import OpenAI
from dotenv import load_dotenv

load_dotenv()
client = OpenAI()

response = client.chat.completions.create(
    messages = [
        {
            "role": "user",
            "content": "What is the meaning of life?",
        }
    ],
    model = "gpt-3.5-turbo-0125" # any openai model
)

print(response.choices[0].message.content)
```

#### Test

Run tests with:
```bash
pytest
```


