Skip to main content

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

Metadata

Release files for apikeylogger 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apikeylogger 1.1.1
File Size Uploaded
apikeylogger-1.1.1.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apikeylogger 1.1.1
File Interpreter ABI Platform
apikeylogger-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / apikeylogger-1.1.1.tar.gz

Download URL apikeylogger-1.1.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d3a4d94d0b552201bf82fbedc203316f94620d1bcf7549f7c8023345c022d1f9
BLAKE2b-256 checksum
How to use checksums
839ed2215ce99e282c5b5383027b1afb83841d717c9a155858562b009ece84d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.8.0 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.1 rfc3986/1.5.0 tqdm/4.66.1 urllib3/1.26.18 CPython/3.10.12

Release files / apikeylogger-1.1.1-py3-none-any.whl

Download URL apikeylogger-1.1.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ab09b3bc6104635a6d11b41c1d68011011cd4741513eff4b78f1a232fbcc3e0
BLAKE2b-256 checksum
How to use checksums
f17f4c413e72412eeeaaaace510fd8414c307d5c1c2ae3d088bcf508b508546d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.8.0 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.1 rfc3986/1.5.0 tqdm/4.66.1 urllib3/1.26.18 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page