OpenRouter Stats and Cost tracking

function

Filter function for Open WebUI, which displays stats and cost tracking when using OpenRouter connection

mindphuq
@mindphuq
·
a year ago
188
2
2K
Updated a year ago
Created May 28, 2025
openrouter_stats_and_cost_tracking.py
Python · 132 lines
"""
title: OpenRouter Stats & Cost tracking
author: Hristo Karamanliev
author_url: https://github.com/karamanliev
version: 1.1.0
"""
import logging
import time
from typing import Dict, Optional, Callable
import requests
from pydantic import BaseModel, Field

OpenRouter Stats & Cost tracking

Filter function for Open WebUI, which displays stats and cost tracking when using OpenRouter connection.

Utilizes usage accounting which OpenRouter enables after sending the updated user input. This makes it possible to report the exact cost and remaining credit as shown on the activity page on the OpenRouter dashboard.

Don't forget to enable the function globally after enabling it!


1