Upload File Args: file: The file to upload betas: Optional header to specify the beta version(s) you want to use. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add addi
(
self,
*,
file: FileTypes,
betas: List[AnthropicBetaParam] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
)
| 284 | ) |
| 285 | |
| 286 | def upload( |
| 287 | self, |
| 288 | *, |
| 289 | file: FileTypes, |
| 290 | betas: List[AnthropicBetaParam] | Omit = omit, |
| 291 | # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 292 | # The extra values given here take precedence over values defined on the client or passed to this method. |
| 293 | extra_headers: Headers | None = None, |
| 294 | extra_query: Query | None = None, |
| 295 | extra_body: Body | None = None, |
| 296 | timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 297 | ) -> FileMetadata: |
| 298 | """ |
| 299 | Upload File |
| 300 | |
| 301 | Args: |
| 302 | file: The file to upload |
| 303 | |
| 304 | betas: Optional header to specify the beta version(s) you want to use. |
| 305 | |
| 306 | extra_headers: Send extra headers |
| 307 | |
| 308 | extra_query: Add additional query parameters to the request |
| 309 | |
| 310 | extra_body: Add additional JSON properties to the request |
| 311 | |
| 312 | timeout: Override the client-level default timeout for this request, in seconds |
| 313 | """ |
| 314 | extra_headers = { |
| 315 | **strip_not_given( |
| 316 | { |
| 317 | "anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"])) |
| 318 | if is_given(betas) |
| 319 | else not_given |
| 320 | } |
| 321 | ), |
| 322 | **(extra_headers or {}), |
| 323 | } |
| 324 | extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})} |
| 325 | extra_headers = merge_headers(_stainless_helper_header_from_file(file), extra_headers) |
| 326 | body = deepcopy_with_paths({"file": file}, [["file"]]) |
| 327 | files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
| 328 | # It should be noted that the actual Content-Type header that will be |
| 329 | # sent to the server will contain a `boundary` parameter, e.g. |
| 330 | # multipart/form-data; boundary=---abc-- |
| 331 | extra_headers["Content-Type"] = "multipart/form-data" |
| 332 | return self._post( |
| 333 | "/v1/files?beta=true", |
| 334 | body=maybe_transform(body, file_upload_params.FileUploadParams), |
| 335 | files=files, |
| 336 | options=make_request_options( |
| 337 | extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 338 | ), |
| 339 | cast_to=FileMetadata, |
| 340 | ) |
| 341 | |
| 342 | |
| 343 | class AsyncFiles(AsyncAPIResource): |