Home / Function/ upload() — anthropic-sdk-python Function Reference

upload() — anthropic-sdk-python Function Reference

Architecture documentation for the upload() function in files.py from the anthropic-sdk-python codebase.

Function python AnthropicClient AsyncAPI calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  3dbef1a4_a354_5bb8_2fe0_82cae8d90ec8["upload()"]
  3e08ebfe_73a6_0f3e_2027_4a081297bec5["Files"]
  3dbef1a4_a354_5bb8_2fe0_82cae8d90ec8 -->|defined in| 3e08ebfe_73a6_0f3e_2027_4a081297bec5
  b6e7caed_07d6_372f_f216_e5a44b9dd309["upload()"]
  b6e7caed_07d6_372f_f216_e5a44b9dd309 -->|calls| 3dbef1a4_a354_5bb8_2fe0_82cae8d90ec8
  b6e7caed_07d6_372f_f216_e5a44b9dd309["upload()"]
  3dbef1a4_a354_5bb8_2fe0_82cae8d90ec8 -->|calls| b6e7caed_07d6_372f_f216_e5a44b9dd309
  style 3dbef1a4_a354_5bb8_2fe0_82cae8d90ec8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/resources/beta/files.py lines 275–328

    def upload(
        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,
    ) -> FileMetadata:
        """
        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 additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        extra_headers = {
            **strip_not_given(
                {
                    "anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
                    if is_given(betas)
                    else not_given
                }
            ),
            **(extra_headers or {}),
        }
        extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
        body = deepcopy_minimal({"file": file})
        files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
        # It should be noted that the actual Content-Type header that will be
        # sent to the server will contain a `boundary` parameter, e.g.
        # multipart/form-data; boundary=---abc--
        extra_headers["Content-Type"] = "multipart/form-data"
        return self._post(
            "/v1/files?beta=true",
            body=maybe_transform(body, file_upload_params.FileUploadParams),
            files=files,
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=FileMetadata,
        )

Subdomains

Calls

Called By

Frequently Asked Questions

What does upload() do?
upload() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/resources/beta/files.py.
Where is upload() defined?
upload() is defined in src/anthropic/resources/beta/files.py at line 275.
What does upload() call?
upload() calls 1 function(s): upload.
What calls upload()?
upload() is called by 1 function(s): upload.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free