Skip to content

[BUG] accumulated_usage token count is always 0 (Azure OpenAI) #47

Closed
@patrickpenn

Description

@patrickpenn

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

0.1.2

Python Version

3.12.0

Operating System

Windows 11

Installation Method

pip

Steps to Reproduce

  1. install strands-agents version 0.1.2. via pip install
  2. Create environment variables for Azure OpenAI through LiteLLM

Expected Behavior

Seeing an output greater than 0 for inputTokens and outputTokens.

Actual Behavior

Current output is
Input tokens: 0
Output tokens: 0

Additional Context

Here is my script:

import os
import sys
from strands import Agent
from strands.models.litellm import LiteLLMModel

openai_model = "gpt-4omini"
os.environ["AZURE_API_KEY"] = ""
os.environ["AZURE_API_BASE"] = ""
os.environ["AZURE_API_VERSION"] = ""


model = LiteLLMModel(
    model_id=f"azure/{openai_model}",
    
    params={
        "max_tokens": 16384,
        "temperature": 0.1,
    }
)

agent = Agent(model=model, system_prompt="Say hello to the user")

response = agent("Hi, my name is John Doe.")

print(f"Input tokens: {response.metrics.accumulated_usage['inputTokens']}")
print(f"Output tokens: {response.metrics.accumulated_usage['outputTokens']}")
print(f"Execution time: {sum(response.metrics.cycle_durations):.2f} seconds")
sys.exit(0)

The output is

Hello, John Doe! How can I assist you today?
Input tokens: 0
Output tokens: 0
Execution time: 0.93 seconds

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions