You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Install this plugin in the same environment as Datasette.
datasette install datasette-llm-usage
Usage
This plugin adds functionality to track and manage LLM token usage in Datasette. It creates two tables.
_llm_usage: Tracks usage of LLM tokens
_llm_allowance: Manages credit allowances for LLM usage
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:
The plugin provides an LLM class that wraps the llm library to track token usage:
fromdatasette_llm_usageimportLLMllm=LLM(datasette)
# Get available modelsmodels=llm.get_async_models()
# Get a specific modelmodel=llm.get_async_model("gpt-4o-mini", purpose="my_purpose")
# Use the modelresponse=awaitmodel.prompt("Your prompt here")
text=awaitresponse.text()
Usage will be automatically recorded.
Built-in endpoint
The plugin provides a simple demo endpoint at /-/llm-usage-simple-prompt that requires authentication and uses the gpt-4o-mini model.
Supported Models and Pricing
The plugin includes pricing information for various models including: