Skip to content

Commit da303fc

Browse files
feat: Repair SDK tracking generation
Stainless-Generated-From: cbc546d01211970ac7bc195f0b260106aad040a8
1 parent 092229c commit da303fc

5 files changed

Lines changed: 98 additions & 13 deletions

File tree

src/hypeman/resources/instances/instances.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, Iterable
5+
from typing import Dict, Union, Iterable
6+
from datetime import datetime
67
from typing_extensions import Literal
78

89
import httpx
@@ -126,6 +127,7 @@ def create(
126127
disk_io_bps: str | Omit = omit,
127128
entrypoint: SequenceNotStr[str] | Omit = omit,
128129
env: Dict[str, str] | Omit = omit,
130+
expires_at: Union[str, datetime] | Omit = omit,
129131
gpu: instance_create_params.GPU | Omit = omit,
130132
health_check: HealthCheckParam | Omit = omit,
131133
hotplug_size: str | Omit = omit,
@@ -139,6 +141,7 @@ def create(
139141
skip_kernel_headers: bool | Omit = omit,
140142
snapshot_policy: SnapshotPolicyParam | Omit = omit,
141143
tags: Dict[str, str] | Omit = omit,
144+
ttl: str | Omit = omit,
142145
vcpus: int | Omit = omit,
143146
volumes: Iterable[VolumeMountParam] | Omit = omit,
144147
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -178,6 +181,9 @@ def create(
178181
179182
env: Environment variables
180183
184+
expires_at: Absolute expiration time. Must be in the future and is mutually exclusive with
185+
ttl.
186+
181187
gpu: GPU configuration for the instance
182188
183189
health_check: Workload health check policy. Health is reported separately from instance
@@ -219,6 +225,10 @@ def create(
219225
220226
tags: User-defined key-value tags.
221227
228+
ttl: Relative lifetime from instance creation, in Go duration format. Use "0s" or
229+
omit both expiration fields to disable automatic expiration. Mutually exclusive
230+
with expires_at.
231+
222232
vcpus: Number of virtual CPUs
223233
224234
volumes: Volumes to attach to the instance at creation time
@@ -244,6 +254,7 @@ def create(
244254
"disk_io_bps": disk_io_bps,
245255
"entrypoint": entrypoint,
246256
"env": env,
257+
"expires_at": expires_at,
247258
"gpu": gpu,
248259
"health_check": health_check,
249260
"hotplug_size": hotplug_size,
@@ -257,6 +268,7 @@ def create(
257268
"skip_kernel_headers": skip_kernel_headers,
258269
"snapshot_policy": snapshot_policy,
259270
"tags": tags,
271+
"ttl": ttl,
260272
"vcpus": vcpus,
261273
"volumes": volumes,
262274
},
@@ -274,20 +286,21 @@ def update(
274286
*,
275287
auto_standby: AutoStandbyPolicyParam | Omit = omit,
276288
env: Dict[str, str] | Omit = omit,
289+
expires_at: Union[str, datetime] | Omit = omit,
277290
health_check: HealthCheckParam | Omit = omit,
278291
restart_policy: RestartPolicyParam | Omit = omit,
292+
ttl: str | Omit = omit,
279293
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
280294
# The extra values given here take precedence over values defined on the client or passed to this method.
281295
extra_headers: Headers | None = None,
282296
extra_query: Query | None = None,
283297
extra_body: Body | None = None,
284298
timeout: float | httpx.Timeout | None | NotGiven = not_given,
285299
) -> Instance:
286-
"""Update mutable properties of a running instance.
300+
"""Update mutable instance properties.
287301
288-
Currently supports updating
289-
only the environment variables referenced by existing credential policies,
290-
enabling secret/key rotation without instance restart.
302+
TTL values are relative to when the update
303+
is committed. Expiration updates are rejected after the current deadline passes.
291304
292305
Args:
293306
auto_standby: Linux-only automatic standby policy based on active inbound TCP connections
@@ -297,11 +310,17 @@ def update(
297310
the instance's existing credential `source.env` bindings are accepted. Use this
298311
to rotate real credential values without restarting the VM.
299312
313+
expires_at: Absolute expiration time. Must be in the future and is mutually exclusive with
314+
ttl.
315+
300316
health_check: Workload health check policy. Health is reported separately from instance
301317
lifecycle state.
302318
303319
restart_policy: Whole-instance restart supervision policy.
304320
321+
ttl: Relative lifetime from when this update is committed, in Go duration format. Use
322+
"0s" to disable automatic expiration. Mutually exclusive with expires_at.
323+
305324
extra_headers: Send extra headers
306325
307326
extra_query: Add additional query parameters to the request
@@ -318,8 +337,10 @@ def update(
318337
{
319338
"auto_standby": auto_standby,
320339
"env": env,
340+
"expires_at": expires_at,
321341
"health_check": health_check,
322342
"restart_policy": restart_policy,
343+
"ttl": ttl,
323344
},
324345
instance_update_params.InstanceUpdateParams,
325346
),
@@ -919,6 +940,7 @@ async def create(
919940
disk_io_bps: str | Omit = omit,
920941
entrypoint: SequenceNotStr[str] | Omit = omit,
921942
env: Dict[str, str] | Omit = omit,
943+
expires_at: Union[str, datetime] | Omit = omit,
922944
gpu: instance_create_params.GPU | Omit = omit,
923945
health_check: HealthCheckParam | Omit = omit,
924946
hotplug_size: str | Omit = omit,
@@ -932,6 +954,7 @@ async def create(
932954
skip_kernel_headers: bool | Omit = omit,
933955
snapshot_policy: SnapshotPolicyParam | Omit = omit,
934956
tags: Dict[str, str] | Omit = omit,
957+
ttl: str | Omit = omit,
935958
vcpus: int | Omit = omit,
936959
volumes: Iterable[VolumeMountParam] | Omit = omit,
937960
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -971,6 +994,9 @@ async def create(
971994
972995
env: Environment variables
973996
997+
expires_at: Absolute expiration time. Must be in the future and is mutually exclusive with
998+
ttl.
999+
9741000
gpu: GPU configuration for the instance
9751001
9761002
health_check: Workload health check policy. Health is reported separately from instance
@@ -1012,6 +1038,10 @@ async def create(
10121038
10131039
tags: User-defined key-value tags.
10141040
1041+
ttl: Relative lifetime from instance creation, in Go duration format. Use "0s" or
1042+
omit both expiration fields to disable automatic expiration. Mutually exclusive
1043+
with expires_at.
1044+
10151045
vcpus: Number of virtual CPUs
10161046
10171047
volumes: Volumes to attach to the instance at creation time
@@ -1037,6 +1067,7 @@ async def create(
10371067
"disk_io_bps": disk_io_bps,
10381068
"entrypoint": entrypoint,
10391069
"env": env,
1070+
"expires_at": expires_at,
10401071
"gpu": gpu,
10411072
"health_check": health_check,
10421073
"hotplug_size": hotplug_size,
@@ -1050,6 +1081,7 @@ async def create(
10501081
"skip_kernel_headers": skip_kernel_headers,
10511082
"snapshot_policy": snapshot_policy,
10521083
"tags": tags,
1084+
"ttl": ttl,
10531085
"vcpus": vcpus,
10541086
"volumes": volumes,
10551087
},
@@ -1067,20 +1099,21 @@ async def update(
10671099
*,
10681100
auto_standby: AutoStandbyPolicyParam | Omit = omit,
10691101
env: Dict[str, str] | Omit = omit,
1102+
expires_at: Union[str, datetime] | Omit = omit,
10701103
health_check: HealthCheckParam | Omit = omit,
10711104
restart_policy: RestartPolicyParam | Omit = omit,
1105+
ttl: str | Omit = omit,
10721106
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
10731107
# The extra values given here take precedence over values defined on the client or passed to this method.
10741108
extra_headers: Headers | None = None,
10751109
extra_query: Query | None = None,
10761110
extra_body: Body | None = None,
10771111
timeout: float | httpx.Timeout | None | NotGiven = not_given,
10781112
) -> Instance:
1079-
"""Update mutable properties of a running instance.
1113+
"""Update mutable instance properties.
10801114
1081-
Currently supports updating
1082-
only the environment variables referenced by existing credential policies,
1083-
enabling secret/key rotation without instance restart.
1115+
TTL values are relative to when the update
1116+
is committed. Expiration updates are rejected after the current deadline passes.
10841117
10851118
Args:
10861119
auto_standby: Linux-only automatic standby policy based on active inbound TCP connections
@@ -1090,11 +1123,17 @@ async def update(
10901123
the instance's existing credential `source.env` bindings are accepted. Use this
10911124
to rotate real credential values without restarting the VM.
10921125
1126+
expires_at: Absolute expiration time. Must be in the future and is mutually exclusive with
1127+
ttl.
1128+
10931129
health_check: Workload health check policy. Health is reported separately from instance
10941130
lifecycle state.
10951131
10961132
restart_policy: Whole-instance restart supervision policy.
10971133
1134+
ttl: Relative lifetime from when this update is committed, in Go duration format. Use
1135+
"0s" to disable automatic expiration. Mutually exclusive with expires_at.
1136+
10981137
extra_headers: Send extra headers
10991138
11001139
extra_query: Add additional query parameters to the request
@@ -1111,8 +1150,10 @@ async def update(
11111150
{
11121151
"auto_standby": auto_standby,
11131152
"env": env,
1153+
"expires_at": expires_at,
11141154
"health_check": health_check,
11151155
"restart_policy": restart_policy,
1156+
"ttl": ttl,
11161157
},
11171158
instance_update_params.InstanceUpdateParams,
11181159
),

src/hypeman/types/instance.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ class Instance(BaseModel):
5555
created_at: datetime
5656
"""Creation timestamp (RFC3339)"""
5757

58+
expires_at: Optional[datetime] = None
59+
"""Absolute expiration time, or null when automatic expiration is disabled.
60+
61+
Instance TTL is cleared on fork.
62+
"""
63+
5864
image: str
5965
"""OCI image reference"""
6066

src/hypeman/types/instance_create_params.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, Iterable
6-
from typing_extensions import Literal, Required, TypedDict
5+
from typing import Dict, Union, Iterable
6+
from datetime import datetime
7+
from typing_extensions import Literal, Required, Annotated, TypedDict
78

89
from .._types import SequenceNotStr
10+
from .._utils import PropertyInfo
911
from .health_check_param import HealthCheckParam
1012
from .volume_mount_param import VolumeMountParam
1113
from .restart_policy_param import RestartPolicyParam
@@ -73,6 +75,12 @@ class InstanceCreateParams(TypedDict, total=False):
7375
env: Dict[str, str]
7476
"""Environment variables"""
7577

78+
expires_at: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
79+
"""Absolute expiration time.
80+
81+
Must be in the future and is mutually exclusive with ttl.
82+
"""
83+
7684
gpu: GPU
7785
"""GPU configuration for the instance"""
7886

@@ -142,6 +150,13 @@ class InstanceCreateParams(TypedDict, total=False):
142150
tags: Dict[str, str]
143151
"""User-defined key-value tags."""
144152

153+
ttl: str
154+
"""Relative lifetime from instance creation, in Go duration format.
155+
156+
Use "0s" or omit both expiration fields to disable automatic expiration.
157+
Mutually exclusive with expires_at.
158+
"""
159+
145160
vcpus: int
146161
"""Number of virtual CPUs"""
147162

src/hypeman/types/instance_update_params.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict
6-
from typing_extensions import TypedDict
5+
from typing import Dict, Union
6+
from datetime import datetime
7+
from typing_extensions import Annotated, TypedDict
78

9+
from .._utils import PropertyInfo
810
from .health_check_param import HealthCheckParam
911
from .restart_policy_param import RestartPolicyParam
1012
from .auto_standby_policy_param import AutoStandbyPolicyParam
@@ -26,6 +28,12 @@ class InstanceUpdateParams(TypedDict, total=False):
2628
to rotate real credential values without restarting the VM.
2729
"""
2830

31+
expires_at: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
32+
"""Absolute expiration time.
33+
34+
Must be in the future and is mutually exclusive with ttl.
35+
"""
36+
2937
health_check: HealthCheckParam
3038
"""Workload health check policy.
3139
@@ -34,3 +42,9 @@ class InstanceUpdateParams(TypedDict, total=False):
3442

3543
restart_policy: RestartPolicyParam
3644
"""Whole-instance restart supervision policy."""
45+
46+
ttl: str
47+
"""Relative lifetime from when this update is committed, in Go duration format.
48+
49+
Use "0s" to disable automatic expiration. Mutually exclusive with expires_at.
50+
"""

tests/api_resources/test_instances.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
InstanceListResponse,
1717
WaitForStateResponse,
1818
)
19+
from hypeman._utils import parse_datetime
1920

2021
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
2122

@@ -66,6 +67,7 @@ def test_method_create_with_all_params(self, client: Hypeman) -> None:
6667
"PORT": "3000",
6768
"NODE_ENV": "production",
6869
},
70+
expires_at=parse_datetime("2026-08-21T18:00:00Z"),
6971
gpu={"profile": "L40S-1Q"},
7072
health_check={
7173
"exec": {
@@ -120,6 +122,7 @@ def test_method_create_with_all_params(self, client: Hypeman) -> None:
120122
"team": "backend",
121123
"env": "staging",
122124
},
125+
ttl="24h",
123126
vcpus=2,
124127
volumes=[
125128
{
@@ -181,6 +184,7 @@ def test_method_update_with_all_params(self, client: Hypeman) -> None:
181184
"ignore_source_cidrs": ["10.0.0.0/8", "192.168.0.0/16"],
182185
},
183186
env={"OUTBOUND_OPENAI_KEY": "new-rotated-key-456"},
187+
expires_at=parse_datetime("2026-08-21T18:00:00Z"),
184188
health_check={
185189
"exec": {
186190
"command": ["curl", "-f", "http://localhost:4318/"],
@@ -206,6 +210,7 @@ def test_method_update_with_all_params(self, client: Hypeman) -> None:
206210
"policy": "on_failure",
207211
"stable_after": "10m",
208212
},
213+
ttl="6h",
209214
)
210215
assert_matches_type(Instance, instance, path=["response"])
211216

@@ -871,6 +876,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncHypeman) -
871876
"PORT": "3000",
872877
"NODE_ENV": "production",
873878
},
879+
expires_at=parse_datetime("2026-08-21T18:00:00Z"),
874880
gpu={"profile": "L40S-1Q"},
875881
health_check={
876882
"exec": {
@@ -925,6 +931,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncHypeman) -
925931
"team": "backend",
926932
"env": "staging",
927933
},
934+
ttl="24h",
928935
vcpus=2,
929936
volumes=[
930937
{
@@ -986,6 +993,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncHypeman) -
986993
"ignore_source_cidrs": ["10.0.0.0/8", "192.168.0.0/16"],
987994
},
988995
env={"OUTBOUND_OPENAI_KEY": "new-rotated-key-456"},
996+
expires_at=parse_datetime("2026-08-21T18:00:00Z"),
989997
health_check={
990998
"exec": {
991999
"command": ["curl", "-f", "http://localhost:4318/"],
@@ -1011,6 +1019,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncHypeman) -
10111019
"policy": "on_failure",
10121020
"stable_after": "10m",
10131021
},
1022+
ttl="6h",
10141023
)
10151024
assert_matches_type(Instance, instance, path=["response"])
10161025

0 commit comments

Comments
 (0)