Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Bug]: Add correct defaults when token values are not found (#417)

patcher9359d9573efca
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index 6cd523b2..c24c782a 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.22.1"
+version = "1.22.2"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
diff --git a/sdk/python/src/openlit/instrumentation/langchain/langchain.py b/sdk/python/src/openlit/instrumentation/langchain/langchain.py
index da993fdb..6a35a250 100644
--- a/sdk/python/src/openlit/instrumentation/langchain/langchain.py
+++ b/sdk/python/src/openlit/instrumentation/langchain/langchain.py
@@ -481,8 +481,8 @@ def chat(gen_ai_endpoint, version, environment, application_name,
response = wrapped(*args, **kwargs)
try:
- input_tokens = response.response_metadata["prompt_eval_count"] or 0
- output_tokens = response.response_metadata["eval_count"] or 0
+ input_tokens = response.response_metadata.get("prompt_eval_count", 0)
+ output_tokens = response.response_metadata.get("eval_count", 0)
# Calculate cost of the operation
cost = get_chat_model_cost(