From a9a2ae4a685bcba70b9329f9335561ba2e3f9413 Mon Sep 17 00:00:00 2001 From: Xuwei <30304550+lixuwei2333@users.noreply.github.com> Date: Tue, 14 Apr 2026 12:22:00 +0800 Subject: [PATCH] [Anthropic] Fix clock mismatch in received_time causing negative Prometheus metrics (#22247) Signed-off-by: Xuwei Li --- python/sglang/srt/entrypoints/anthropic/serving.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/entrypoints/anthropic/serving.py b/python/sglang/srt/entrypoints/anthropic/serving.py index 88725d41c..9039a7c13 100644 --- a/python/sglang/srt/entrypoints/anthropic/serving.py +++ b/python/sglang/srt/entrypoints/anthropic/serving.py @@ -36,6 +36,7 @@ from sglang.srt.entrypoints.openai.protocol import ( ToolChoice, ToolChoiceFuncName, ) +from sglang.srt.observability.req_time_stats import monotonic_time if TYPE_CHECKING: from sglang.srt.entrypoints.openai.serving_chat import OpenAIServingChat @@ -313,7 +314,7 @@ class AnthropicServing: raw_request: Request, ) -> JSONResponse: """Handle non-streaming Anthropic request by delegating to OpenAI handler.""" - received_time = time.time() + received_time = monotonic_time() received_time_perf = time.perf_counter() # Validate @@ -369,7 +370,7 @@ class AnthropicServing: raw_request: Request, ) -> Union[StreamingResponse, JSONResponse]: """Handle streaming Anthropic request.""" - received_time = time.time() + received_time = monotonic_time() received_time_perf = time.perf_counter() # Validate