Skip to main content

Track usage of LLM tokens in a SQLite table

Project description

datasette-llm-usage

PyPI Changelog Tests License

Track usage of LLM tokens in a SQLite table

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-llm-usage

Usage

This plugin tracks LLM token usage in Datasette via the datasette-llm llm_prompt_context hook. It creates two tables:

  • llm_usage: Tracks token usage per request (model, purpose, actor, input/output tokens)
  • llm_usage_prompt_log: Optionally logs full prompts and responses

Configuration

By default the tables are created in the internal database passed to Datasette using --internal internal.db. You can change that by setting the following in your Datasette plugin configuration:

{
    "plugins": {
        "datasette-llm-usage": {
            "database": "your_database_name"
        }
    }
}

To enable full prompt and response logging, set log_prompts to true:

{
    "plugins": {
        "datasette-llm-usage": {
            "log_prompts": true
        }
    }
}

Prompt testing tool

The plugin also provides a simple demo page at /-/llm-usage-simple-prompt which can be used to execute prompts for testing.

That page requires the user to have the llm-usage-simple-prompt permission.

Development

Clone this repo and run the tests:

cd datasette-llm-usage
uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasette_llm_usage-0.2a0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datasette_llm_usage-0.2a0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file datasette_llm_usage-0.2a0.tar.gz.

File metadata

  • Download URL: datasette_llm_usage-0.2a0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for datasette_llm_usage-0.2a0.tar.gz
Algorithm Hash digest
SHA256 cce0156565c391d6c3fe7c358c7428b3bac70e7eefdf2e0430b688ba0e3f6df0
MD5 19388645d2baf42d02a4fac7b26c6897
BLAKE2b-256 dec6ca3ac2e610f0f6454bec00c184eb2441d36318bf632a78ae55a020daba64

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasette_llm_usage-0.2a0.tar.gz:

Publisher: publish.yml on datasette/datasette-llm-usage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file datasette_llm_usage-0.2a0-py3-none-any.whl.

File metadata

File hashes

Hashes for datasette_llm_usage-0.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 2846f4e95c9fcf31d764536ef18e026d927ef3bb322488c1fd74aeb42e5cf8ad
MD5 528efb579faffe0c389020b9f8968c06
BLAKE2b-256 11e20143a8dd362edba1cc74a264d24a96d20e76a5634e357ae51d49787b3a2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasette_llm_usage-0.2a0-py3-none-any.whl:

Publisher: publish.yml on datasette/datasette-llm-usage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page