Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

add Together AI Instrumentation

patcher9449296aa701f
diff --git a/docs/images/docs-together-banner.gif b/docs/images/docs-together-banner.gif
new file mode 100644
index 00000000..5dd909df
Binary files /dev/null and b/docs/images/docs-together-banner.gif differ
diff --git a/docs/latest/integrations/introduction.mdx b/docs/latest/integrations/introduction.mdx
index 6ad438e7..9d5b029e 100644
--- a/docs/latest/integrations/introduction.mdx
+++ b/docs/latest/integrations/introduction.mdx
@@ -400,6 +400,53 @@ Start integrating and monitoring your applications with OpenLIT in just one line
iconType="duotone"
>
</Card>
+ <Card
+ title="Together.ai"
+ href="/latest/integrations/together"
+ icon={
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 265 265">
+ <path d="M0 0 C84.48 0 168.96 0 256 0 C256 84.48 256 168.96 256 256 C171.52 256 87.04 256 0 256 C0 171.52 0 87.04 0 0 Z " fill="#F0EFEE" transform="translate(0,0)"/>
+ <path d="M0 0 C0.80308594 -0.02449219 1.60617188 -0.04898438 2.43359375 -0.07421875 C8.44207305 -0.1034334 12.34500123 1.42577962 17.5 4.375 C18.78346191 4.95597724 20.07502285 5.51948211 21.375 6.0625 C23.10296931 6.78824711 24.82367383 7.53683691 26.5 8.375 C26.5 9.365 26.5 10.355 26.5 11.375 C27.0775 11.6225 27.655 11.87 28.25 12.125 C30.82939979 13.55799988 32.56121592 15.15924676 34.5 17.375 C34.5 18.035 34.5 18.695 34.5 19.375 C35.16 19.375 35.82 19.375 36.5 19.375 C37.51303762 21.09656096 38.50994848 22.82761806 39.5 24.5625 C40.056875 25.52542969 40.61375 26.48835938 41.1875 27.48046875 C42.52216758 30.42388743 42.77915461 32.19380057 42.5 35.375 C43.16 35.375 43.82 35.375 44.5 35.375 C45.05353075 53.23149203 45.05353075 53.23149203 41.5 61.375 C40.84 61.375 40.18 61.375 39.5 61.375 C39.396875 62.303125 39.29375 63.23125 39.1875 64.1875 C38.44440392 67.63276362 37.95835021 68.10575365 35.5 70.375 C34.943125 71.7053125 34.943125 71.7053125 34.375 73.0625 C29.34852949 81.9425979 20.22582529 87.18369654 10.58911133 89.91699219 C-0.58328381 92.36638021 -13.49363499 90.89892169 -23.421875 85.2890625 C-24.81732005 84.37027938 -26.16339432 83.37745426 -27.5 82.375 C-28.14710938 82.08625 -28.79421875 81.7975 -29.4609375 81.5 C-31.88895184 80.16040588 -33.00988857 78.74086141 -34.625 76.5 C-35.12257812 75.82195312 -35.62015625 75.14390625 -36.1328125 74.4453125 C-37.5 72.375 -37.5 72.375 -38.5546875 70.1796875 C-39.36922532 68.19672002 -39.36922532 68.19672002 -41.5 67.375 C-42.1328125 65.08984375 -42.1328125 65.08984375 -42.625 62.3125 C-42.79257813 61.39339844 -42.96015625 60.47429687 -43.1328125 59.52734375 C-43.25398437 58.81707031 -43.37515625 58.10679687 -43.5 57.375 C-44.16 57.375 -44.82 57.375 -45.5 57.375 C-45.61798604 53.60443831 -45.68783864 49.83436235 -45.75 46.0625 C-45.78351563 45.00998047 -45.81703125 43.95746094 -45.8515625 42.87304688 C-45.95887341 34.15403571 -44.38603655 26.70405483 -39.5 19.375 C-38.84 19.375 -38.18 19.375 -37.5 19.375 C-36.84 18.055 -36.18 16.735 -35.5 15.375 C-34.84 15.375 -34.18 15.375 -33.5 15.375 C-33.12875 14.446875 -33.12875 14.446875 -32.75 13.5 C-31.27753937 10.99681694 -30.08971163 10.54454719 -27.5 9.375 C-27.17 8.715 -26.84 8.055 -26.5 7.375 C-24.43359375 6.5234375 -24.43359375 6.5234375 -21.9375 5.75 C-21.11121094 5.48960937 -20.28492188 5.22921875 -19.43359375 4.9609375 C-18.79550781 4.76757812 -18.15742188 4.57421875 -17.5 4.375 C-17.5 3.715 -17.5 3.055 -17.5 2.375 C-11.55501169 0.67058821 -6.17380667 0.0099098 0 0 Z " fill="#D3D1D2" transform="translate(181.5,136.625)"/>
+ <path d="M0 0 C1.27133789 0.00966797 1.27133789 0.00966797 2.56835938 0.01953125 C3.8899707 0.04466797 3.8899707 0.04466797 5.23828125 0.0703125 C6.57729492 0.08384766 6.57729492 0.08384766 7.94335938 0.09765625 C10.14610439 0.12121502 12.34830713 0.15410921 14.55078125 0.1953125 C14.55078125 0.8553125 14.55078125 1.5153125 14.55078125 2.1953125 C15.16824219 2.28167969 15.78570312 2.36804687 16.421875 2.45703125 C28.18454464 4.40852439 35.71544969 9.9602797 42.92578125 19.2578125 C44.62226769 22.32453799 45.22038892 24.72619302 45.55078125 28.1953125 C46.21078125 28.1953125 46.87078125 28.1953125 47.55078125 28.1953125 C51.33295315 37.96592325 52.2878974 48.27597817 48.55078125 58.1953125 C47.99390625 59.8659375 47.99390625 59.8659375 47.42578125 61.5703125 C47.13703125 62.4365625 46.84828125 63.3028125 46.55078125 64.1953125 C45.89078125 64.1953125 45.23078125 64.1953125 44.55078125 64.1953125 C44.28265625 64.9171875 44.01453125 65.6390625 43.73828125 66.3828125 C40.65684643 73.68094761 35.23974051 81.90707439 27.80078125 85.2578125 C24.55078125 86.1953125 24.55078125 86.1953125 20.55078125 86.1953125 C20.55078125 87.1853125 20.55078125 88.1753125 20.55078125 89.1953125 C17.12504188 89.97059729 13.9783888 90.31450028 10.46875 90.29296875 C9.53740234 90.28974609 8.60605469 90.28652344 7.64648438 90.28320312 C6.20692383 90.27063477 6.20692383 90.27063477 4.73828125 90.2578125 C3.75923828 90.25330078 2.78019531 90.24878906 1.77148438 90.24414062 C-0.63547986 90.23239934 -3.04231732 90.21597669 -5.44921875 90.1953125 C-5.44921875 89.5353125 -5.44921875 88.8753125 -5.44921875 88.1953125 C-6.45984375 88.0921875 -7.47046875 87.9890625 -8.51171875 87.8828125 C-12.66140083 87.15826483 -15.66278138 85.97261984 -19.44921875 84.1953125 C-19.44921875 83.5353125 -19.44921875 82.8753125 -19.44921875 82.1953125 C-21.09921875 81.5353125 -22.74921875 80.8753125 -24.44921875 80.1953125 C-24.44921875 79.5353125 -24.44921875 78.8753125 -24.44921875 78.1953125 C-25.03574219 77.95941406 -25.62226563 77.72351563 -26.2265625 77.48046875 C-32.4165701 73.90136067 -35.94521231 66.01872628 -37.94140625 59.3984375 C-40.95100249 46.34141996 -40.88696249 34.12813037 -34.44921875 22.1953125 C-33.78921875 22.1953125 -33.12921875 22.1953125 -32.44921875 22.1953125 C-32.22234375 21.3290625 -31.99546875 20.4628125 -31.76171875 19.5703125 C-30.21983153 15.60545965 -28.45492045 13.2010142 -25.44921875 10.1953125 C-23.46907443 9.47179823 -21.4710056 8.79265861 -19.44921875 8.1953125 C-19.11921875 7.2053125 -18.78921875 6.2153125 -18.44921875 5.1953125 C-16.05078125 4.31640625 -16.05078125 4.31640625 -13.07421875 3.6328125 C-8.32537866 2.52391449 -4.86249975 -0.06526845 0 0 Z " fill="#D3D1D2" transform="translate(175.44921875,31.8046875)"/>
+ <path d="M0 0 C2.89608593 -0.05413245 5.79115195 -0.09373641 8.6875 -0.125 C9.91243164 -0.15013672 9.91243164 -0.15013672 11.16210938 -0.17578125 C15.6126015 -0.21181762 18.9306642 -0.00131269 23 2 C24.19625 2.33 25.3925 2.66 26.625 3 C30 4 30 4 33 6 C33 6.66 33 7.32 33 8 C33.70125 8.226875 34.4025 8.45375 35.125 8.6875 C39.24321571 10.567555 43.20709928 12.90447666 44.875 17.3125 C44.91625 17.869375 44.9575 18.42625 45 19 C45.66 19 46.32 19 47 19 C47 19.99 47 20.98 47 22 C47.66 22 48.32 22 49 22 C49.27714844 22.69867188 49.55429688 23.39734375 49.83984375 24.1171875 C50.38318359 25.48230469 50.38318359 25.48230469 50.9375 26.875 C51.47697266 28.23238281 51.47697266 28.23238281 52.02734375 29.6171875 C52.94901262 31.96137667 52.94901262 31.96137667 54 34 C54.67131528 48.23812881 54.47821274 62.30910411 44.6875 73.6875 C43.3571875 74.8321875 43.3571875 74.8321875 42 76 C41.36707031 76.59941406 40.73414062 77.19882813 40.08203125 77.81640625 C36.40002128 81.23590895 34.11256835 83.32542501 29 84 C29 84.66 29 85.32 29 86 C26.03 86.495 26.03 86.495 23 87 C23 87.66 23 88.32 23 89 C12.66675564 92.39017203 -1.52226212 90.62881471 -11.25 86.1875 C-14.78720112 84.29632316 -17.30260033 81.98901044 -20 79 C-20.845625 78.154375 -21.69125 77.30875 -22.5625 76.4375 C-23.366875 75.633125 -24.17125 74.82875 -25 74 C-26.051875 73.0409375 -26.051875 73.0409375 -27.125 72.0625 C-33.78588434 64.73552723 -35.50706727 54.5381919 -35.375 45 C-35.38660156 44.16210938 -35.39820312 43.32421875 -35.41015625 42.4609375 C-35.36999238 33.81231682 -33.12683219 26.9911348 -28 20 C-27.34 18.989375 -26.68 17.97875 -26 16.9375 C-20.72668356 9.19231648 -14.7630537 4.58766809 -5.4375 2.3984375 C-3.25 2.125 -3.25 2.125 0 2 C0 1.34 0 0.68 0 0 Z " fill="#D3D1D2" transform="translate(66,137)"/>
+ <path d="M0 0 C9.33569445 7.70132884 15.94954174 17.65588937 18.4375 29.6875 C19.02128492 36.57433772 18.75879805 43.15051125 16.4375 49.6875 C16.07011719 50.72777344 16.07011719 50.72777344 15.6953125 51.7890625 C11.12106309 63.24492606 3.41864699 72.84834361 -7.75390625 78.22265625 C-16.18624552 81.60501357 -23.55399198 82.32126438 -32.5625 81.6875 C-33.29984375 81.6771875 -34.0371875 81.666875 -34.796875 81.65625 C-45.4077218 81.13009231 -54.11847646 74.07774132 -61.07421875 66.69921875 C-71.21863701 54.42080984 -72.54850619 43.03632974 -71.5625 27.6875 C-71.01843421 24.35394433 -70.10609436 21.68113754 -68.5625 18.6875 C-68.1603125 17.883125 -67.758125 17.07875 -67.34375 16.25 C-61.73829112 6.03560827 -53.51791065 -2.41874486 -42.265625 -6.0546875 C-28.2726642 -9.39287749 -11.82204027 -8.59521655 0 0 Z " fill="#326EF3" transform="translate(102.5625,40.3125)"/>
+ <path d="M0 0 C0 0.66 0 1.32 0 2 C-0.99 2 -1.98 2 -3 2 C-3 2.99 -3 3.98 -3 5 C-4.423125 5.3403125 -4.423125 5.3403125 -5.875 5.6875 C-9.19323388 6.69083714 -9.19323388 6.69083714 -10.375 9.625 C-10.684375 10.800625 -10.684375 10.800625 -11 12 C-12.32 12 -13.64 12 -15 12 C-15.2475 12.70125 -15.495 13.4025 -15.75 14.125 C-17 17 -17 17 -19 19.6875 C-21.28014135 23.46398411 -21.91661457 26.61883314 -22.60546875 30.92578125 C-23 33 -23 33 -24 34 C-24.54808732 42.75885692 -24.93817769 51.92508105 -21 60 C-19.70529025 61.37086915 -18.37849103 62.71340837 -17 64 C-16.25 67.25 -16.25 67.25 -16 70 C-18.91149059 67.25903055 -21.11619069 64.54345907 -23.1875 61.125 C-23.69667969 60.30257812 -24.20585938 59.48015625 -24.73046875 58.6328125 C-28.76329975 50.26934145 -28.5732897 35.84086686 -25.875 27 C-25.03125 25 -25.03125 25 -24 23 C-23.5978125 22.195625 -23.195625 21.39125 -22.78125 20.5625 C-18.66056163 13.05369007 -9.73706473 0 0 0 Z " fill="#4F79D6" transform="translate(58,36)"/>
+ <path d="M0 0 C0.66 0 1.32 0 2 0 C2.07347656 1.82724609 2.07347656 1.82724609 2.1484375 3.69140625 C2.22352273 5.31512437 2.29906802 6.93882126 2.375 8.5625 C2.42140625 9.76229492 2.42140625 9.76229492 2.46875 10.98632812 C3.13171604 24.52188474 9.17716117 34.89899743 18.88671875 44.16015625 C20.86136029 45.87929888 22.88064573 47.46430537 25 49 C24 50 24 50 21.4375 50.0625 C20.633125 50.041875 19.82875 50.02125 19 50 C19 49.01 19 48.02 19 47 C17.68 46.34 16.36 45.68 15 45 C15 44.34 15 43.68 15 43 C14.01 43 13.02 43 12 43 C9.14948857 40.83361132 8.16757737 38.32310483 7 35 C6.01 35.495 6.01 35.495 5 36 C4 28.25 4 28.25 4 26 C3.34 26 2.68 26 2 26 C-1.0854731 18.0291945 -1.59439347 10.50439895 -1 2 C-0.67 1.34 -0.34 0.68 0 0 Z " fill="#CCDDF7" transform="translate(29,68)"/>
+ <path d="M0 0 C0.81640625 2.171875 0.81640625 2.171875 1 4 C0.34 3.731875 -0.32 3.46375 -1 3.1875 C-1.99 2.795625 -2.98 2.40375 -4 2 C-4.92425781 1.62101562 -4.92425781 1.62101562 -5.8671875 1.234375 C-18.38894577 -3.73535007 -31.42795421 -2.82046941 -44.234375 0.5390625 C-45.14703125 0.69117188 -46.0596875 0.84328125 -47 1 C-47.66 0.34 -48.32 -0.32 -49 -1 C-47.02 -1.33 -45.04 -1.66 -43 -2 C-43 -2.66 -43 -3.32 -43 -4 C-30.14619199 -6.68981917 -11.23503007 -7.95030061 0 0 Z " fill="#E1EEFD" transform="translate(101,36)"/>
+ <path d="M0 0 C6.79347257 2.51610095 9.95212445 9.27149213 12.86328125 15.43359375 C17.57868594 26.07971362 18.46617771 35.73492243 15 47 C14.67 47 14.34 47 14 47 C14.02618408 46.42668945 14.05236816 45.85337891 14.0793457 45.26269531 C14.91507102 28.93040111 14.91507102 28.93040111 9 14 C8.34 13.67 7.68 13.34 7 13 C6.67 12.01 6.34 11.02 6 10 C3.98491642 9.26676204 3.98491642 9.26676204 2 9 C2 7.35 2 5.7 2 4 C1.34 4 0.68 4 0 4 C0 2.68 0 1.36 0 0 Z " fill="#5882DC" transform="translate(104,43)"/>
+ <path d="M0 0 C2 1 4 2 6 3 C6 3.66 6 4.32 6 5 C7.32 5 8.64 5 10 5 C10.33 5.66 10.66 6.32 11 7 C11.99 7.33 12.98 7.66 14 8 C14 8.66 14 9.32 14 10 C14.56589844 10.13277344 15.13179687 10.26554687 15.71484375 10.40234375 C16.44832031 10.57894531 17.18179688 10.75554687 17.9375 10.9375 C18.66839844 11.11152344 19.39929688 11.28554687 20.15234375 11.46484375 C22 12 22 12 23 13 C24.85369611 13.08737645 26.71067541 13.10698153 28.56640625 13.09765625 C29.69111328 13.09443359 30.81582031 13.09121094 31.97460938 13.08789062 C33.15861328 13.07951172 34.34261719 13.07113281 35.5625 13.0625 C36.75037109 13.05798828 37.93824219 13.05347656 39.16210938 13.04882812 C42.10812226 13.03699675 45.05403681 13.02051287 48 13 C45.08161179 15.91838821 42.90915606 15.96193189 38.828125 16.1328125 C35.21710114 16.12492817 31.6101082 16.08149228 28 16 C27.24976562 15.99484375 26.49953125 15.9896875 25.7265625 15.984375 C16.07957045 15.41451049 7.70724917 9.443711 1.328125 2.63671875 C0 1 0 1 0 0 Z " fill="#577CD4" transform="translate(42,106)"/>
+ <path d="M0 0 C1 3 1 3 -0.4375 6.5625 C-5.40894872 15.8391208 -12.28884909 23.71899289 -21.8125 28.375 C-24 29 -24 29 -27 29 C-27 28.34 -27 27.68 -27 27 C-26.36191406 26.81824219 -25.72382812 26.63648437 -25.06640625 26.44921875 C-24.24011719 26.19785156 -23.41382812 25.94648437 -22.5625 25.6875 C-21.73878906 25.44386719 -20.91507812 25.20023438 -20.06640625 24.94921875 C-19.38449219 24.63597656 -18.70257813 24.32273437 -18 24 C-17.67 23.01 -17.34 22.02 -17 21 C-16.01 21 -15.02 21 -14 21 C-14 20.34 -14 19.68 -14 19 C-12.125 16.875 -12.125 16.875 -10 15 C-9.34 15 -8.68 15 -8 15 C-8 14.34 -8 13.68 -8 13 C-7.34 13 -6.68 13 -6 13 C-6 11.68 -6 10.36 -6 9 C-5.34 9 -4.68 9 -4 9 C-4.33 8.01 -4.66 7.02 -5 6 C-2.66666667 1.33333333 -2.66666667 1.33333333 0 0 Z " fill="#4772D5" transform="translate(117,90)"/>
+ <path d="M0 0 C1.06262319 0.91367809 2.11384574 1.84216874 3.125 2.8125 C2.135 3.1425 1.145 3.4725 0.125 3.8125 C0.125 3.1525 0.125 2.4925 0.125 1.8125 C-1.22847689 1.35213371 -2.582827 0.89433463 -3.9375 0.4375 C-4.69160156 0.18226562 -5.44570312 -0.07296875 -6.22265625 -0.3359375 C-7.53556641 -0.75746094 -7.53556641 -0.75746094 -8.875 -1.1875 C-9.844375 -1.5484375 -10.81375 -1.909375 -11.8125 -2.28125 C-17.63443922 -3.92574089 -23.82279928 -3.39416346 -29.8125 -3.3125 C-31.06869141 -3.30347656 -32.32488281 -3.29445312 -33.61914062 -3.28515625 C-36.70462522 -3.26169249 -39.78971205 -3.22886201 -42.875 -3.1875 C-31.08287452 -9.41217503 -10.65417342 -7.93435802 0 0 Z " fill="#456DD6" transform="translate(100.875,39.1875)"/>
+ <path d="M0 0 C0.33 0 0.66 0 1 0 C1.16575651 4.30966915 1.23241672 7.27930547 -1 11 C-1.268125 11.78375 -1.53625 12.5675 -1.8125 13.375 C-3.40731698 16.90038491 -5.32285823 19.19226594 -8 22 C-8.99 22 -9.98 22 -11 22 C-11 22.99 -11 23.98 -11 25 C-11.99 25.33 -12.98 25.66 -14 26 C-14.66 25.34 -15.32 24.68 -16 24 C-15.319375 23.360625 -14.63875 22.72125 -13.9375 22.0625 C-7.40471405 15.45547784 -2.96887644 8.83286842 0 0 Z " fill="#DDE9F7" transform="translate(119,88)"/>
+ <path d="M0 0 C0 3 0 3 -2 6 C-3.875 7.0625 -3.875 7.0625 -6 8 C-6.5775 8.350625 -7.155 8.70125 -7.75 9.0625 C-16.50544296 12.71060123 -27.11511225 11.35249983 -36 9 C-32.44492347 7.85543877 -29.3315482 8.06340032 -25.625 8.25 C-16.42864286 8.33657658 -7.20554025 5.99290055 0 0 Z " fill="#D4E3FB" transform="translate(102,113)"/>
+ <path d="M0 0 C0 0.66 0 1.32 0 2 C-0.99 2 -1.98 2 -3 2 C-3 2.99 -3 3.98 -3 5 C-4.423125 5.3403125 -4.423125 5.3403125 -5.875 5.6875 C-9.19323388 6.69083714 -9.19323388 6.69083714 -10.375 9.625 C-10.58125 10.40875 -10.7875 11.1925 -11 12 C-12.32 12 -13.64 12 -15 12 C-15.226875 12.680625 -15.45375 13.36125 -15.6875 14.0625 C-17.06407823 17.14341319 -18.75993706 19.52339142 -20.7578125 22.21875 C-22.47015315 24.67418187 -23.74369794 27.28903241 -25 30 C-26 27 -26 27 -25.1015625 24.65234375 C-20.64591099 16.46007444 -10.90635823 0 0 0 Z " fill="#4970D6" transform="translate(58,36)"/>
+ <path d="M0 0 C0.78640869 0.00523682 1.57281738 0.01047363 2.38305664 0.01586914 C3.5868396 0.01889038 3.5868396 0.01889038 4.81494141 0.02197266 C13.22331969 0.16118146 21.14118855 1.66441311 29.13305664 4.32836914 C29.82055664 6.39086914 29.82055664 6.39086914 30.13305664 8.32836914 C29.47305664 8.06024414 28.81305664 7.79211914 28.13305664 7.51586914 C27.14305664 7.12399414 26.15305664 6.73211914 25.13305664 6.32836914 C24.20879883 5.94938477 24.20879883 5.94938477 23.26586914 5.56274414 C22.60329102 5.29977539 21.94071289 5.03680664 21.25805664 4.76586914 C20.33379883 4.39268555 20.33379883 4.39268555 19.39086914 4.01196289 C13.24974993 2.15262749 7.04239188 2.19938336 0.69555664 2.26586914 C-0.54484375 2.27263672 -0.54484375 2.27263672 -1.81030273 2.27954102 C-3.82921482 2.29121103 -5.8480891 2.30914196 -7.86694336 2.32836914 C-5.29381172 -0.2447625 -3.51296292 0.04353162 0 0 Z " fill="#B4CBF3" transform="translate(71.866943359375,31.671630859375)"/>
+ <path d="M0 0 C0.66 0 1.32 0 2 0 C2 6.93 2 13.86 2 21 C-0.70914728 18.29085272 -0.9792985 16.51205773 -1.1328125 12.71484375 C-1.12894531 10.84505859 -1.12894531 10.84505859 -1.125 8.9375 C-1.12757812 7.68839844 -1.13015625 6.43929687 -1.1328125 5.15234375 C-1 2 -1 2 0 0 Z " fill="#DAECFC" transform="translate(29,68)"/>
+ <path d="M0 0 C1.32 0.33 2.64 0.66 4 1 C4.33 3.64 4.66 6.28 5 9 C5.33 9 5.66 9 6 9 C6 16.26 6 23.52 6 31 C5.34 31 4.68 31 4 31 C4.04640625 29.85144531 4.0928125 28.70289062 4.140625 27.51953125 C4.41748524 17.49848837 3.7305516 9.42630449 0 0 Z " fill="#E2EFFE" transform="translate(116,57)"/>
+ <path d="M0 0 C2.68972524 0.4746574 5.16953539 1.05972269 7.75 1.96875 C11.13238088 3.04200547 14.36488296 3.62355471 17.875 4.125 C19.02742188 4.29257813 20.17984375 4.46015625 21.3671875 4.6328125 C22.23601562 4.75398438 23.10484375 4.87515625 24 5 C24 5.33 24 5.66 24 6 C14.95702695 6.26727999 8.34588654 5.54067914 0 2 C0 1.34 0 0.68 0 0 Z " fill="#E6EEFC" transform="translate(57,119)"/>
+ <path d="M0 0 C0.99 0.33 1.98 0.66 3 1 C2.54109375 1.43570313 2.0821875 1.87140625 1.609375 2.3203125 C-2.16354586 5.9822651 -5.2623152 9.51019692 -8 14 C-8.84819206 11.63234732 -9.23923525 10.50796525 -8.14453125 8.18359375 C-3.20593412 1.70983153 -3.20593412 1.70983153 0 0 Z " fill="#D4E8FD" transform="translate(45,41)"/>
+ <path d="M0 0 C3.93204293 1.96602147 5.40300225 7.08060763 7 11 C7.61188888 13.7316468 7.84403749 16.19267479 8 19 C3.3239005 14.3239005 0.52847638 6.51787536 0 0 Z " fill="#5477D5" transform="translate(111,50)"/>
+ <path d="M0 0 C2.64362871 2.64362871 3.10163281 5.27252067 4.12109375 8.80859375 C5.07336327 11.18291908 6.19749668 12.23646973 8 14 C8.6875 17.1875 8.6875 17.1875 9 20 C3.03822054 14.67698263 0.65081707 9.51907779 0.078125 1.72265625 C0.05234375 1.15417969 0.0265625 0.58570312 0 0 Z " fill="#466ED5" transform="translate(33,86)"/>
+ <path d="M0 0 C2 1 4 2 6 3 C6 3.66 6 4.32 6 5 C7.32 5 8.64 5 10 5 C10.33 5.66 10.66 6.32 11 7 C11.99 7.33 12.98 7.66 14 8 C14 8.66 14 9.32 14 10 C9.12368483 10 6.94567677 8.30885942 3.625 5 C0 1.19850187 0 1.19850187 0 0 Z " fill="#4972D2" transform="translate(42,106)"/>
+ <path d="M0 0 C4.45165834 1.39909262 6.85625212 3.60135365 10 7 C10.66 7.66 11.32 8.32 12 9 C12.125 11.625 12.125 11.625 12 14 C9 12 9 12 7.625 9.6875 C5.78138562 6.63844545 3.54417936 4.47722727 1 2 C0.67 1.34 0.34 0.68 0 0 Z " fill="#D1E1F9" transform="translate(104,42)"/>
+ <path d="M0 0 C2.52363093 2.52363093 2.2605272 4.12326296 2.2734375 7.5703125 C2.26570313 8.28960937 2.25796875 9.00890625 2.25 9.75 C2.25773437 10.45382813 2.26546875 11.15765625 2.2734375 11.8828125 C2.257025 16.29777476 1.64807517 19.84057219 0 24 C-1.14669461 20.55991617 -0.69712956 19.4856478 0 16 C0.068089 13.21924515 0.09478336 10.46635261 0.0625 7.6875 C0.05798828 6.94693359 0.05347656 6.20636719 0.04882812 5.44335938 C0.03712175 3.62887101 0.01918898 1.81442466 0 0 Z " fill="#3566DF" transform="translate(117,67)"/>
+ <path d="M0 0 C6.55327899 0.27305329 10.06930548 2.81211141 15 7 C14.01 7.33 13.02 7.66 12 8 C12 7.34 12 6.68 12 6 C11.38511719 5.79503906 10.77023438 5.59007812 10.13671875 5.37890625 C6.7578125 4.25260417 3.37890625 3.12630208 0 2 C0 1.34 0 0.68 0 0 Z " fill="#587DD7" transform="translate(89,35)"/>
+ <path d="M0 0 C3.99455527 0.61454696 6.74466336 2.70646737 10 5 C9.67 5.66 9.34 6.32 9 7 C7.35 7 5.7 7 4 7 C4 6.01 4 5.02 4 4 C2.68 3.34 1.36 2.68 0 2 C0 1.34 0 0.68 0 0 Z " fill="#DFE6FB" transform="translate(44,111)"/>
+ <path d="M0 0 C1.32 0 2.64 0 4 0 C3.29666462 2.97722547 2.41751463 5.85256543 1.4375 8.75 C1.03337891 9.94882813 1.03337891 9.94882813 0.62109375 11.171875 C0.41613281 11.77515625 0.21117187 12.3784375 0 13 C-0.33 13 -0.66 13 -1 13 C-1.07654536 8.48382401 -1.10228696 4.40914783 0 0 Z " fill="#D7E7FA" transform="translate(32,55)"/>
+ <path d="M0 0 C1 3 1 3 -0.43359375 5.91796875 C-1.09488281 6.99691406 -1.75617187 8.07585938 -2.4375 9.1875 C-3.09621094 10.27417969 -3.75492188 11.36085938 -4.43359375 12.48046875 C-5.20896484 13.72763672 -5.20896484 13.72763672 -6 15 C-7 12 -7 12 -5.8203125 9.3359375 C-4.98113281 7.87027344 -4.98113281 7.87027344 -4.125 6.375 C-3.57070313 5.39273438 -3.01640625 4.41046875 -2.4453125 3.3984375 C-1 1 -1 1 0 0 Z " fill="#5B82D5" transform="translate(39,51)"/>
+ <path d="M0 0 C0 3 0 3 -2 6 C-4.3828125 6.51171875 -4.3828125 6.51171875 -7.125 6.6875 C-8.03507812 6.75324219 -8.94515625 6.81898437 -9.8828125 6.88671875 C-10.93082031 6.94279297 -10.93082031 6.94279297 -12 7 C-9.08273524 5.05515683 -6.13164127 3.56582063 -3 2 C-2.01 1.34 -1.02 0.68 0 0 Z " fill="#CBDCFA" transform="translate(102,113)"/>
+ <path d="M0 0 C0.66 0 1.32 0 2 0 C0.5682479 5.01113235 -1.98445693 6.94469549 -6 10 C-5.49259538 5.60249328 -2.91706686 3.13051078 0 0 Z " fill="#DCDAD8" transform="translate(46,146)"/>
+ <path d="M0 0 C0 0.66 0 1.32 0 2 C-0.99 2 -1.98 2 -3 2 C-3 2.99 -3 3.98 -3 5 C-5.64 5.66 -8.28 6.32 -11 7 C-4.48275862 0 -4.48275862 0 0 0 Z " fill="#6086DA" transform="translate(58,36)"/>
+ <path d="M0 0 C1 3 1 3 0.25 5.125 C-1 7 -1 7 -4 8 C-4.66 7.34 -5.32 6.68 -6 6 C-4 4 -2 2 0 0 Z " fill="#C9DDF9" transform="translate(109,106)"/>
+ <path d="M0 0 C1.32 0.33 2.64 0.66 4 1 C4 4.3 4 7.6 4 11 C1.54176828 7.31265242 0.98757384 4.30300029 0 0 Z " fill="#C8DCFA" transform="translate(116,57)"/>
+ <path d="M0 0 C2.0625 0.4375 2.0625 0.4375 4 1 C2.1875 3 2.1875 3 0 5 C-0.99 5 -1.98 5 -3 5 C-1.125 1.125 -1.125 1.125 0 0 Z " fill="#3B6AED" transform="translate(50,41)"/>
+ <path d="M0 0 C0.33 1.32 0.66 2.64 1 4 C-0.9375 6.25 -0.9375 6.25 -3 8 C-3.66 7.67 -4.32 7.34 -5 7 C-3.35 4.69 -1.7 2.38 0 0 Z " fill="#C1DAF8" transform="translate(115,98)"/>
+ <path d="M0 0 C1 3 1 3 -0.4375 6.1875 C-1.2109375 7.5796875 -1.2109375 7.5796875 -2 9 C-3.10102197 5.69693408 -2.95067299 4.28414305 -2 1 C-1.34 0.67 -0.68 0.34 0 0 Z " fill="#5372D3" transform="translate(117,90)"/>
+ </svg>
+ }
+ iconType="duotone"
+ >
+ </Card>
<Card
title="Assembly AI"
href="/latest/integrations/assemblyai"
diff --git a/docs/latest/integrations/together.mdx b/docs/latest/integrations/together.mdx
new file mode 100644
index 00000000..85e91ea8
--- /dev/null
+++ b/docs/latest/integrations/together.mdx
@@ -0,0 +1,103 @@
+---
+title: 'Monitor Together using OpenTelemetry'
+sidebarTitle: 'Together'
+---
+
+<Frame>
+ <img src="/images/docs-together-banner.gif" />
+</Frame>
+
+OpenLIT uses OpenTelemetry Auto-Instrumentation to help you monitor LLM applications built using Together models. This includes tracking performance, token usage, costs, and how users interact with the application.
+
+Auto-instrumentation means you don't have to set up monitoring manually for different LLMs, frameworks, or databases. By simply adding OpenLIT in your application, all the necessary monitoring configurations are automatically set up.
+
+The integration is compatible with
+- Together Python SDK client `>=1.3.5`
+
+## Get Started
+
+<Steps>
+ <Step title="Install OpenLIT">
+ Open your command line or terminal and run:
+ <Tabs>
+ <Tab title="Python">
+ ```shell
+ pip install openlit
+ ```
+ </Tab>
+ <Tab title="Typescript">
+ ```shell
+ npm install openlit
+ ```
+ </Tab>
+ </Tabs>
+
+ </Step>
+ <Step title="Initialize OpenLIT in your Application">
+ You can set up OpenLIT in your application using either function arguments directly in your code or by using environment variables.
+ <Tabs>
+ <Tab title="Setup using function arguments">
+ Add the following two lines to your application code:
+ <Tabs>
+ <Tab title="Python">
+ ```python
+ import openlit
+
+ openlit.init(otlp_endpoint="YOUR_OTEL_ENDPOINT")
+ ```
+
+ </Tab>
+ </Tabs>
+
+
+ Replace:
+ 1. `YOUR_OTEL_ENDPOINT` with the URL of your OpenTelemetry backend, such as `http://127.0.0.1:4318` if you are using OpenLIT and a local OTel Collector.
+
+ </Tab>
+ <Tab title="Setup using Environment Variables">
+
+ Add the following two lines to your application code:
+
+ <Tabs>
+ <Tab title="Python">
+ ```python
+ import openlit
+
+ openlit.init()
+ ```
+
+ </Tab>
+ <Tab title="Typescript">
+ ```typescript
+ import openlit from "openlit"
+
+ openlit.init()
+ ```
+ </Tab>
+ </Tabs>
+
+ Then, configure the your OTLP endpoint using environment variable:
+ ```shell
+ export OTEL_EXPORTER_OTLP_ENDPOINT = "YOUR_OTEL_ENDPOINT"
+ ```
+
+ Replace:
+ 1. `YOUR_OTEL_ENDPOINT` with the URL of your OpenTelemetry backend, such as `http://127.0.0.1:4318` if you are using OpenLIT and a local OTel Collector.
+ </Tab>
+ </Tabs>
+ To send metrics and traces to other Observability tools, refer to the [Connections Guide](/latest/connections/intro).
+
+ For more advanced configurations and application use cases, visit the [OpenLIT Python repository](https://github.com/openlit/openlit/tree/main/sdk/python) or [OpenLIT Typescript repository](https://github.com/openlit/openlit/tree/main/sdk/typescript).
+ </Step>
+</Steps>
+
+---
+
+<CardGroup cols={2}>
+<Card title="Connections" href="/latest/connections/intro" icon='link'>
+Connect to your existing Observablity Stack
+</Card>
+<Card title="SDK configuration" href="/latest/sdk-configuration" icon='file-code'>
+Documentation of the configuration options for the OpenLIT SDK.
+</Card>
+</CardGroup>
\ No newline at end of file
diff --git a/docs/mint.json b/docs/mint.json
index e9941690..52ab0812 100644
--- a/docs/mint.json
+++ b/docs/mint.json
@@ -103,6 +103,7 @@
"latest/integrations/xai",
"latest/integrations/elevenlabs",
"latest/integrations/ai21",
+ "latest/integrations/together",
"latest/integrations/assemblyai",
"latest/integrations/reka",
"latest/integrations/krutrim",
diff --git a/sdk/python/README.md b/sdk/python/README.md
index a1b54197..eea329f4 100644
--- a/sdk/python/README.md
+++ b/sdk/python/README.md
@@ -58,6 +58,7 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
| [✅ xAI](https://docs.openlit.io/latest/integrations/xai) | | | |
| [✅ Prem AI](https://docs.openlit.io/latest/integrations/premai) | | | |
| [✅ Assembly AI](https://docs.openlit.io/latest/integrations/assemblyai) | | | |
+| [✅ Together](https://docs.openlit.io/latest/integrations/together) | | | |
## Supported Destinations
- [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index ef70a9f2..70908385 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.32.12"
+version = "1.33.0"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
diff --git a/sdk/python/src/openlit/__init__.py b/sdk/python/src/openlit/__init__.py
index 9c164a3c..a56d4fad 100644
--- a/sdk/python/src/openlit/__init__.py
+++ b/sdk/python/src/openlit/__init__.py
@@ -52,6 +52,7 @@ from openlit.instrumentation.milvus import MilvusInstrumentor
from openlit.instrumentation.astra import AstraInstrumentor
from openlit.instrumentation.transformers import TransformersInstrumentor
from openlit.instrumentation.litellm import LiteLLMInstrumentor
+from openlit.instrumentation.together import TogetherInstrumentor
from openlit.instrumentation.crewai import CrewAIInstrumentor
from openlit.instrumentation.ag2 import AG2Instrumentor
from openlit.instrumentation.multion import MultiOnInstrumentor
@@ -188,7 +189,6 @@ def instrument_if_available(
metrics_dict=config.metrics_dict,
disable_metrics=config.disable_metrics,
)
- logger.info("Instrumented %s", instrumentor_name)
else:
# pylint: disable=line-too-long
logger.info("Library for %s (%s) not found. Skipping instrumentation", instrumentor_name, module_name)
@@ -264,6 +264,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
"crawl4ai": "crawl4ai",
"firecrawl": "firecrawl",
"letta": "letta",
+ "together": "together",
}
invalid_instrumentors = [
@@ -360,6 +361,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
"crawl4ai": Crawl4AIInstrumentor(),
"firecrawl": FireCrawlInstrumentor(),
"letta": LettaInstrumentor(),
+ "together": TogetherInstrumentor(),
}
# Initialize and instrument only the enabled instrumentors
diff --git a/sdk/python/src/openlit/instrumentation/together/__init__.py b/sdk/python/src/openlit/instrumentation/together/__init__.py
new file mode 100644
index 00000000..41fb11ed
--- /dev/null
+++ b/sdk/python/src/openlit/instrumentation/together/__init__.py
@@ -0,0 +1,70 @@
+# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
+"""Initializer of Auto Instrumentation of Together AI Functions"""
+
+from typing import Collection
+import importlib.metadata
+from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
+from wrapt import wrap_function_wrapper
+
+from openlit.instrumentation.together.together import (
+ completion, image_generate
+)
+from openlit.instrumentation.together.async_together import (
+ async_completion, async_image_generate
+)
+
+_instruments = ("together >= 1.3.5",)
+
+class TogetherInstrumentor(BaseInstrumentor):
+ """
+ An instrumentor for Together's client library.
+ """
+
+ def instrumentation_dependencies(self) -> Collection[str]:
+ return _instruments
+
+ def _instrument(self, **kwargs):
+ application_name = kwargs.get("application_name", "default_application")
+ environment = kwargs.get("environment", "default_environment")
+ tracer = kwargs.get("tracer")
+ metrics = kwargs.get("metrics_dict")
+ pricing_info = kwargs.get("pricing_info", {})
+ trace_content = kwargs.get("trace_content", False)
+ disable_metrics = kwargs.get("disable_metrics")
+ version = importlib.metadata.version("together")
+
+ # Chat completions
+ wrap_function_wrapper(
+ "together.resources.chat.completions",
+ "ChatCompletions.create",
+ completion("together.chat.completions", version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
+ )
+
+ # Image generate
+ wrap_function_wrapper(
+ "together.resources.images",
+ "Images.generate",
+ image_generate("together.image.generate", version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
+ )
+
+ # Chat completions
+ wrap_function_wrapper(
+ "together.resources.chat.completions",
+ "AsyncChatCompletions.create",
+ async_completion("together.chat.completions", version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
+ )
+
+ # Image generate
+ wrap_function_wrapper(
+ "together.resources.images",
+ "AsyncImages.generate",
+ async_image_generate("together.image.generate", version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
+ )
+
+ def _uninstrument(self, **kwargs):
+ # Proper uninstrumentation logic to revert patched methods
+ pass
diff --git a/sdk/python/src/openlit/instrumentation/together/async_together.py b/sdk/python/src/openlit/instrumentation/together/async_together.py
new file mode 100644
index 00000000..0648b765
--- /dev/null
+++ b/sdk/python/src/openlit/instrumentation/together/async_together.py
@@ -0,0 +1,528 @@
+# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, too-many-branches
+"""
+Module for monitoring Together calls.
+"""
+
+import logging
+from opentelemetry.trace import SpanKind, Status, StatusCode
+from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from openlit.__helpers import (
+ get_chat_model_cost,
+ general_tokens,
+ get_image_model_cost,
+ handle_exception,
+ response_as_dict,
+)
+from openlit.semcov import SemanticConvetion
+
+# Initialize logger for logging potential issues and operations
+logger = logging.getLogger(__name__)
+
+def async_completion(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
+ """
+ Generates a telemetry wrapper for chat completions to collect metrics.
+
+ Args:
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
+ version: Version of the monitoring package.
+ environment: Deployment environment (e.g., production, staging).
+ application_name: Name of the application using the Together AI SDK.
+ tracer: OpenTelemetry tracer for creating spans.
+ pricing_info: Information used for calculating the cost of Together AI usage.
+ trace_content: Flag indicating whether to trace the actual content.
+
+ Returns:
+ A function that wraps the chat completions method to add telemetry.
+ """
+
+ class TracedAsyncStream:
+ """
+ Wrapper for streaming responses to collect metrics and trace data.
+
+ This class implements the '__aiter__' and '__anext__' methods that
+ handle asynchronous streaming responses.
+
+ This class also implements '__aenter__' and '__aexit__' methods that
+ handle asynchronous context management protocol.
+ """
+ def __init__(
+ self,
+ wrapped,
+ span,
+ kwargs,
+ **args,
+ ):
+ self.__wrapped__ = wrapped
+ self._span = span
+ # Placeholder for aggregating streaming response
+ self._llmresponse = ""
+ self._response_id = ""
+
+ self._args = args
+ self._kwargs = kwargs
+
+ async def __aenter__(self):
+ await self.__wrapped__.__aenter__()
+ return self
+
+ async def __aexit__(self, exc_type, exc_value, traceback):
+ await self.__wrapped__.__aexit__(exc_type, exc_value, traceback)
+
+ def __aiter__(self):
+ return self
+
+ async def __getattr__(self, name):
+ """Delegate attribute access to the wrapped object."""
+ return getattr(await self.__wrapped__, name)
+
+ async def __anext__(self):
+ try:
+ chunk = await self.__wrapped__.__anext__()
+ chunked = response_as_dict(chunk)
+ # Collect message IDs and aggregated response from events
+ if (len(chunked.get('choices')) > 0 and ('delta' in chunked.get('choices')[0] and
+ 'content' in chunked.get('choices')[0].get('delta'))):
+
+ content = chunked.get('choices')[0].get('delta').get('content')
+ if content:
+ self._llmresponse += content
+ if chunked.get("usage"):
+ self._prompt_tokens = chunked.get("usage").get("prompt_tokens")
+ self._completion_tokens = chunked.get("usage").get("completion_tokens")
+ self._total_tokens = chunked.get("usage").get("total_tokens")
+ self._response_id = chunked.get('id')
+ return chunk
+ except StopAsyncIteration:
+ # Handling exception ensure observability without disrupting operation
+ try:
+ # Format 'messages' into a single string
+ message_prompt = self._kwargs.get("messages", "")
+ formatted_messages = []
+ for message in message_prompt:
+ role = message["role"]
+ content = message["content"]
+
+ if isinstance(content, list):
+ content_str = ", ".join(
+ # pylint: disable=line-too-long
+ f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
+ if "type" in item else f'text: {item["text"]}'
+ for item in content
+ )
+ formatted_messages.append(f"{role}: {content_str}")
+ else:
+ formatted_messages.append(f"{role}: {content}")
+ prompt = "\n".join(formatted_messages)
+
+ # Calculate cost of the operation
+ cost = get_chat_model_cost(self._kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo"),
+ pricing_info, self._prompt_tokens,
+ self._completion_tokens)
+
+ # Set Span attributes
+ self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
+ self._response_id)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ environment)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ application_name)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
+ self._kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo"))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
+ self._kwargs.get("user", ""))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
+ self._kwargs.get("top_p", 1.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
+ self._kwargs.get("max_tokens", -1))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
+ self._kwargs.get("temperature", 1.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
+ self._kwargs.get("presence_penalty", 0.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
+ self._kwargs.get("frequency_penalty", 0.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
+ self._kwargs.get("seed", ""))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
+ True)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
+ self._prompt_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
+ self._completion_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
+ self._total_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ cost)
+ if trace_content:
+ self._span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
+ },
+ )
+ self._span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
+ },
+ )
+
+ self._span.set_status(Status(StatusCode.OK))
+
+ if disable_metrics is False:
+ attributes = {
+ TELEMETRY_SDK_NAME:
+ "openlit",
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ application_name,
+ SemanticConvetion.GEN_AI_SYSTEM:
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
+ environment,
+ SemanticConvetion.GEN_AI_TYPE:
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
+ self._kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo")
+ }
+
+ metrics["genai_requests"].add(1, attributes)
+ metrics["genai_total_tokens"].add(
+ self._total_tokens, attributes
+ )
+ metrics["genai_completion_tokens"].add(self._completion_tokens, attributes)
+ metrics["genai_prompt_tokens"].add(self._prompt_tokens, attributes)
+ metrics["genai_cost"].record(cost, attributes)
+
+ except Exception as e:
+ handle_exception(self._span, e)
+ logger.error("Error in trace creation: %s", e)
+ finally:
+ self._span.end()
+ raise
+
+ async def wrapper(wrapped, instance, args, kwargs):
+ """
+ Wraps the 'chat.completions' API call to add telemetry.
+
+ This collects metrics such as execution time, cost, and token usage, and handles errors
+ gracefully, adding details to the trace for observability.
+
+ Args:
+ wrapped: The original 'chat.completions' method to be wrapped.
+ instance: The instance of the class where the original method is defined.
+ args: Positional arguments for the 'chat.completions' method.
+ kwargs: Keyword arguments for the 'chat.completions' method.
+
+ Returns:
+ The response from the original 'chat.completions' method.
+ """
+
+ # Check if streaming is enabled for the API call
+ streaming = kwargs.get("stream", False)
+
+ # pylint: disable=no-else-return
+ if streaming:
+ # Special handling for streaming response to accommodate the nature of data flow
+ awaited_wrapped = await wrapped(*args, **kwargs)
+ span = tracer.start_span(gen_ai_endpoint, kind=SpanKind.CLIENT)
+
+ return TracedAsyncStream(awaited_wrapped, span, kwargs)
+
+ # Handling for non-streaming responses
+ else:
+ # pylint: disable=line-too-long
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ response = await wrapped(*args, **kwargs)
+
+ response_dict = response_as_dict(response)
+
+ try:
+ # Format 'messages' into a single string
+ message_prompt = kwargs.get("messages", "")
+ formatted_messages = []
+ for message in message_prompt:
+ role = message["role"]
+ content = message["content"]
+
+ if isinstance(content, list):
+ content_str = ", ".join(
+ # pylint: disable=line-too-long
+ f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
+ if "type" in item else f'text: {item["text"]}'
+ for item in content
+ )
+ formatted_messages.append(f"{role}: {content_str}")
+ else:
+ formatted_messages.append(f"{role}: {content}")
+ prompt = "\n".join(formatted_messages)
+
+ # Set base span attribues
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER)
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
+ response_dict.get("id"))
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ environment)
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
+ kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo"))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
+ kwargs.get("top_p", 1.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
+ kwargs.get("max_tokens", -1))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
+ kwargs.get("user", ""))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
+ kwargs.get("temperature", 1.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
+ kwargs.get("presence_penalty", 0.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
+ kwargs.get("frequency_penalty", 0.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
+ kwargs.get("seed", ""))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
+ False)
+ if trace_content:
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
+ },
+ )
+
+ # Set span attributes when tools is not passed to the function call
+ if "tools" not in kwargs:
+ # Calculate cost of the operation
+ cost = get_chat_model_cost(kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo"),
+ pricing_info, response_dict.get('usage', {}).get('prompt_tokens', None),
+ response_dict.get('usage', {}).get('completion_tokens', None))
+
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
+ response_dict.get('usage', {}).get('prompt_tokens', None))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
+ response_dict.get('usage', {}).get('completion_tokens', None))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
+ response_dict.get('usage', {}).get('total_tokens', None))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ cost)
+
+ # Set span attributes for when n = 1 (default)
+ if "n" not in kwargs or kwargs["n"] == 1:
+ if trace_content:
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices', [])[0].get("message").get("content"),
+ },
+ )
+
+ # Set span attributes for when n > 0
+ else:
+ i = 0
+ while i < kwargs["n"] and trace_content is True:
+ attribute_name = f"gen_ai.content.completion.{i}"
+ span.add_event(
+ name=attribute_name,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices')[i].get("message").get("content"),
+ },
+ )
+ i += 1
+
+ # Return original response
+ return response
+
+ # Set span attributes when tools is passed to the function call
+ elif "tools" in kwargs:
+ # Calculate cost of the operation
+ cost = get_chat_model_cost(kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo"),
+ pricing_info, response_dict.get('usage').get('prompt_tokens'),
+ response_dict.get('usage').get('completion_tokens'))
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
+ },
+ )
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
+ response_dict.get('usage').get('prompt_tokens'))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
+ response_dict.get('usage').get('completion_tokens'))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
+ response_dict.get('usage').get('total_tokens'))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ cost)
+
+ span.set_status(Status(StatusCode.OK))
+
+ if disable_metrics is False:
+ attributes = {
+ TELEMETRY_SDK_NAME:
+ "openlit",
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ application_name,
+ SemanticConvetion.GEN_AI_SYSTEM:
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
+ environment,
+ SemanticConvetion.GEN_AI_TYPE:
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
+ kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo")
+ }
+
+ metrics["genai_requests"].add(1, attributes)
+ metrics["genai_total_tokens"].add(response_dict.get('usage').get('total_tokens'), attributes)
+ metrics["genai_completion_tokens"].add(response_dict.get('usage').get('completion_tokens'), attributes)
+ metrics["genai_prompt_tokens"].add(response_dict.get('usage').get('prompt_tokens'), attributes)
+ metrics["genai_cost"].record(cost, attributes)
+
+ # Return original response
+ return response
+
+ except Exception as e:
+ handle_exception(span, e)
+ logger.error("Error in trace creation: %s", e)
+
+ # Return original response
+ return response
+
+ return wrapper
+
+def async_image_generate(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
+ """
+ Generates a telemetry wrapper for image generation to collect metrics.
+
+ Args:
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
+ version: Version of the monitoring package.
+ environment: Deployment environment (e.g., production, staging).
+ application_name: Name of the application using the Together API.
+ tracer: OpenTelemetry tracer for creating spans.
+ pricing_info: Information used for calculating the cost of Together image generation.
+ trace_content: Flag indicating whether to trace the input prompt and generated images.
+
+ Returns:
+ A function that wraps the image generation method to add telemetry.
+ """
+
+ async def wrapper(wrapped, instance, args, kwargs):
+ """
+ Wraps the 'images.generate' API call to add telemetry.
+
+ This collects metrics such as execution time, cost, and handles errors
+ gracefully, adding details to the trace for observability.
+
+ Args:
+ wrapped: The original 'images.generate' method to be wrapped.
+ instance: The instance of the class where the original method is defined.
+ args: Positional arguments for the 'images.generate' method.
+ kwargs: Keyword arguments for the 'images.generate' method.
+
+ Returns:
+ The response from the original 'images.generate' method.
+ """
+
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ response = await wrapped(*args, **kwargs)
+ images_count = 0
+
+ try:
+ # Find Image format
+ if "response_format" in kwargs and kwargs["response_format"] == "b64_json":
+ image = "b64_json"
+ else:
+ image = "url"
+
+ # Calculate cost of the operation
+ image_size = str(kwargs.get("height", 1024)) + "x" + str(kwargs.get("width", 1024))
+ cost = get_image_model_cost(kwargs.get("model", "black-forest-labs/FLUX.1-dev"),
+ pricing_info, image_size,
+ kwargs.get("quality", "standard"))
+
+ for items in response.data:
+ # Set Span attributes
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER)
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
+ SemanticConvetion.GEN_AI_TYPE_IMAGE)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
+ response.id)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ environment)
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
+ kwargs.get("model", "black-forest-labs/FLUX.1-dev"))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
+ image_size)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
+ kwargs.get("quality", "standard"))
+ if trace_content:
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
+ },
+ )
+ attribute_name = f"gen_ai.response.image.{images_count}"
+ span.add_event(
+ name=attribute_name,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),
+ },
+ )
+
+ images_count+=1
+
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ len(response.data) * cost)
+ span.set_status(Status(StatusCode.OK))
+
+ if disable_metrics is False:
+ attributes = {
+ TELEMETRY_SDK_NAME:
+ "openlit",
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ application_name,
+ SemanticConvetion.GEN_AI_SYSTEM:
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
+ environment,
+ SemanticConvetion.GEN_AI_TYPE:
+ SemanticConvetion.GEN_AI_TYPE_IMAGE,
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
+ kwargs.get("model", "black-forest-labs/FLUX.1-dev")
+ }
+
+ metrics["genai_requests"].add(1, attributes)
+ metrics["genai_cost"].record(cost, attributes)
+
+ # Return original response
+ return response
+
+ except Exception as e:
+ handle_exception(span, e)
+ logger.error("Error in trace creation: %s", e)
+
+ # Return original response
+ return response
+
+ return wrapper
diff --git a/sdk/python/src/openlit/instrumentation/together/together.py b/sdk/python/src/openlit/instrumentation/together/together.py
new file mode 100644
index 00000000..6a64c8e3
--- /dev/null
+++ b/sdk/python/src/openlit/instrumentation/together/together.py
@@ -0,0 +1,552 @@
+# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, too-many-branches
+"""
+Module for monitoring Together calls.
+"""
+
+import logging
+from opentelemetry.trace import SpanKind, Status, StatusCode
+from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from openlit.__helpers import (
+ get_chat_model_cost,
+ general_tokens,
+ get_image_model_cost,
+ handle_exception,
+ response_as_dict,
+)
+from openlit.semcov import SemanticConvetion
+
+# Initialize logger for logging potential issues and operations
+logger = logging.getLogger(__name__)
+
+def completion(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
+ """
+ Generates a telemetry wrapper for chat completions to collect metrics.
+
+ Args:
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
+ version: Version of the monitoring package.
+ environment: Deployment environment (e.g., production, staging).
+ application_name: Name of the application using the Together AI SDK.
+ tracer: OpenTelemetry tracer for creating spans.
+ pricing_info: Information used for calculating the cost of Together AI usage.
+ trace_content: Flag indicating whether to trace the actual content.
+
+ Returns:
+ A function that wraps the chat completions method to add telemetry.
+ """
+
+ class TracedSyncStream:
+ """
+ Wrapper for streaming responses to collect metrics and trace data.
+
+ This class implements the '__aiter__' and '__anext__' methods that
+ handle asynchronous streaming responses.
+
+ This class also implements '__aenter__' and '__aexit__' methods that
+ handle asynchronous context management protocol.
+ """
+ def __init__(
+ self,
+ wrapped,
+ span,
+ kwargs,
+ **args,
+ ):
+ self.__wrapped__ = wrapped
+ self._span = span
+ # Placeholder for aggregating streaming response
+ self._llmresponse = ""
+ self._response_id = ""
+ self._prompt_tokens = 0
+ self._completion_tokens = 0
+ self._total_tokens = 0
+
+ self._args = args
+ self._kwargs = kwargs
+
+ def __enter__(self):
+ self.__wrapped__.__enter__()
+ return self
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ self.__wrapped__.__exit__(exc_type, exc_value, traceback)
+
+ def __iter__(self):
+ return self
+
+ def __getattr__(self, name):
+ """Delegate attribute access to the wrapped object."""
+ return getattr(self.__wrapped__, name)
+
+ def __next__(self):
+ try:
+ chunk = self.__wrapped__.__next__()
+ chunked = response_as_dict(chunk)
+ # Collect message IDs and aggregated response from events
+ if (len(chunked.get('choices')) > 0 and ('delta' in chunked.get('choices')[0] and
+ 'content' in chunked.get('choices')[0].get('delta'))):
+
+ content = chunked.get('choices')[0].get('delta').get('content')
+ if content:
+ self._llmresponse += content
+ if chunked.get("usage"):
+ self._prompt_tokens = chunked.get("usage").get("prompt_tokens")
+ self._completion_tokens = chunked.get("usage").get("completion_tokens")
+ self._total_tokens = chunked.get("usage").get("total_tokens")
+ self._response_id = chunked.get('id')
+ return chunk
+ except StopIteration:
+ # Handling exception ensure observability without disrupting operation
+ try:
+ # Format 'messages' into a single string
+ message_prompt = self._kwargs.get("messages", "")
+ formatted_messages = []
+ for message in message_prompt:
+ role = message["role"]
+ content = message["content"]
+
+ if isinstance(content, list):
+ content_str = ", ".join(
+ # pylint: disable=line-too-long
+ f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
+ if "type" in item else f'text: {item["text"]}'
+ for item in content
+ )
+ formatted_messages.append(f"{role}: {content_str}")
+ else:
+ formatted_messages.append(f"{role}: {content}")
+ prompt = "\n".join(formatted_messages)
+
+ # Calculate cost of the operation
+ cost = get_chat_model_cost(self._kwargs.get(
+ "model",
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo"
+ ),
+ pricing_info, self._prompt_tokens,
+ self._completion_tokens)
+
+ # Set Span attributes
+ self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
+ self._response_id)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ environment)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ application_name)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
+ self._kwargs.get("model",
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo"))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
+ self._kwargs.get("user", ""))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
+ self._kwargs.get("top_p", 1.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
+ self._kwargs.get("max_tokens", -1))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
+ self._kwargs.get("temperature", 1.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
+ self._kwargs.get("presence_penalty", 0.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
+ self._kwargs.get("frequency_penalty", 0.0))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
+ self._kwargs.get("seed", ""))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
+ True)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
+ self._prompt_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
+ self._completion_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
+ self._total_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ cost)
+ if trace_content:
+ self._span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
+ },
+ )
+ self._span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
+ },
+ )
+
+ self._span.set_status(Status(StatusCode.OK))
+
+ if disable_metrics is False:
+ attributes = {
+ TELEMETRY_SDK_NAME:
+ "openlit",
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ application_name,
+ SemanticConvetion.GEN_AI_SYSTEM:
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
+ environment,
+ SemanticConvetion.GEN_AI_TYPE:
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
+ self._kwargs.get("model",
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo")
+ }
+
+ metrics["genai_requests"].add(1, attributes)
+ metrics["genai_total_tokens"].add(
+ self._total_tokens, attributes
+ )
+ metrics["genai_completion_tokens"].add(
+ self._completion_tokens, attributes
+ )
+ metrics["genai_prompt_tokens"].add(
+ self._prompt_tokens, attributes
+ )
+ metrics["genai_cost"].record(cost, attributes)
+
+ except Exception as e:
+ handle_exception(self._span, e)
+ logger.error("Error in trace creation: %s", e)
+ finally:
+ self._span.end()
+ raise
+
+ def wrapper(wrapped, instance, args, kwargs):
+ """
+ Wraps the 'chat.completions' API call to add telemetry.
+
+ This collects metrics such as execution time, cost, and token usage, and handles errors
+ gracefully, adding details to the trace for observability.
+
+ Args:
+ wrapped: The original 'chat.completions' method to be wrapped.
+ instance: The instance of the class where the original method is defined.
+ args: Positional arguments for the 'chat.completions' method.
+ kwargs: Keyword arguments for the 'chat.completions' method.
+
+ Returns:
+ The response from the original 'chat.completions' method.
+ """
+
+ # Check if streaming is enabled for the API call
+ streaming = kwargs.get("stream", False)
+
+ # pylint: disable=no-else-return
+ if streaming:
+ # Special handling for streaming response to accommodate the nature of data flow
+ awaited_wrapped = wrapped(*args, **kwargs)
+ span = tracer.start_span(gen_ai_endpoint, kind=SpanKind.CLIENT)
+
+ return TracedSyncStream(awaited_wrapped, span, kwargs)
+
+ # Handling for non-streaming responses
+ else:
+ # pylint: disable=line-too-long
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ response = wrapped(*args, **kwargs)
+
+ response_dict = response_as_dict(response)
+
+ try:
+ # Format 'messages' into a single string
+ message_prompt = kwargs.get("messages", "")
+ formatted_messages = []
+ for message in message_prompt:
+ role = message["role"]
+ content = message["content"]
+
+ if isinstance(content, list):
+ content_str = ", ".join(
+ # pylint: disable=line-too-long
+ f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
+ if "type" in item else f'text: {item["text"]}'
+ for item in content
+ )
+ formatted_messages.append(f"{role}: {content_str}")
+ else:
+ formatted_messages.append(f"{role}: {content}")
+ prompt = "\n".join(formatted_messages)
+
+ # Set base span attribues
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER)
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
+ response_dict.get("id"))
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ environment)
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
+ kwargs.get("model",
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo"))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
+ kwargs.get("top_p", 1.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
+ kwargs.get("max_tokens", -1))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
+ kwargs.get("user", ""))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
+ kwargs.get("temperature", 1.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
+ kwargs.get("presence_penalty", 0.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
+ kwargs.get("frequency_penalty", 0.0))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
+ kwargs.get("seed", ""))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
+ False)
+ if trace_content:
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
+ },
+ )
+
+ # Set span attributes when tools is not passed to the function call
+ if "tools" not in kwargs:
+ # Calculate cost of the operation
+ cost = get_chat_model_cost(kwargs.get(
+ "model",
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo"
+ ),
+ pricing_info,
+ response_dict.get('usage', {}).get('prompt_tokens', None),
+ response_dict.get('usage', {}).get('completion_tokens', None))
+
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
+ response_dict.get('usage', {}).get('prompt_tokens', None))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
+ response_dict.get('usage', {}).get('completion_tokens', None))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
+ response_dict.get('usage', {}).get('total_tokens', None))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ cost)
+
+ # Set span attributes for when n = 1 (default)
+ if "n" not in kwargs or kwargs["n"] == 1:
+ if trace_content:
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices', [])[0].get("message").get("content"),
+ },
+ )
+
+ # Set span attributes for when n > 0
+ else:
+ i = 0
+ while i < kwargs["n"] and trace_content is True:
+ attribute_name = f"gen_ai.content.completion.{i}"
+ span.add_event(
+ name=attribute_name,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices')[i].get("message").get("content"),
+ },
+ )
+ i += 1
+
+ # Return original response
+ return response
+
+ # Set span attributes when tools is passed to the function call
+ elif "tools" in kwargs:
+ # Calculate cost of the operation
+ cost = get_chat_model_cost(kwargs.get(
+ "model",
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo"
+ ),
+ pricing_info,
+ response_dict.get('usage').get('prompt_tokens'),
+ response_dict.get('usage').get('completion_tokens'))
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
+ },
+ )
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
+ response_dict.get('usage').get('prompt_tokens'))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
+ response_dict.get('usage').get('completion_tokens'))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
+ response_dict.get('usage').get('total_tokens'))
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ cost)
+
+ span.set_status(Status(StatusCode.OK))
+
+ if disable_metrics is False:
+ attributes = {
+ TELEMETRY_SDK_NAME:
+ "openlit",
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ application_name,
+ SemanticConvetion.GEN_AI_SYSTEM:
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
+ environment,
+ SemanticConvetion.GEN_AI_TYPE:
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
+ kwargs.get("model", "meta-llama/Llama-3.3-70B-Instruct-Turbo")
+ }
+
+ metrics["genai_requests"].add(1, attributes)
+ metrics["genai_total_tokens"].add(
+ response_dict.get('usage').get('total_tokens'), attributes)
+ metrics["genai_completion_tokens"].add(
+ response_dict.get('usage').get('completion_tokens'), attributes)
+ metrics["genai_prompt_tokens"].add(
+ response_dict.get('usage').get('prompt_tokens'), attributes)
+ metrics["genai_cost"].record(cost, attributes)
+
+ # Return original response
+ return response
+
+ except Exception as e:
+ handle_exception(span, e)
+ logger.error("Error in trace creation: %s", e)
+
+ # Return original response
+ return response
+
+ return wrapper
+
+def image_generate(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
+ """
+ Generates a telemetry wrapper for image generation to collect metrics.
+
+ Args:
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
+ version: Version of the monitoring package.
+ environment: Deployment environment (e.g., production, staging).
+ application_name: Name of the application using the Together API.
+ tracer: OpenTelemetry tracer for creating spans.
+ pricing_info: Information used for calculating the cost of Together image generation.
+ trace_content: Flag indicating whether to trace the input prompt and generated images.
+
+ Returns:
+ A function that wraps the image generation method to add telemetry.
+ """
+
+ def wrapper(wrapped, instance, args, kwargs):
+ """
+ Wraps the 'images.generate' API call to add telemetry.
+
+ This collects metrics such as execution time, cost, and handles errors
+ gracefully, adding details to the trace for observability.
+
+ Args:
+ wrapped: The original 'images.generate' method to be wrapped.
+ instance: The instance of the class where the original method is defined.
+ args: Positional arguments for the 'images.generate' method.
+ kwargs: Keyword arguments for the 'images.generate' method.
+
+ Returns:
+ The response from the original 'images.generate' method.
+ """
+
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ response = wrapped(*args, **kwargs)
+ images_count = 0
+
+ try:
+ # Find Image format
+ if "response_format" in kwargs and kwargs["response_format"] == "b64_json":
+ image = "b64_json"
+ else:
+ image = "url"
+
+ # Calculate cost of the operation
+ image_size = str(kwargs.get("height", 1024)) + "x" + str(kwargs.get("width", 1024))
+ cost = get_image_model_cost(kwargs.get("model", "black-forest-labs/FLUX.1-dev"),
+ pricing_info, image_size,
+ kwargs.get("quality", "standard"))
+
+ for items in response.data:
+ # Set Span attributes
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER)
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
+ SemanticConvetion.GEN_AI_TYPE_IMAGE)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
+ response.id)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ environment)
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
+ kwargs.get("model", "black-forest-labs/FLUX.1-dev"))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
+ image_size)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
+ kwargs.get("quality", "standard"))
+ if trace_content:
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
+ },
+ )
+ attribute_name = f"gen_ai.response.image.{images_count}"
+ span.add_event(
+ name=attribute_name,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),
+ },
+ )
+
+ images_count+=1
+
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
+ len(response.data) * cost)
+ span.set_status(Status(StatusCode.OK))
+
+ if disable_metrics is False:
+ attributes = {
+ TELEMETRY_SDK_NAME:
+ "openlit",
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ application_name,
+ SemanticConvetion.GEN_AI_SYSTEM:
+ SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
+ environment,
+ SemanticConvetion.GEN_AI_TYPE:
+ SemanticConvetion.GEN_AI_TYPE_IMAGE,
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
+ kwargs.get("model", "black-forest-labs/FLUX.1-dev")
+ }
+
+ metrics["genai_requests"].add(1, attributes)
+ metrics["genai_cost"].record(cost, attributes)
+
+ # Return original response
+ return response
+
+ except Exception as e:
+ handle_exception(span, e)
+ logger.error("Error in trace creation: %s", e)
+
+ # Return original response
+ return response
+
+ return wrapper
diff --git a/sdk/python/src/openlit/semcov/__init__.py b/sdk/python/src/openlit/semcov/__init__.py
index eeff2d28..af599026 100644
--- a/sdk/python/src/openlit/semcov/__init__.py
+++ b/sdk/python/src/openlit/semcov/__init__.py
@@ -134,6 +134,7 @@ class SemanticConvetion:
GEN_AI_SYSTEM_CRAWL4AI = "crawl4ai"
GEN_AI_SYSTEM_FIRECRAWL = "firecrawl"
GEN_AI_SYSTEM_LETTA = "letta"
+ GEN_AI_SYSTEM_TOGETHER = "together"
# Vector DB
DB_OPERATION_API_ENDPOINT = "db.operation.api_endpoint"
diff --git a/sdk/python/tests/test_together.py b/sdk/python/tests/test_together.py
new file mode 100644
index 00000000..e0bc9b08
--- /dev/null
+++ b/sdk/python/tests/test_together.py
@@ -0,0 +1,106 @@
+# pylint: disable=duplicate-code, no-name-in-module
+"""
+This module contains tests for Together functionality using the Together Python library.
+
+Tests cover various API endpoints, including chat and embeddings.
+These tests validate integration with OpenLIT.
+
+Environment Variables:
+ - TOGETHER_API_KEY: Together API key for authentication.
+
+Note: Ensure the environment is properly configured for Together access and OpenLIT monitoring
+prior to running these tests.
+"""
+
+import pytest
+from together import Together
+import openlit
+
+# Initialize synchronous Together client
+sync_client = Together()
+
+# Initialize asynchronous Together client
+async_client = AsyncTogether()
+
+# Initialize environment and application name for OpenLIT monitoring
+openlit.init(environment="openlit-python-testing", application_name="openlit-python-together-test")
+
+def test_sync_together_chat():
+ """
+ Tests synchronous chat.
+
+ Raises:
+ AssertionError: If the response object is not as expected.
+ """
+
+ response = sync_client.chat.completions.create(
+ model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
+ messages=[
+ {
+ "role": "user",
+ "content": "Hi"
+ },
+ ],
+ max_tokens=1,
+ stream=False,
+ )
+ assert message.model == 'meta-llama/Llama-3.3-70B-Instruct-Turbo'
+
+def test_sync_together_image():
+ """
+ Tests synchronous image generate.
+
+ Raises:
+ AssertionError: If the response object is not as expected.
+ """
+
+ response = sync_client.images.generate(
+ prompt="AI Observability dashboard",
+ model="black-forest-labs/FLUX.1-dev",
+ width=768,
+ height=768,
+ n=1,
+ )
+
+ assert message.model == 'black-forest-labs/FLUX.1-dev'
+
+async def test_async_together_chat():
+ """
+ Tests asynchronous chat.
+
+ Raises:
+ AssertionError: If the response object is not as expected.
+ """
+
+ response = await async_client.chat.completions.create(
+ model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
+ messages=[
+ {
+ "role": "user",
+ "content": "Hi"
+ },
+ ],
+ max_tokens=1,
+ stream=False,
+ )
+ assert message.model == 'meta-llama/Llama-3.3-70B-Instruct-Turbo'
+
+async def test_async_together_image():
+ """
+ Tests asynchronous image generate.
+
+ Raises:
+ AssertionError: If the response object is not as expected.
+ """
+
+ response = await async_client.images.generate(
+ prompt="AI Observability dashboard",
+ model="black-forest-labs/FLUX.1-dev",
+ width=768,
+ height=768,
+ n=1,
+ )
+
+ assert message.model == 'black-forest-labs/FLUX.1-dev'
\ No newline at end of file