main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5from typing_extensions import Literal
6
7import httpx
8
9from ... import _legacy_response
10from ...types import container_list_params, container_create_params
11from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, SequenceNotStr, omit, not_given
12from ..._utils import maybe_transform, async_maybe_transform
13from ..._compat import cached_property
14from ..._resource import SyncAPIResource, AsyncAPIResource
15from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
16from .files.files import (
17 Files,
18 AsyncFiles,
19 FilesWithRawResponse,
20 AsyncFilesWithRawResponse,
21 FilesWithStreamingResponse,
22 AsyncFilesWithStreamingResponse,
23)
24from ...pagination import SyncCursorPage, AsyncCursorPage
25from ..._base_client import AsyncPaginator, make_request_options
26from ...types.container_list_response import ContainerListResponse
27from ...types.container_create_response import ContainerCreateResponse
28from ...types.container_retrieve_response import ContainerRetrieveResponse
29
30__all__ = ["Containers", "AsyncContainers"]
31
32
33class Containers(SyncAPIResource):
34 @cached_property
35 def files(self) -> Files:
36 return Files(self._client)
37
38 @cached_property
39 def with_raw_response(self) -> ContainersWithRawResponse:
40 """
41 This property can be used as a prefix for any HTTP method call to return
42 the raw response object instead of the parsed content.
43
44 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
45 """
46 return ContainersWithRawResponse(self)
47
48 @cached_property
49 def with_streaming_response(self) -> ContainersWithStreamingResponse:
50 """
51 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
52
53 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
54 """
55 return ContainersWithStreamingResponse(self)
56
57 def create(
58 self,
59 *,
60 name: str,
61 expires_after: container_create_params.ExpiresAfter | Omit = omit,
62 file_ids: SequenceNotStr[str] | Omit = omit,
63 memory_limit: Literal["1g", "4g", "16g", "64g"] | Omit = omit,
64 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
65 # The extra values given here take precedence over values defined on the client or passed to this method.
66 extra_headers: Headers | None = None,
67 extra_query: Query | None = None,
68 extra_body: Body | None = None,
69 timeout: float | httpx.Timeout | None | NotGiven = not_given,
70 ) -> ContainerCreateResponse:
71 """
72 Create Container
73
74 Args:
75 name: Name of the container to create.
76
77 expires_after: Container expiration time in seconds relative to the 'anchor' time.
78
79 file_ids: IDs of files to copy to the container.
80
81 memory_limit: Optional memory limit for the container. Defaults to "1g".
82
83 extra_headers: Send extra headers
84
85 extra_query: Add additional query parameters to the request
86
87 extra_body: Add additional JSON properties to the request
88
89 timeout: Override the client-level default timeout for this request, in seconds
90 """
91 return self._post(
92 "/containers",
93 body=maybe_transform(
94 {
95 "name": name,
96 "expires_after": expires_after,
97 "file_ids": file_ids,
98 "memory_limit": memory_limit,
99 },
100 container_create_params.ContainerCreateParams,
101 ),
102 options=make_request_options(
103 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
104 ),
105 cast_to=ContainerCreateResponse,
106 )
107
108 def retrieve(
109 self,
110 container_id: str,
111 *,
112 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
113 # The extra values given here take precedence over values defined on the client or passed to this method.
114 extra_headers: Headers | None = None,
115 extra_query: Query | None = None,
116 extra_body: Body | None = None,
117 timeout: float | httpx.Timeout | None | NotGiven = not_given,
118 ) -> ContainerRetrieveResponse:
119 """
120 Retrieve Container
121
122 Args:
123 extra_headers: Send extra headers
124
125 extra_query: Add additional query parameters to the request
126
127 extra_body: Add additional JSON properties to the request
128
129 timeout: Override the client-level default timeout for this request, in seconds
130 """
131 if not container_id:
132 raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
133 return self._get(
134 f"/containers/{container_id}",
135 options=make_request_options(
136 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
137 ),
138 cast_to=ContainerRetrieveResponse,
139 )
140
141 def list(
142 self,
143 *,
144 after: str | Omit = omit,
145 limit: int | Omit = omit,
146 order: Literal["asc", "desc"] | Omit = omit,
147 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
148 # The extra values given here take precedence over values defined on the client or passed to this method.
149 extra_headers: Headers | None = None,
150 extra_query: Query | None = None,
151 extra_body: Body | None = None,
152 timeout: float | httpx.Timeout | None | NotGiven = not_given,
153 ) -> SyncCursorPage[ContainerListResponse]:
154 """List Containers
155
156 Args:
157 after: A cursor for use in pagination.
158
159 `after` is an object ID that defines your place
160 in the list. For instance, if you make a list request and receive 100 objects,
161 ending with obj_foo, your subsequent call can include after=obj_foo in order to
162 fetch the next page of the list.
163
164 limit: A limit on the number of objects to be returned. Limit can range between 1 and
165 100, and the default is 20.
166
167 order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
168 order and `desc` for descending order.
169
170 extra_headers: Send extra headers
171
172 extra_query: Add additional query parameters to the request
173
174 extra_body: Add additional JSON properties to the request
175
176 timeout: Override the client-level default timeout for this request, in seconds
177 """
178 return self._get_api_list(
179 "/containers",
180 page=SyncCursorPage[ContainerListResponse],
181 options=make_request_options(
182 extra_headers=extra_headers,
183 extra_query=extra_query,
184 extra_body=extra_body,
185 timeout=timeout,
186 query=maybe_transform(
187 {
188 "after": after,
189 "limit": limit,
190 "order": order,
191 },
192 container_list_params.ContainerListParams,
193 ),
194 ),
195 model=ContainerListResponse,
196 )
197
198 def delete(
199 self,
200 container_id: str,
201 *,
202 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
203 # The extra values given here take precedence over values defined on the client or passed to this method.
204 extra_headers: Headers | None = None,
205 extra_query: Query | None = None,
206 extra_body: Body | None = None,
207 timeout: float | httpx.Timeout | None | NotGiven = not_given,
208 ) -> None:
209 """
210 Delete Container
211
212 Args:
213 extra_headers: Send extra headers
214
215 extra_query: Add additional query parameters to the request
216
217 extra_body: Add additional JSON properties to the request
218
219 timeout: Override the client-level default timeout for this request, in seconds
220 """
221 if not container_id:
222 raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
223 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
224 return self._delete(
225 f"/containers/{container_id}",
226 options=make_request_options(
227 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
228 ),
229 cast_to=NoneType,
230 )
231
232
233class AsyncContainers(AsyncAPIResource):
234 @cached_property
235 def files(self) -> AsyncFiles:
236 return AsyncFiles(self._client)
237
238 @cached_property
239 def with_raw_response(self) -> AsyncContainersWithRawResponse:
240 """
241 This property can be used as a prefix for any HTTP method call to return
242 the raw response object instead of the parsed content.
243
244 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
245 """
246 return AsyncContainersWithRawResponse(self)
247
248 @cached_property
249 def with_streaming_response(self) -> AsyncContainersWithStreamingResponse:
250 """
251 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
252
253 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
254 """
255 return AsyncContainersWithStreamingResponse(self)
256
257 async def create(
258 self,
259 *,
260 name: str,
261 expires_after: container_create_params.ExpiresAfter | Omit = omit,
262 file_ids: SequenceNotStr[str] | Omit = omit,
263 memory_limit: Literal["1g", "4g", "16g", "64g"] | Omit = omit,
264 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
265 # The extra values given here take precedence over values defined on the client or passed to this method.
266 extra_headers: Headers | None = None,
267 extra_query: Query | None = None,
268 extra_body: Body | None = None,
269 timeout: float | httpx.Timeout | None | NotGiven = not_given,
270 ) -> ContainerCreateResponse:
271 """
272 Create Container
273
274 Args:
275 name: Name of the container to create.
276
277 expires_after: Container expiration time in seconds relative to the 'anchor' time.
278
279 file_ids: IDs of files to copy to the container.
280
281 memory_limit: Optional memory limit for the container. Defaults to "1g".
282
283 extra_headers: Send extra headers
284
285 extra_query: Add additional query parameters to the request
286
287 extra_body: Add additional JSON properties to the request
288
289 timeout: Override the client-level default timeout for this request, in seconds
290 """
291 return await self._post(
292 "/containers",
293 body=await async_maybe_transform(
294 {
295 "name": name,
296 "expires_after": expires_after,
297 "file_ids": file_ids,
298 "memory_limit": memory_limit,
299 },
300 container_create_params.ContainerCreateParams,
301 ),
302 options=make_request_options(
303 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
304 ),
305 cast_to=ContainerCreateResponse,
306 )
307
308 async def retrieve(
309 self,
310 container_id: str,
311 *,
312 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
313 # The extra values given here take precedence over values defined on the client or passed to this method.
314 extra_headers: Headers | None = None,
315 extra_query: Query | None = None,
316 extra_body: Body | None = None,
317 timeout: float | httpx.Timeout | None | NotGiven = not_given,
318 ) -> ContainerRetrieveResponse:
319 """
320 Retrieve Container
321
322 Args:
323 extra_headers: Send extra headers
324
325 extra_query: Add additional query parameters to the request
326
327 extra_body: Add additional JSON properties to the request
328
329 timeout: Override the client-level default timeout for this request, in seconds
330 """
331 if not container_id:
332 raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
333 return await self._get(
334 f"/containers/{container_id}",
335 options=make_request_options(
336 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
337 ),
338 cast_to=ContainerRetrieveResponse,
339 )
340
341 def list(
342 self,
343 *,
344 after: str | Omit = omit,
345 limit: int | Omit = omit,
346 order: Literal["asc", "desc"] | Omit = omit,
347 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
348 # The extra values given here take precedence over values defined on the client or passed to this method.
349 extra_headers: Headers | None = None,
350 extra_query: Query | None = None,
351 extra_body: Body | None = None,
352 timeout: float | httpx.Timeout | None | NotGiven = not_given,
353 ) -> AsyncPaginator[ContainerListResponse, AsyncCursorPage[ContainerListResponse]]:
354 """List Containers
355
356 Args:
357 after: A cursor for use in pagination.
358
359 `after` is an object ID that defines your place
360 in the list. For instance, if you make a list request and receive 100 objects,
361 ending with obj_foo, your subsequent call can include after=obj_foo in order to
362 fetch the next page of the list.
363
364 limit: A limit on the number of objects to be returned. Limit can range between 1 and
365 100, and the default is 20.
366
367 order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
368 order and `desc` for descending order.
369
370 extra_headers: Send extra headers
371
372 extra_query: Add additional query parameters to the request
373
374 extra_body: Add additional JSON properties to the request
375
376 timeout: Override the client-level default timeout for this request, in seconds
377 """
378 return self._get_api_list(
379 "/containers",
380 page=AsyncCursorPage[ContainerListResponse],
381 options=make_request_options(
382 extra_headers=extra_headers,
383 extra_query=extra_query,
384 extra_body=extra_body,
385 timeout=timeout,
386 query=maybe_transform(
387 {
388 "after": after,
389 "limit": limit,
390 "order": order,
391 },
392 container_list_params.ContainerListParams,
393 ),
394 ),
395 model=ContainerListResponse,
396 )
397
398 async def delete(
399 self,
400 container_id: str,
401 *,
402 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
403 # The extra values given here take precedence over values defined on the client or passed to this method.
404 extra_headers: Headers | None = None,
405 extra_query: Query | None = None,
406 extra_body: Body | None = None,
407 timeout: float | httpx.Timeout | None | NotGiven = not_given,
408 ) -> None:
409 """
410 Delete Container
411
412 Args:
413 extra_headers: Send extra headers
414
415 extra_query: Add additional query parameters to the request
416
417 extra_body: Add additional JSON properties to the request
418
419 timeout: Override the client-level default timeout for this request, in seconds
420 """
421 if not container_id:
422 raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
423 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
424 return await self._delete(
425 f"/containers/{container_id}",
426 options=make_request_options(
427 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
428 ),
429 cast_to=NoneType,
430 )
431
432
433class ContainersWithRawResponse:
434 def __init__(self, containers: Containers) -> None:
435 self._containers = containers
436
437 self.create = _legacy_response.to_raw_response_wrapper(
438 containers.create,
439 )
440 self.retrieve = _legacy_response.to_raw_response_wrapper(
441 containers.retrieve,
442 )
443 self.list = _legacy_response.to_raw_response_wrapper(
444 containers.list,
445 )
446 self.delete = _legacy_response.to_raw_response_wrapper(
447 containers.delete,
448 )
449
450 @cached_property
451 def files(self) -> FilesWithRawResponse:
452 return FilesWithRawResponse(self._containers.files)
453
454
455class AsyncContainersWithRawResponse:
456 def __init__(self, containers: AsyncContainers) -> None:
457 self._containers = containers
458
459 self.create = _legacy_response.async_to_raw_response_wrapper(
460 containers.create,
461 )
462 self.retrieve = _legacy_response.async_to_raw_response_wrapper(
463 containers.retrieve,
464 )
465 self.list = _legacy_response.async_to_raw_response_wrapper(
466 containers.list,
467 )
468 self.delete = _legacy_response.async_to_raw_response_wrapper(
469 containers.delete,
470 )
471
472 @cached_property
473 def files(self) -> AsyncFilesWithRawResponse:
474 return AsyncFilesWithRawResponse(self._containers.files)
475
476
477class ContainersWithStreamingResponse:
478 def __init__(self, containers: Containers) -> None:
479 self._containers = containers
480
481 self.create = to_streamed_response_wrapper(
482 containers.create,
483 )
484 self.retrieve = to_streamed_response_wrapper(
485 containers.retrieve,
486 )
487 self.list = to_streamed_response_wrapper(
488 containers.list,
489 )
490 self.delete = to_streamed_response_wrapper(
491 containers.delete,
492 )
493
494 @cached_property
495 def files(self) -> FilesWithStreamingResponse:
496 return FilesWithStreamingResponse(self._containers.files)
497
498
499class AsyncContainersWithStreamingResponse:
500 def __init__(self, containers: AsyncContainers) -> None:
501 self._containers = containers
502
503 self.create = async_to_streamed_response_wrapper(
504 containers.create,
505 )
506 self.retrieve = async_to_streamed_response_wrapper(
507 containers.retrieve,
508 )
509 self.list = async_to_streamed_response_wrapper(
510 containers.list,
511 )
512 self.delete = async_to_streamed_response_wrapper(
513 containers.delete,
514 )
515
516 @cached_property
517 def files(self) -> AsyncFilesWithStreamingResponse:
518 return AsyncFilesWithStreamingResponse(self._containers.files)