Debian Codegraph @

src/anthropic/resources/beta/files.py

raw
1 from __future__ import annotations
2
3 from typing import List, Mapping, Optional, cast
4
5 import httpx2
6
7 from ..._files import deepcopy_with_paths
8 from ..._types import (
9 Body,
10 Omit,
11 Query,
12 Headers,
13 NotGiven,
14 FileTypes,
15 SequenceNotStr,
16 omit,
17 not_given,
18 )
19 from ..._utils import is_given, extract_files, path_template, strip_not_given
20 from ..._compat import cached_property
21 from ..._resource import SyncAPIResource, AsyncAPIResource
22 from ..._response import (
23 BinaryAPIResponse,
24 AsyncBinaryAPIResponse,
25 StreamedBinaryAPIResponse,
26 AsyncStreamedBinaryAPIResponse,
27 to_raw_response_wrapper,
28 to_streamed_response_wrapper,
29 async_to_raw_response_wrapper,
30 to_custom_raw_response_wrapper,
31 async_to_streamed_response_wrapper,
32 to_custom_streamed_response_wrapper,
33 async_to_custom_raw_response_wrapper,
34 async_to_custom_streamed_response_wrapper,
35 )
36 from ...pagination import SyncPageCursor, AsyncPageCursor
37 from ..._base_client import (
38 AsyncPaginator,
39 merge_headers,
40 make_request_options,
41 )
42 from ...lib._stainless_helpers import stainless_helper_header_from_file as _stainless_helper_header_from_file
43 from ...types.anthropic_beta_param import AnthropicBetaParam
44 from ...types.beta.beta_deleted_file import BetaDeletedFile
45 from ...types.beta.beta_file_metadata import BetaFileMetadata
46
47 __all__ = ["Files", "AsyncFiles"]
48
49
50 class Files(SyncAPIResource):
51 @cached_property
52 def with_raw_response(self) -> FilesWithRawResponse:
53 """
54 This property can be used as a prefix for any HTTP method call to return
55 the raw response object instead of the parsed content.
56
57 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
58 """
59 return FilesWithRawResponse(self)
60
61 @cached_property
62 def with_streaming_response(self) -> FilesWithStreamingResponse:
63 """
64 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
65
66 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
67 """
68 return FilesWithStreamingResponse(self)
69
70 def list(
71 self,
72 *,
73 ids: Optional[SequenceNotStr[str]] | Omit = omit,
74 limit: int | Omit = omit,
75 page: Optional[str] | Omit = omit,
76 scope_id: str | Omit = omit,
77 betas: List[AnthropicBetaParam] | Omit = omit,
78 workspace_id: str | Omit = omit,
79 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
80 # The extra values given here take precedence over values defined on the client or passed to this method.
81 extra_headers: Headers | None = None,
82 extra_query: Query | None = None,
83 extra_body: Body | None = None,
84 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
85 ) -> SyncPageCursor[BetaFileMetadata]:
86 """
87 List Files
88
89 Args:
90 ids: Restrict the result set to Files whose `id` is in this list. At most 100 entries
91 (after de-duplication). Mutually exclusive with `page` and `limit`. When
92 supplied, the response is always a single page (`next_page` is null). IDs that
93 do not resolve to a visible File — including deleted Files — are silently
94 omitted.
95
96 limit: Number of items to return per page.
97
98 Defaults to `20`. Ranges from `1` to `1000`.
99
100 page: Opaque page cursor returned in a prior list response's `next_page`. Prefixed
101 `page_`.
102
103 scope_id: Filter by scope ID. Only returns files associated with the specified scope
104 (e.g., a session ID).
105
106 betas: Optional header to specify the beta version(s) you want to use.
107
108 workspace_id: Optional header to select the Workspace for this request. The value is a
109 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
110
111 Only needed for credentials that can act on more than one Workspace. A
112 credential that belongs to a specific Workspace may omit it; if sent, it must
113 match that Workspace.
114
115 extra_headers: Send extra headers
116
117 extra_query: Add additional query parameters to the request
118
119 extra_body: Add additional JSON properties to the request
120
121 timeout: Override the client-level default timeout for this request, in seconds
122 """
123 extra_headers = {
124 **strip_not_given(
125 {
126 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
127 "anthropic-workspace-id": workspace_id,
128 }
129 ),
130 **(extra_headers or {}),
131 }
132 return self._get_api_list(
133 "/v1/files?beta=true",
134 page=SyncPageCursor[BetaFileMetadata],
135 options=make_request_options(
136 extra_headers=extra_headers,
137 extra_query=extra_query,
138 extra_body=extra_body,
139 timeout=timeout,
140 query={
141 "ids": ids,
142 "limit": limit,
143 "page": page,
144 "scope_id": scope_id,
145 },
146 ),
147 model=BetaFileMetadata,
148 )
149
150 def delete(
151 self,
152 file_id: str,
153 *,
154 betas: List[AnthropicBetaParam] | Omit = omit,
155 workspace_id: str | Omit = omit,
156 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
157 # The extra values given here take precedence over values defined on the client or passed to this method.
158 extra_headers: Headers | None = None,
159 extra_query: Query | None = None,
160 extra_body: Body | None = None,
161 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
162 ) -> BetaDeletedFile:
163 """
164 Delete File
165
166 Args:
167 file_id: ID of the File.
168
169 betas: Optional header to specify the beta version(s) you want to use.
170
171 workspace_id: Optional header to select the Workspace for this request. The value is a
172 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
173
174 Only needed for credentials that can act on more than one Workspace. A
175 credential that belongs to a specific Workspace may omit it; if sent, it must
176 match that Workspace.
177
178 extra_headers: Send extra headers
179
180 extra_query: Add additional query parameters to the request
181
182 extra_body: Add additional JSON properties to the request
183
184 timeout: Override the client-level default timeout for this request, in seconds
185 """
186 if not file_id:
187 raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
188 extra_headers = {
189 **strip_not_given(
190 {
191 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
192 "anthropic-workspace-id": workspace_id,
193 }
194 ),
195 **(extra_headers or {}),
196 }
197 return self._delete(
198 path_template("/v1/files/{file_id}?beta=true", file_id=file_id),
199 options=make_request_options(
200 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
201 ),
202 cast_to=BetaDeletedFile,
203 )
204
205 def download(
206 self,
207 file_id: str,
208 *,
209 betas: List[AnthropicBetaParam] | Omit = omit,
210 workspace_id: str | Omit = omit,
211 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
212 # The extra values given here take precedence over values defined on the client or passed to this method.
213 extra_headers: Headers | None = None,
214 extra_query: Query | None = None,
215 extra_body: Body | None = None,
216 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
217 ) -> BinaryAPIResponse:
218 """
219 Download File
220
221 Args:
222 file_id: ID of the File.
223
224 betas: Optional header to specify the beta version(s) you want to use.
225
226 workspace_id: Optional header to select the Workspace for this request. The value is a
227 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
228
229 Only needed for credentials that can act on more than one Workspace. A
230 credential that belongs to a specific Workspace may omit it; if sent, it must
231 match that Workspace.
232
233 extra_headers: Send extra headers
234
235 extra_query: Add additional query parameters to the request
236
237 extra_body: Add additional JSON properties to the request
238
239 timeout: Override the client-level default timeout for this request, in seconds
240 """
241 if not file_id:
242 raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
243 extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
244 extra_headers = {
245 **strip_not_given(
246 {
247 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
248 "anthropic-workspace-id": workspace_id,
249 }
250 ),
251 **(extra_headers or {}),
252 }
253 return self._get(
254 path_template("/v1/files/{file_id}/content?beta=true", file_id=file_id),
255 options=make_request_options(
256 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
257 ),
258 cast_to=BinaryAPIResponse,
259 )
260
261 def retrieve_metadata(
262 self,
263 file_id: str,
264 *,
265 betas: List[AnthropicBetaParam] | Omit = omit,
266 workspace_id: str | Omit = omit,
267 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
268 # The extra values given here take precedence over values defined on the client or passed to this method.
269 extra_headers: Headers | None = None,
270 extra_query: Query | None = None,
271 extra_body: Body | None = None,
272 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
273 ) -> BetaFileMetadata:
274 """
275 Get File Metadata
276
277 Args:
278 file_id: ID of the File.
279
280 betas: Optional header to specify the beta version(s) you want to use.
281
282 workspace_id: Optional header to select the Workspace for this request. The value is a
283 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
284
285 Only needed for credentials that can act on more than one Workspace. A
286 credential that belongs to a specific Workspace may omit it; if sent, it must
287 match that Workspace.
288
289 extra_headers: Send extra headers
290
291 extra_query: Add additional query parameters to the request
292
293 extra_body: Add additional JSON properties to the request
294
295 timeout: Override the client-level default timeout for this request, in seconds
296 """
297 if not file_id:
298 raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
299 extra_headers = {
300 **strip_not_given(
301 {
302 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
303 "anthropic-workspace-id": workspace_id,
304 }
305 ),
306 **(extra_headers or {}),
307 }
308 return self._get(
309 path_template("/v1/files/{file_id}?beta=true", file_id=file_id),
310 options=make_request_options(
311 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
312 ),
313 cast_to=BetaFileMetadata,
314 )
315
316 def upload(
317 self,
318 *,
319 file: FileTypes,
320 expires_in_seconds: int | Omit = omit,
321 betas: List[AnthropicBetaParam] | Omit = omit,
322 workspace_id: str | Omit = omit,
323 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
324 # The extra values given here take precedence over values defined on the client or passed to this method.
325 extra_headers: Headers | None = None,
326 extra_query: Query | None = None,
327 extra_body: Body | None = None,
328 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
329 ) -> BetaFileMetadata:
330 """Upload File
331
332 Args:
333 file: The file to upload.
334
335 Only the final path component of the part's `filename` is
336 kept; an absent or empty `filename` is replaced with `unnamed` plus the
337 extension for the file's stored `mime_type`, when known.
338
339 expires_in_seconds: Seconds from upload until the file expires and its bytes become permanently
340 unavailable. Must be between 3600 (one hour) and 7776000 (ninety days).
341
342 betas: Optional header to specify the beta version(s) you want to use.
343
344 workspace_id: Optional header to select the Workspace for this request. The value is a
345 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
346
347 Only needed for credentials that can act on more than one Workspace. A
348 credential that belongs to a specific Workspace may omit it; if sent, it must
349 match that Workspace.
350
351 extra_headers: Send extra headers
352
353 extra_query: Add additional query parameters to the request
354
355 extra_body: Add additional JSON properties to the request
356
357 timeout: Override the client-level default timeout for this request, in seconds
358 """
359 extra_headers = {
360 **strip_not_given(
361 {
362 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
363 "anthropic-workspace-id": workspace_id,
364 }
365 ),
366 **(extra_headers or {}),
367 }
368 extra_headers = merge_headers(_stainless_helper_header_from_file(file), extra_headers)
369 body = deepcopy_with_paths(
370 {
371 "file": file,
372 "expires_in_seconds": expires_in_seconds,
373 },
374 [["file"]],
375 )
376 files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
377 # It should be noted that the actual Content-Type header that will be
378 # sent to the server will contain a `boundary` parameter, e.g.
379 # multipart/form-data; boundary=---abc--
380 extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
381 return self._post(
382 "/v1/files?beta=true",
383 body=body,
384 files=files,
385 options=make_request_options(
386 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
387 ),
388 cast_to=BetaFileMetadata,
389 )
390
391
392 class AsyncFiles(AsyncAPIResource):
393 @cached_property
394 def with_raw_response(self) -> AsyncFilesWithRawResponse:
395 """
396 This property can be used as a prefix for any HTTP method call to return
397 the raw response object instead of the parsed content.
398
399 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
400 """
401 return AsyncFilesWithRawResponse(self)
402
403 @cached_property
404 def with_streaming_response(self) -> AsyncFilesWithStreamingResponse:
405 """
406 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
407
408 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
409 """
410 return AsyncFilesWithStreamingResponse(self)
411
412 def list(
413 self,
414 *,
415 ids: Optional[SequenceNotStr[str]] | Omit = omit,
416 limit: int | Omit = omit,
417 page: Optional[str] | Omit = omit,
418 scope_id: str | Omit = omit,
419 betas: List[AnthropicBetaParam] | Omit = omit,
420 workspace_id: str | Omit = omit,
421 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
422 # The extra values given here take precedence over values defined on the client or passed to this method.
423 extra_headers: Headers | None = None,
424 extra_query: Query | None = None,
425 extra_body: Body | None = None,
426 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
427 ) -> AsyncPaginator[BetaFileMetadata, AsyncPageCursor[BetaFileMetadata]]:
428 """
429 List Files
430
431 Args:
432 ids: Restrict the result set to Files whose `id` is in this list. At most 100 entries
433 (after de-duplication). Mutually exclusive with `page` and `limit`. When
434 supplied, the response is always a single page (`next_page` is null). IDs that
435 do not resolve to a visible File — including deleted Files — are silently
436 omitted.
437
438 limit: Number of items to return per page.
439
440 Defaults to `20`. Ranges from `1` to `1000`.
441
442 page: Opaque page cursor returned in a prior list response's `next_page`. Prefixed
443 `page_`.
444
445 scope_id: Filter by scope ID. Only returns files associated with the specified scope
446 (e.g., a session ID).
447
448 betas: Optional header to specify the beta version(s) you want to use.
449
450 workspace_id: Optional header to select the Workspace for this request. The value is a
451 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
452
453 Only needed for credentials that can act on more than one Workspace. A
454 credential that belongs to a specific Workspace may omit it; if sent, it must
455 match that Workspace.
456
457 extra_headers: Send extra headers
458
459 extra_query: Add additional query parameters to the request
460
461 extra_body: Add additional JSON properties to the request
462
463 timeout: Override the client-level default timeout for this request, in seconds
464 """
465 extra_headers = {
466 **strip_not_given(
467 {
468 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
469 "anthropic-workspace-id": workspace_id,
470 }
471 ),
472 **(extra_headers or {}),
473 }
474 return self._get_api_list(
475 "/v1/files?beta=true",
476 page=AsyncPageCursor[BetaFileMetadata],
477 options=make_request_options(
478 extra_headers=extra_headers,
479 extra_query=extra_query,
480 extra_body=extra_body,
481 timeout=timeout,
482 query={
483 "ids": ids,
484 "limit": limit,
485 "page": page,
486 "scope_id": scope_id,
487 },
488 ),
489 model=BetaFileMetadata,
490 )
491
492 async def delete(
493 self,
494 file_id: str,
495 *,
496 betas: List[AnthropicBetaParam] | Omit = omit,
497 workspace_id: str | Omit = omit,
498 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
499 # The extra values given here take precedence over values defined on the client or passed to this method.
500 extra_headers: Headers | None = None,
501 extra_query: Query | None = None,
502 extra_body: Body | None = None,
503 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
504 ) -> BetaDeletedFile:
505 """
506 Delete File
507
508 Args:
509 file_id: ID of the File.
510
511 betas: Optional header to specify the beta version(s) you want to use.
512
513 workspace_id: Optional header to select the Workspace for this request. The value is a
514 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
515
516 Only needed for credentials that can act on more than one Workspace. A
517 credential that belongs to a specific Workspace may omit it; if sent, it must
518 match that Workspace.
519
520 extra_headers: Send extra headers
521
522 extra_query: Add additional query parameters to the request
523
524 extra_body: Add additional JSON properties to the request
525
526 timeout: Override the client-level default timeout for this request, in seconds
527 """
528 if not file_id:
529 raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
530 extra_headers = {
531 **strip_not_given(
532 {
533 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
534 "anthropic-workspace-id": workspace_id,
535 }
536 ),
537 **(extra_headers or {}),
538 }
539 return await self._delete(
540 path_template("/v1/files/{file_id}?beta=true", file_id=file_id),
541 options=make_request_options(
542 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
543 ),
544 cast_to=BetaDeletedFile,
545 )
546
547 async def download(
548 self,
549 file_id: str,
550 *,
551 betas: List[AnthropicBetaParam] | Omit = omit,
552 workspace_id: str | Omit = omit,
553 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
554 # The extra values given here take precedence over values defined on the client or passed to this method.
555 extra_headers: Headers | None = None,
556 extra_query: Query | None = None,
557 extra_body: Body | None = None,
558 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
559 ) -> AsyncBinaryAPIResponse:
560 """
561 Download File
562
563 Args:
564 file_id: ID of the File.
565
566 betas: Optional header to specify the beta version(s) you want to use.
567
568 workspace_id: Optional header to select the Workspace for this request. The value is a
569 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
570
571 Only needed for credentials that can act on more than one Workspace. A
572 credential that belongs to a specific Workspace may omit it; if sent, it must
573 match that Workspace.
574
575 extra_headers: Send extra headers
576
577 extra_query: Add additional query parameters to the request
578
579 extra_body: Add additional JSON properties to the request
580
581 timeout: Override the client-level default timeout for this request, in seconds
582 """
583 if not file_id:
584 raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
585 extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
586 extra_headers = {
587 **strip_not_given(
588 {
589 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
590 "anthropic-workspace-id": workspace_id,
591 }
592 ),
593 **(extra_headers or {}),
594 }
595 return await self._get(
596 path_template("/v1/files/{file_id}/content?beta=true", file_id=file_id),
597 options=make_request_options(
598 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
599 ),
600 cast_to=AsyncBinaryAPIResponse,
601 )
602
603 async def retrieve_metadata(
604 self,
605 file_id: str,
606 *,
607 betas: List[AnthropicBetaParam] | Omit = omit,
608 workspace_id: str | Omit = omit,
609 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
610 # The extra values given here take precedence over values defined on the client or passed to this method.
611 extra_headers: Headers | None = None,
612 extra_query: Query | None = None,
613 extra_body: Body | None = None,
614 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
615 ) -> BetaFileMetadata:
616 """
617 Get File Metadata
618
619 Args:
620 file_id: ID of the File.
621
622 betas: Optional header to specify the beta version(s) you want to use.
623
624 workspace_id: Optional header to select the Workspace for this request. The value is a
625 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
626
627 Only needed for credentials that can act on more than one Workspace. A
628 credential that belongs to a specific Workspace may omit it; if sent, it must
629 match that Workspace.
630
631 extra_headers: Send extra headers
632
633 extra_query: Add additional query parameters to the request
634
635 extra_body: Add additional JSON properties to the request
636
637 timeout: Override the client-level default timeout for this request, in seconds
638 """
639 if not file_id:
640 raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
641 extra_headers = {
642 **strip_not_given(
643 {
644 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
645 "anthropic-workspace-id": workspace_id,
646 }
647 ),
648 **(extra_headers or {}),
649 }
650 return await self._get(
651 path_template("/v1/files/{file_id}?beta=true", file_id=file_id),
652 options=make_request_options(
653 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
654 ),
655 cast_to=BetaFileMetadata,
656 )
657
658 async def upload(
659 self,
660 *,
661 file: FileTypes,
662 expires_in_seconds: int | Omit = omit,
663 betas: List[AnthropicBetaParam] | Omit = omit,
664 workspace_id: str | Omit = omit,
665 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
666 # The extra values given here take precedence over values defined on the client or passed to this method.
667 extra_headers: Headers | None = None,
668 extra_query: Query | None = None,
669 extra_body: Body | None = None,
670 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
671 ) -> BetaFileMetadata:
672 """Upload File
673
674 Args:
675 file: The file to upload.
676
677 Only the final path component of the part's `filename` is
678 kept; an absent or empty `filename` is replaced with `unnamed` plus the
679 extension for the file's stored `mime_type`, when known.
680
681 expires_in_seconds: Seconds from upload until the file expires and its bytes become permanently
682 unavailable. Must be between 3600 (one hour) and 7776000 (ninety days).
683
684 betas: Optional header to specify the beta version(s) you want to use.
685
686 workspace_id: Optional header to select the Workspace for this request. The value is a
687 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
688
689 Only needed for credentials that can act on more than one Workspace. A
690 credential that belongs to a specific Workspace may omit it; if sent, it must
691 match that Workspace.
692
693 extra_headers: Send extra headers
694
695 extra_query: Add additional query parameters to the request
696
697 extra_body: Add additional JSON properties to the request
698
699 timeout: Override the client-level default timeout for this request, in seconds
700 """
701 extra_headers = {
702 **strip_not_given(
703 {
704 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
705 "anthropic-workspace-id": workspace_id,
706 }
707 ),
708 **(extra_headers or {}),
709 }
710 extra_headers = merge_headers(_stainless_helper_header_from_file(file), extra_headers)
711 body = deepcopy_with_paths(
712 {
713 "file": file,
714 "expires_in_seconds": expires_in_seconds,
715 },
716 [["file"]],
717 )
718 files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
719 # It should be noted that the actual Content-Type header that will be
720 # sent to the server will contain a `boundary` parameter, e.g.
721 # multipart/form-data; boundary=---abc--
722 extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
723 return await self._post(
724 "/v1/files?beta=true",
725 body=body,
726 files=files,
727 options=make_request_options(
728 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
729 ),
730 cast_to=BetaFileMetadata,
731 )
732
733
734 class FilesWithRawResponse:
735 def __init__(self, files: Files) -> None:
736 self._files = files
737
738 self.list = to_raw_response_wrapper(
739 files.list,
740 )
741 self.delete = to_raw_response_wrapper(
742 files.delete,
743 )
744 self.download = to_custom_raw_response_wrapper(
745 files.download,
746 BinaryAPIResponse,
747 )
748 self.retrieve_metadata = to_raw_response_wrapper(
749 files.retrieve_metadata,
750 )
751 self.upload = to_raw_response_wrapper(
752 files.upload,
753 )
754
755
756 class AsyncFilesWithRawResponse:
757 def __init__(self, files: AsyncFiles) -> None:
758 self._files = files
759
760 self.list = async_to_raw_response_wrapper(
761 files.list,
762 )
763 self.delete = async_to_raw_response_wrapper(
764 files.delete,
765 )
766 self.download = async_to_custom_raw_response_wrapper(
767 files.download,
768 AsyncBinaryAPIResponse,
769 )
770 self.retrieve_metadata = async_to_raw_response_wrapper(
771 files.retrieve_metadata,
772 )
773 self.upload = async_to_raw_response_wrapper(
774 files.upload,
775 )
776
777
778 class FilesWithStreamingResponse:
779 def __init__(self, files: Files) -> None:
780 self._files = files
781
782 self.list = to_streamed_response_wrapper(
783 files.list,
784 )
785 self.delete = to_streamed_response_wrapper(
786 files.delete,
787 )
788 self.download = to_custom_streamed_response_wrapper(
789 files.download,
790 StreamedBinaryAPIResponse,
791 )
792 self.retrieve_metadata = to_streamed_response_wrapper(
793 files.retrieve_metadata,
794 )
795 self.upload = to_streamed_response_wrapper(
796 files.upload,
797 )
798
799
800 class AsyncFilesWithStreamingResponse:
801 def __init__(self, files: AsyncFiles) -> None:
802 self._files = files
803
804 self.list = async_to_streamed_response_wrapper(
805 files.list,
806 )
807 self.delete = async_to_streamed_response_wrapper(
808 files.delete,
809 )
810 self.download = async_to_custom_streamed_response_wrapper(
811 files.download,
812 AsyncStreamedBinaryAPIResponse,
813 )
814 self.retrieve_metadata = async_to_streamed_response_wrapper(
815 files.retrieve_metadata,
816 )
817 self.upload = async_to_streamed_response_wrapper(
818 files.upload,
819 )