Skip to content

Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI

Fix: Rounding error showing cost (#293)

AndinAvdiu5c7cb7f267fc
diff --git a/agentops/client.py b/agentops/client.py
index a760c67a..5e9bd773 100644
--- a/agentops/client.py
+++ b/agentops/client.py
@@ -13,7 +13,7 @@ import sys
import threading
import traceback
import logging
-from decimal import Decimal
+from decimal import Decimal, ROUND_HALF_UP
from uuid import UUID, uuid4
from typing import Optional, List, Union
@@ -424,7 +424,7 @@ class Client(metaclass=MetaClient):
"This run's cost ${}".format(
"{:.2f}".format(token_cost_d)
if token_cost_d == 0
- else "{:.6f}".format(token_cost_d)
+ else "{:.6f}".format(token_cost_d.quantize(Decimal('0.000001'), rounding=ROUND_HALF_UP))
)
)