sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] Five model providers hardcode latencyMs to 0

Open hashwnath opened this issue 3 days ago • 1 comments

Human Overview

Five model providers always report 0ms latency, which breaks OTel spans and multiagent metrics.

Checks

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

SDK Language

Python

Strands Version

1.67.0

Language Runtime Version

Python 3.12

Operating System

macOS 15.5

Installation Method

pip

Steps to Reproduce

  1. Use AnthropicModel, OpenAIModel, OpenAIResponsesModel, GeminiModel, or LlamaAPIModel
  2. Make any agent call
  3. Look at the metadata event metrics - latencyMs is 0 every time

Expected Behavior

latencyMs should report actual request duration. Ollama and Mistral already do this correctly.

Actual Behavior

All five providers return "latencyMs": 0 with a # TODO comment:

  • models/anthropic.py:1199
  • models/openai.py:691
  • models/openai_responses.py:1309
  • models/gemini.py:623
  • models/llamaapi.py:364

The tracer skips gen_ai.server.request.duration when latencyMs is 0 (tracer.py:292), so OTel tools never see request duration for these providers. Swarm/Graph latency accumulation is also wrong since it sums 0s.

Possible Solution

process_stream() in streaming.py already gets start_time and computes TTFB at the metadata event. Same start_time can compute total latency as a fallback when the model reports 0. Single change in streaming.py covers all five providers without touching each model file.

I have a fix for this if the team wants a PR.

Additional Context

No response

Related Issues

No response

hashwnath avatar Nov 30 '26 02:11 hashwnath

I have a fix that computes latency from the existing start_time in process_stream() covers all five providers in one spot. Cool if I open a PR?

hashwnath avatar Nov 30 '26 02:11 hashwnath