Skip to content

Commit 2411906

Browse files
feat(api): makes 1 hour TTL Cache Control generally available
1 parent c99f5cd commit 2411906

File tree

7 files changed

+81
-15
lines changed

7 files changed

+81
-15
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 26
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-7b8549f399e6f6cd3ccba4595d5cb0ac3c5d8d40280e9a739f1e8d24be179929.yml
3-
openapi_spec_hash: e3c27dba60dbd66bd9bd1191817cf625
4-
config_hash: 2309881a63309f8b11dbb1d2c17abc1d
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-0f40955413f5d04b30ecd6c2f5002ce36a85c320cc671911ff70902fed6e342c.yml
3+
openapi_spec_hash: 92a37231c475ddfec0093718cd24f7ab
4+
config_hash: 80044c845c567b0aa38e7e759d984045

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ from anthropic.types import (
2525
Base64ImageSource,
2626
Base64PDFSource,
2727
CacheControlEphemeral,
28+
CacheCreation,
2829
CitationCharLocation,
2930
CitationCharLocationParam,
3031
CitationContentBlockLocation,

src/anthropic/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .message_param import MessageParam as MessageParam
3131
from .text_citation import TextCitation as TextCitation
3232
from .beta_api_error import BetaAPIError as BetaAPIError
33+
from .cache_creation import CacheCreation as CacheCreation
3334
from .metadata_param import MetadataParam as MetadataParam
3435
from .thinking_block import ThinkingBlock as ThinkingBlock
3536
from .thinking_delta import ThinkingDelta as ThinkingDelta

src/anthropic/types/cache_control_ephemeral_param.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@
99

1010
class CacheControlEphemeralParam(TypedDict, total=False):
1111
type: Required[Literal["ephemeral"]]
12+
13+
ttl: Literal["5m", "1h"]
14+
"""The time-to-live for the cache control breakpoint.
15+
16+
This may be one the following values:
17+
18+
- `5m`: 5 minutes
19+
- `1h`: 1 hour
20+
21+
Defaults to `5m`.
22+
"""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from .._models import BaseModel
4+
5+
__all__ = ["CacheCreation"]
6+
7+
8+
class CacheCreation(BaseModel):
9+
ephemeral_1h_input_tokens: int
10+
"""The number of input tokens used to create the 1 hour cache entry."""
11+
12+
ephemeral_5m_input_tokens: int
13+
"""The number of input tokens used to create the 5 minute cache entry."""

src/anthropic/types/usage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
from typing_extensions import Literal
55

66
from .._models import BaseModel
7+
from .cache_creation import CacheCreation
78
from .server_tool_usage import ServerToolUsage
89

910
__all__ = ["Usage"]
1011

1112

1213
class Usage(BaseModel):
14+
cache_creation: Optional[CacheCreation] = None
15+
"""Breakdown of cached tokens by TTL"""
16+
1317
cache_creation_input_tokens: Optional[int] = None
1418
"""The number of input tokens used to create the cache entry."""
1519

tests/api_resources/test_messages.py

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def test_method_create_with_all_params_overload_1(self, client: Anthropic) -> No
5454
{
5555
"text": "Today's date is 2024-06-01.",
5656
"type": "text",
57-
"cache_control": {"type": "ephemeral"},
57+
"cache_control": {
58+
"type": "ephemeral",
59+
"ttl": "5m",
60+
},
5861
"citations": [
5962
{
6063
"cited_text": "cited_text",
@@ -93,7 +96,10 @@ def test_method_create_with_all_params_overload_1(self, client: Anthropic) -> No
9396
"required": ["location"],
9497
},
9598
"name": "name",
96-
"cache_control": {"type": "ephemeral"},
99+
"cache_control": {
100+
"type": "ephemeral",
101+
"ttl": "5m",
102+
},
97103
"description": "Get the current weather in a given location",
98104
"type": "custom",
99105
}
@@ -175,7 +181,10 @@ def test_method_create_with_all_params_overload_2(self, client: Anthropic) -> No
175181
{
176182
"text": "Today's date is 2024-06-01.",
177183
"type": "text",
178-
"cache_control": {"type": "ephemeral"},
184+
"cache_control": {
185+
"type": "ephemeral",
186+
"ttl": "5m",
187+
},
179188
"citations": [
180189
{
181190
"cited_text": "cited_text",
@@ -214,7 +223,10 @@ def test_method_create_with_all_params_overload_2(self, client: Anthropic) -> No
214223
"required": ["location"],
215224
},
216225
"name": "name",
217-
"cache_control": {"type": "ephemeral"},
226+
"cache_control": {
227+
"type": "ephemeral",
228+
"ttl": "5m",
229+
},
218230
"description": "Get the current weather in a given location",
219231
"type": "custom",
220232
}
@@ -300,7 +312,10 @@ def test_method_count_tokens_with_all_params(self, client: Anthropic) -> None:
300312
{
301313
"text": "Today's date is 2024-06-01.",
302314
"type": "text",
303-
"cache_control": {"type": "ephemeral"},
315+
"cache_control": {
316+
"type": "ephemeral",
317+
"ttl": "5m",
318+
},
304319
"citations": [
305320
{
306321
"cited_text": "cited_text",
@@ -338,7 +353,10 @@ def test_method_count_tokens_with_all_params(self, client: Anthropic) -> None:
338353
"required": ["location"],
339354
},
340355
"name": "name",
341-
"cache_control": {"type": "ephemeral"},
356+
"cache_control": {
357+
"type": "ephemeral",
358+
"ttl": "5m",
359+
},
342360
"description": "Get the current weather in a given location",
343361
"type": "custom",
344362
}
@@ -421,7 +439,10 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn
421439
{
422440
"text": "Today's date is 2024-06-01.",
423441
"type": "text",
424-
"cache_control": {"type": "ephemeral"},
442+
"cache_control": {
443+
"type": "ephemeral",
444+
"ttl": "5m",
445+
},
425446
"citations": [
426447
{
427448
"cited_text": "cited_text",
@@ -460,7 +481,10 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn
460481
"required": ["location"],
461482
},
462483
"name": "name",
463-
"cache_control": {"type": "ephemeral"},
484+
"cache_control": {
485+
"type": "ephemeral",
486+
"ttl": "5m",
487+
},
464488
"description": "Get the current weather in a given location",
465489
"type": "custom",
466490
}
@@ -542,7 +566,10 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn
542566
{
543567
"text": "Today's date is 2024-06-01.",
544568
"type": "text",
545-
"cache_control": {"type": "ephemeral"},
569+
"cache_control": {
570+
"type": "ephemeral",
571+
"ttl": "5m",
572+
},
546573
"citations": [
547574
{
548575
"cited_text": "cited_text",
@@ -581,7 +608,10 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn
581608
"required": ["location"],
582609
},
583610
"name": "name",
584-
"cache_control": {"type": "ephemeral"},
611+
"cache_control": {
612+
"type": "ephemeral",
613+
"ttl": "5m",
614+
},
585615
"description": "Get the current weather in a given location",
586616
"type": "custom",
587617
}
@@ -667,7 +697,10 @@ async def test_method_count_tokens_with_all_params(self, async_client: AsyncAnth
667697
{
668698
"text": "Today's date is 2024-06-01.",
669699
"type": "text",
670-
"cache_control": {"type": "ephemeral"},
700+
"cache_control": {
701+
"type": "ephemeral",
702+
"ttl": "5m",
703+
},
671704
"citations": [
672705
{
673706
"cited_text": "cited_text",
@@ -705,7 +738,10 @@ async def test_method_count_tokens_with_all_params(self, async_client: AsyncAnth
705738
"required": ["location"],
706739
},
707740
"name": "name",
708-
"cache_control": {"type": "ephemeral"},
741+
"cache_control": {
742+
"type": "ephemeral",
743+
"ttl": "5m",
744+
},
709745
"description": "Get the current weather in a given location",
710746
"type": "custom",
711747
}

0 commit comments

Comments
 (0)