Thanks for the quick update — it's great that you're seeing:
Checking NanoGPT balance...
Balance: 2.73703532 Nano
That means your check_balance() call is working, but the balance data is not being displayed in the chat interface.
Let’s troubleshoot this step-by-step:
✅ What We Know
- ✅
outlet() is getting called (since you're seeing the log print).
- ✅ The balance API call succeeds, returns proper data.
- ✅ You expect the balance to appear below the assistant's last reply, but it doesn’t show.
🛠 Likely Reason
In Open WebUI some versions of the outlet() function return None, meaning the changes to body["messages"] are not applied unless your outlet() explicitly returns the modified body.
🔍 From the official docs:
The example for outlet() shows def outlet(self, body: dict) -> None: — but other examples return dict!
So what does that mean?
➡️ If your outlet() is defined like:
def outlet(self, body: dict) -> None:
# Modify body...
Then changes to body may not be applied in practice.
✅ Solution
Update your outlet() method to return the modified body explicitly like this:
✅ FIXED FILTER SNIPPET
def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
balance = self.check_balance()
if balance:
for message in reversed(body.get("messages", [])):
if message.get("role") == "assistant":
message["content"] += f"\n\n**NanoGPT Balance:**\n"
message["content"] += f"- Balance: {balance['balance']} Nano\n"
message["content"] += f"- Receivable: {balance['receivable']} Nano\n"
message["content"] += f"- Earned: {balance['earned']} Nano\n"
break
return body # <-- ✅ Make sure you return the modified body!
🔁 Full Modified Class if You Want to Replace It Entirely:
from pydantic import BaseModel
from typing import Optional
import requests
class Filter:
class Valves(BaseModel):
api_key: str = "YOUR_API_KEY"
def __init__(self):
self.valves = self.Valves()
self.NANOGPT_API_BASE_URL = 'https://nano-gpt.com/api/'
self.NANOGPT_API_BALANCE = self.NANOGPT_API_BASE_URL + 'check-nano-balance'
def check_balance(self) -> Optional[dict]:
print("Checking NanoGPT balance...")
try:
headers = {
"x-api-key": self.valves.api_key,
"Content-Type": "application/json"
}
response = requests.post(self.NANOGPT_API_BALANCE, headers=headers)
response.raise_for_status()
balance_info = response.json()
print(f"Balance: {balance_info['balance']} Nano")
return balance_info
except Exception as e:
print(f"Error checking balance: {e}")
return None
def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
return body
def stream(self, event: dict) -> dict:
return event
def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict: # ✅ must return a dict
balance = self.check_balance()
if balance:
for message in reversed(body.get("messages", [])):
if message.get("role") == "assistant":
message["content"] += (
f"\n\n**NanoGPT Balance:**\n"
f"- Balance: {balance['balance']} Nano\n"
f"- Receivable: {balance['receivable']} Nano\n"
f"- Earned: {balance['earned']} Nano\n"
)
break
return body # ✅ return the modified body
✅ Confirm It Works
- Save your updated filter file with the return statement.
- Restart Open WebUI (and/or your backend service).
- Open the chat again, send a message.
- This time, the assistant’s response should include the balance.
🧪 Quick Test: Inject Dummy Balance
To confirm the issue is return-related, before real API stuff, try this:
def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
for message in reversed(body["messages"]):
if message.get("role") == "assistant":
message["content"] += "\n\n**NanoGPT Balance:** 1337 TEST"
break
return body # <== This is crucial
✅ If this works, problem is solved.
🚀 Optional: Markdown Style (Text Improvements)
You could make the message look even cleaner:
message["content"] += (
f"\n\n---\n"
f"💰 **NanoGPT Balance**\n"
f"- **Balance:** `{balance['balance']} Nano`\n"
f"- **Receivable:** `{balance['receivable']} Nano`\n"
f"- **Earned:** `{balance['earned']} Nano`\n"
)
Let me know how that goes, and feel free to share a chat transcript / screenshot if it still doesn’t appear. I’ll help further.
You're really close! 😎💸