LangChain.FileUploader.FileAnthropic (LangChain v0.8.4)

Copy Markdown View Source

Uploads files to Anthropic's Files API.

Requires the files-api-2025-04-14 beta header, which is automatically included.

Usage

{:ok, uploader} = LangChain.FileUploader.FileAnthropic.new(%{api_key: "sk-ant-..."})

{:ok, result} = LangChain.FileUploader.upload(uploader, file_bytes, %{
  filename: "document.pdf",
  mime_type: "application/pdf"
})

result.file_id
#=> "file-abc123"

The returned file_id can be used with ContentPart.file!/2 to reference the uploaded file in messages:

ContentPart.file!(result.file_id, type: :file_id)

Summary

Functions

Setup an Anthropic file uploader configuration.

Setup an Anthropic file uploader configuration and return it or raise an error if invalid.

Types

t()

@type t() :: %LangChain.FileUploader.FileAnthropic{
  api_key: term(),
  api_version: term(),
  endpoint: term(),
  receive_timeout: term(),
  req_opts: term()
}

Functions

new(attrs \\ %{})

@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}

Setup an Anthropic file uploader configuration.

new!(attrs \\ %{})

@spec new!(attrs :: map()) :: t() | no_return()

Setup an Anthropic file uploader configuration and return it or raise an error if invalid.