Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

feat(ui): add time to first token (TTFT) to logs (#22819)

Ishaan Jaffb7f43d411a3e
diff --git a/ttft-logs-screenshot.png b/ttft-logs-screenshot.png
new file mode 100644
index 00000000000..f07ad3b0308
Binary files /dev/null and b/ttft-logs-screenshot.png differ
diff --git a/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx b/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx
index 533e51d31bb..75618076079 100644
--- a/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx
+++ b/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx
@@ -258,6 +258,12 @@ function GuardrailLabel({ label, maskedCount }: { label: string; maskedCount: nu
}
function MetricsSection({ logEntry, metadata }: { logEntry: LogEntry; metadata: Record<string, any> }) {
+ const completionStartTime = logEntry.completionStartTime;
+ const ttftMs =
+ completionStartTime && completionStartTime !== logEntry.endTime
+ ? new Date(completionStartTime).getTime() - new Date(logEntry.startTime).getTime()
+ : null;
+
const hasCacheActivity =
logEntry.cache_hit ||
(metadata?.additional_usage_values?.cache_read_input_tokens &&
@@ -284,6 +290,9 @@ function MetricsSection({ logEntry, metadata }: { logEntry: LogEntry; metadata:
</Descriptions.Item>
<Descriptions.Item label="Cost">${formatNumberWithCommas(logEntry.spend || 0, 8)}</Descriptions.Item>
<Descriptions.Item label="Duration">{logEntry.request_duration_ms != null ? (logEntry.request_duration_ms / 1000).toFixed(3) : "-"} s</Descriptions.Item>
+ {ttftMs != null && ttftMs > 0 && (
+ <Descriptions.Item label="Time to First Token">{(ttftMs / 1000).toFixed(3)} s</Descriptions.Item>
+ )}
{hasCacheActivity && (
<>
diff --git a/ui/litellm-dashboard/src/components/view_logs/columns.tsx b/ui/litellm-dashboard/src/components/view_logs/columns.tsx
index 3d9d73bb09b..a9110d31d30 100644
--- a/ui/litellm-dashboard/src/components/view_logs/columns.tsx
+++ b/ui/litellm-dashboard/src/components/view_logs/columns.tsx
@@ -62,6 +62,7 @@ export type LogEntry = {
proxy_server_request?: string | any[] | Record<string, any>;
session_id?: string;
status?: string;
+ completionStartTime?: string;
request_duration_ms?: number;
session_total_count?: number;
session_total_spend?: number;
@@ -270,6 +271,25 @@ export const createColumns = (sortProps?: LogsSortProps): ColumnDef<LogEntry>[]
);
},
},
+ {
+ header: "TTFT (s)",
+ accessorKey: "completionStartTime",
+ cell: (info: any) => {
+ const row = info.row.original;
+ const completionStartTime = info.getValue();
+ if (!completionStartTime) return <span>-</span>;
+ // For non-streaming, completionStartTime == endTime so TTFT is not meaningful
+ if (completionStartTime === row.endTime) return <span>-</span>;
+ const ttftMs = new Date(completionStartTime).getTime() - new Date(row.startTime).getTime();
+ if (ttftMs <= 0) return <span>-</span>;
+ const ttftSeconds = (ttftMs / 1000).toFixed(2);
+ return (
+ <Tooltip title={`${ttftMs}ms`}>
+ <span className="max-w-[15ch] truncate block">{ttftSeconds}</span>
+ </Tooltip>
+ );
+ },
+ },
{
header: "Team Name",
accessorKey: "metadata.user_api_key_team_alias",