File tree Expand file tree Collapse file tree 6 files changed +68
-0
lines changed
docs/docs/integrations/chat
partners/anthropic/langchain_anthropic Expand file tree Collapse file tree 6 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 568
568
" ```\n " ,
569
569
" and specifying `\" cache_control\" : {\" type\" : \" ephemeral\" , \" ttl\" : \" 1h\" }`.\n " ,
570
570
" \n " ,
571
+ " Details of cached token counts will be included on the `InputTokenDetails` of response's `usage_metadata`:\n " ,
572
+ " \n " ,
573
+ " ```python\n " ,
574
+ " response = llm.invoke(messages)\n " ,
575
+ " response.usage_metadata\n " ,
576
+ " ```\n " ,
577
+ " ```\n " ,
578
+ " {\n " ,
579
+ " \" input_tokens\" : 1500,\n " ,
580
+ " \" output_tokens\" : 200,\n " ,
581
+ " \" total_tokens\" : 1700,\n " ,
582
+ " \" input_token_details\" : {\n " ,
583
+ " \" cache_read\" : 0,\n " ,
584
+ " \" cache_creation\" : 1000,\n " ,
585
+ " \" ephemeral_1h_input_tokens\" : 750,\n " ,
586
+ " \" ephemeral_5m_input_tokens\" : 250,\n " ,
587
+ " }\n " ,
588
+ " }\n " ,
589
+ " ```\n " ,
590
+ " \n " ,
571
591
" :::"
572
592
]
573
593
},
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ class InputTokenDetails(TypedDict, total=False):
55
55
}
56
56
57
57
.. versionadded:: 0.3.9
58
+
59
+ May also hold extra provider-specific keys.
58
60
"""
59
61
60
62
audio : int
Original file line number Diff line number Diff line change 702
702
}
703
703
704
704
.. versionadded:: 0.3.9
705
+
706
+ May also hold extra provider-specific keys.
705
707
''',
706
708
'properties': dict({
707
709
'audio': dict({
2132
2134
}
2133
2135
2134
2136
.. versionadded:: 0.3.9
2137
+
2138
+ May also hold extra provider-specific keys.
2135
2139
''',
2136
2140
'properties': dict({
2137
2141
'audio': dict({
Original file line number Diff line number Diff line change 1105
1105
}
1106
1106
1107
1107
.. versionadded:: 0.3.9
1108
+
1109
+ May also hold extra provider-specific keys.
1108
1110
''',
1109
1111
'properties': dict({
1110
1112
'audio': dict({
Original file line number Diff line number Diff line change 2650
2650
}
2651
2651
2652
2652
.. versionadded:: 0.3.9
2653
+
2654
+ May also hold extra provider-specific keys.
2653
2655
''',
2654
2656
'properties': dict({
2655
2657
'audio': dict({
4124
4126
}
4125
4127
4126
4128
.. versionadded:: 0.3.9
4129
+
4130
+ May also hold extra provider-specific keys.
4127
4131
''',
4128
4132
'properties': dict({
4129
4133
'audio': dict({
5629
5633
}
5630
5634
5631
5635
.. versionadded:: 0.3.9
5636
+
5637
+ May also hold extra provider-specific keys.
5632
5638
''',
5633
5639
'properties': dict({
5634
5640
'audio': dict({
7009
7015
}
7010
7016
7011
7017
.. versionadded:: 0.3.9
7018
+
7019
+ May also hold extra provider-specific keys.
7012
7020
''',
7013
7021
'properties': dict({
7014
7022
'audio': dict({
8525
8533
}
8526
8534
8527
8535
.. versionadded:: 0.3.9
8536
+
8537
+ May also hold extra provider-specific keys.
8528
8538
''',
8529
8539
'properties': dict({
8530
8540
'audio': dict({
9950
9960
}
9951
9961
9952
9962
.. versionadded:: 0.3.9
9963
+
9964
+ May also hold extra provider-specific keys.
9953
9965
''',
9954
9966
'properties': dict({
9955
9967
'audio': dict({
11374
11386
}
11375
11387
11376
11388
.. versionadded:: 0.3.9
11389
+
11390
+ May also hold extra provider-specific keys.
11377
11391
''',
11378
11392
'properties': dict({
11379
11393
'audio': dict({
12840
12854
}
12841
12855
12842
12856
.. versionadded:: 0.3.9
12857
+
12858
+ May also hold extra provider-specific keys.
12843
12859
''',
12844
12860
'properties': dict({
12845
12861
'audio': dict({
Original file line number Diff line number Diff line change @@ -955,6 +955,8 @@ class Joke(BaseModel):
955
955
956
956
.. dropdown:: Extended caching
957
957
958
+ .. versionadded:: 0.3.15
959
+
958
960
The cache lifetime is 5 minutes by default. If this is too short, you can
959
961
apply one hour caching by enabling the ``"extended-cache-ttl-2025-04-11"``
960
962
beta header:
@@ -968,6 +970,28 @@ class Joke(BaseModel):
968
970
969
971
and specifying ``"cache_control": {"type": "ephemeral", "ttl": "1h"}``.
970
972
973
+ Details of cached token counts will be included on the ``InputTokenDetails``
974
+ of response's ``usage_metadata``:
975
+
976
+ .. code-block:: python
977
+
978
+ response = llm.invoke(messages)
979
+ response.usage_metadata
980
+
981
+ .. code-block:: python
982
+
983
+ {
984
+ "input_tokens": 1500,
985
+ "output_tokens": 200,
986
+ "total_tokens": 1700,
987
+ "input_token_details": {
988
+ "cache_read": 0,
989
+ "cache_creation": 1000,
990
+ "ephemeral_1h_input_tokens": 750,
991
+ "ephemeral_5m_input_tokens": 250,
992
+ }
993
+ }
994
+
971
995
See `Claude documentation <https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#1-hour-cache-duration-beta>`_
972
996
for detail.
973
997
You can’t perform that action at this time.
0 commit comments