File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
src/langtrace_python_sdk/utils Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -148,22 +148,25 @@ def set_usage_attributes(span, usage):
148148 if usage is None :
149149 return
150150
151+ input_tokens = usage .get ("input_tokens" ) or usage .get ("prompt_tokens" ) or 0
152+ output_tokens = usage .get ("output_tokens" ) or usage .get ("completion_tokens" ) or 0
153+
151154 set_span_attributes (
152155 span ,
153156 SpanAttributes .LLM_USAGE_PROMPT_TOKENS .value ,
154- usage [ " input_tokens" ] or 0 ,
157+ input_tokens ,
155158 )
156159
157160 set_span_attributes (
158161 span ,
159162 SpanAttributes .LLM_USAGE_COMPLETION_TOKENS .value ,
160- usage [ " output_tokens" ] or 0 ,
163+ output_tokens ,
161164 )
162165
163166 set_span_attributes (
164167 span ,
165168 SpanAttributes .LLM_USAGE_TOTAL_TOKENS .value ,
166- ( usage [ " input_tokens" ] or 0 ) + ( usage [ " output_tokens" ] or 0 ) ,
169+ input_tokens + output_tokens ,
167170 )
168171
169172 if "search_units" in usage :
You can’t perform that action at this time.
0 commit comments