This library allows you to log the OpenAI api usage *by key* without having to change your code
Project description
apikeylogger
Track your OpenAI api usage by key, without any code change.
Installation
pip install apikeylogger
Setup
Create a .env file with your OpenAI api key and organization id (find yours here), like this:
OPENAI_API_KEY = ""
OPENAI_ORG_ID = ""
Usage
# 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:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
apikeylogger-1.1.1.tar.gz
(7.9 kB
view hashes)
Built Distribution
Close
Hashes for apikeylogger-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ab09b3bc6104635a6d11b41c1d68011011cd4741513eff4b78f1a232fbcc3e0 |
|
MD5 | 9d528808c208cc869a307664ae2e5f7e |
|
BLAKE2b-256 | f17f4c413e72412eeeaaaace510fd8414c307d5c1c2ae3d088bcf508b508546d |