Cost Tracker - OpenRouter

function

This function calculates API interaction pricing in Open WebUI and records user model usage for OpenRouter models. Based on maki's edit of bgeneto's cost tracker. See https://github.com/bgeneto/open-webui-cost-tracker for usage.

kkoolldd
@kkoolldd
·
2 years ago
655
1
2.8K
Updated 2 years ago
Created Jan 31, 2025
cost_tracker_openrouter.py
Python · 512 lines
"""
title: Cost Tracker for OpenRouter
description: This function is designed to manage and calculate the costs associated with user interactions and model usage in a Open WebUI based on OpenRouters pricings. See https://github.com/bgeneto/open-webui-cost-tracker & https://openwebui.com/f/makimaki/cost_tracker/edit
author: Kkoolldd (maki & bgeneto)
author_url: https://github.com/bgeneto/open-webui-cost-tracker
funding_url: https://github.com/bgeneto/open-webui-cost-tracker
version: 0.3.2
license: MIT
requirements: requests, tiktoken, cachetools, pydantic
environment_variables:
disclaimer: This function is provided as is without any guarantees.
            It is your responsibility to ensure that the function meets your requirements.

This function calculates API interaction pricing in Open WebUI and records user model usage for OpenRouter models. Based on maki's edit of bgeneto's cost tracker. See https://github.com/bgeneto/open-webui-cost-tracker for usage.


0