Commit 304a3c6
authored
feat: add latency tracking and enhanced token usage details (#665)
## Summary
Added latency tracking and enhanced token usage details for LLM responses, providing more granular metrics for performance monitoring and cost analysis.
## Changes
- Added latency tracking to Vertex provider responses, measuring and reporting API call duration in milliseconds
- Enhanced `BifrostLLMUsage` structure with detailed token usage fields for both prompt and completion tokens
- Added support for specialized token types like cached tokens, reasoning tokens, audio tokens, and prediction tokens
- Implemented conversion methods between different response formats to preserve token usage details
- Updated UI to display detailed token usage information when available
- Added support for vertex provider/model format in pricing lookup
- Removed commented-out code related to response pooling in Vertex provider
## Type of change
- [x] Feature
- [x] Refactor
## Affected areas
- [x] Core (Go)
- [ ] Transports (HTTP)
- [x] Providers/Integrations
- [x] Plugins
- [x] UI (Next.js)
- [ ] Docs
## How to test
Test the latency tracking and enhanced token usage details with various providers:
```sh
# Core/Transports
go version
go test ./...
# UI
cd ui
pnpm i
pnpm test
pnpm build
```
Verify that latency is reported in milliseconds in the response and that detailed token usage information is displayed in the UI when available.
## Breaking changes
- [ ] Yes
- [x] No
## Related issues
N/A
## Security considerations
No security implications as this PR only enhances metrics reporting.
## Checklist
- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicableFile tree
17 files changed
+273
-84
lines changed- core
- providers
- schemas
- providers
- anthropic
- cohere
- gemini
- openai
- framework
- pricing
- plugins/logging
- ui/app/logs/views
17 files changed
+273
-84
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | | - | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 130 | + | |
142 | 131 | | |
143 | 132 | | |
144 | 133 | | |
| |||
907 | 896 | | |
908 | 897 | | |
909 | 898 | | |
910 | | - | |
| 899 | + | |
911 | 900 | | |
912 | | - | |
913 | | - | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
914 | 910 | | |
915 | 911 | | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
920 | 916 | | |
921 | 917 | | |
922 | | - | |
| 918 | + | |
923 | 919 | | |
924 | 920 | | |
925 | 921 | | |
926 | 922 | | |
927 | | - | |
928 | 923 | | |
929 | 924 | | |
930 | | - | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
931 | 941 | | |
932 | 942 | | |
933 | 943 | | |
934 | | - | |
| 944 | + | |
935 | 945 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| 249 | + | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
| |||
267 | 270 | | |
268 | 271 | | |
269 | 272 | | |
| 273 | + | |
| 274 | + | |
270 | 275 | | |
271 | 276 | | |
272 | 277 | | |
| |||
314 | 319 | | |
315 | 320 | | |
316 | 321 | | |
| 322 | + | |
317 | 323 | | |
318 | 324 | | |
319 | 325 | | |
| |||
322 | 328 | | |
323 | 329 | | |
324 | 330 | | |
325 | | - | |
326 | | - | |
327 | 331 | | |
328 | | - | |
329 | 332 | | |
330 | 333 | | |
331 | 334 | | |
| |||
336 | 339 | | |
337 | 340 | | |
338 | 341 | | |
| 342 | + | |
339 | 343 | | |
340 | 344 | | |
341 | 345 | | |
| |||
484 | 488 | | |
485 | 489 | | |
486 | 490 | | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | 491 | | |
495 | | - | |
| 492 | + | |
496 | 493 | | |
497 | 494 | | |
498 | 495 | | |
499 | 496 | | |
500 | 497 | | |
501 | 498 | | |
502 | | - | |
| 499 | + | |
503 | 500 | | |
504 | 501 | | |
505 | 502 | | |
| |||
532 | 529 | | |
533 | 530 | | |
534 | 531 | | |
| 532 | + | |
| 533 | + | |
535 | 534 | | |
536 | 535 | | |
537 | 536 | | |
| |||
554 | 553 | | |
555 | 554 | | |
556 | 555 | | |
| 556 | + | |
| 557 | + | |
557 | 558 | | |
558 | 559 | | |
559 | 560 | | |
| |||
598 | 599 | | |
599 | 600 | | |
600 | 601 | | |
601 | | - | |
| 602 | + | |
602 | 603 | | |
| 604 | + | |
603 | 605 | | |
604 | 606 | | |
605 | 607 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
545 | 545 | | |
546 | 546 | | |
547 | 547 | | |
548 | | - | |
549 | | - | |
550 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
551 | 565 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
615 | 615 | | |
616 | 616 | | |
617 | 617 | | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
618 | 676 | | |
619 | 677 | | |
620 | 678 | | |
| |||
805 | 863 | | |
806 | 864 | | |
807 | 865 | | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
| 866 | + | |
817 | 867 | | |
818 | 868 | | |
819 | 869 | | |
| |||
859 | 909 | | |
860 | 910 | | |
861 | 911 | | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
| 912 | + | |
871 | 913 | | |
872 | 914 | | |
873 | 915 | | |
| |||
976 | 1018 | | |
977 | 1019 | | |
978 | 1020 | | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
| 1021 | + | |
984 | 1022 | | |
985 | 1023 | | |
986 | 1024 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
350 | 351 | | |
351 | 352 | | |
352 | 353 | | |
353 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
354 | 358 | | |
355 | 359 | | |
356 | 360 | | |
| |||
613 | 617 | | |
614 | 618 | | |
615 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
616 | 625 | | |
617 | 626 | | |
618 | 627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
301 | 306 | | |
302 | 307 | | |
303 | 308 | | |
| |||
0 commit comments