Class: Anthropic::Resources::Beta::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/anthropic/resources/beta/files.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Files

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Files.

Parameters:



147
148
149
# File 'lib/anthropic/resources/beta/files.rb', line 147

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(file_id, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::DeletedFile

Delete File

Parameters:

Returns:

See Also:



54
55
56
57
58
59
60
61
62
63
# File 'lib/anthropic/resources/beta/files.rb', line 54

def delete(file_id, params = {})
  parsed, options = Anthropic::Beta::FileDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["v1/files/%1$s?beta=true", file_id],
    headers: parsed.transform_keys(betas: "anthropic-beta"),
    model: Anthropic::Beta::DeletedFile,
    options: {extra_headers: {"anthropic-beta" => "files-api-2025-04-14"}, **options}
  )
end

#download(file_id, betas: nil, request_options: {}) ⇒ StringIO

Download File

Parameters:

Returns:

  • (StringIO)

See Also:



78
79
80
81
82
83
84
85
86
87
# File 'lib/anthropic/resources/beta/files.rb', line 78

def download(file_id, params = {})
  parsed, options = Anthropic::Beta::FileDownloadParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v1/files/%1$s/content?beta=true", file_id],
    headers: {"accept" => "application/binary", **parsed}.transform_keys(betas: "anthropic-beta"),
    model: StringIO,
    options: {extra_headers: {"anthropic-beta" => "files-api-2025-04-14"}, **options}
  )
end

#list(after_id: nil, before_id: nil, limit: nil, betas: nil, request_options: {}) ⇒ Anthropic::Internal::Page<Anthropic::Models::Beta::FileMetadata>

Some parameter documentations has been truncated, see Models::Beta::FileListParams for more details.

List Files

Parameters:

  • after_id (String)

    Query param: ID of the object to use as a cursor for pagination. When provided,

  • before_id (String)

    Query param: ID of the object to use as a cursor for pagination. When provided,

  • limit (Integer)

    Query param: Number of items to return per page.

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/anthropic/resources/beta/files.rb', line 27

def list(params = {})
  parsed, options = Anthropic::Beta::FileListParams.dump_request(params)
  query_params = [:after_id, :before_id, :limit]
  @client.request(
    method: :get,
    path: "v1/files?beta=true",
    query: parsed.slice(*query_params),
    headers: parsed.except(*query_params).transform_keys(betas: "anthropic-beta"),
    page: Anthropic::Internal::Page,
    model: Anthropic::Beta::FileMetadata,
    options: {extra_headers: {"anthropic-beta" => "files-api-2025-04-14"}, **options}
  )
end

#retrieve_metadata(file_id, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::FileMetadata

Get File Metadata

Parameters:

Returns:

See Also:



102
103
104
105
106
107
108
109
110
111
# File 'lib/anthropic/resources/beta/files.rb', line 102

def (file_id, params = {})
  parsed, options = Anthropic::Beta::FileRetrieveMetadataParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v1/files/%1$s?beta=true", file_id],
    headers: parsed.transform_keys(betas: "anthropic-beta"),
    model: Anthropic::Beta::FileMetadata,
    options: {extra_headers: {"anthropic-beta" => "files-api-2025-04-14"}, **options}
  )
end

#upload(file: , betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::FileMetadata

Upload File

Parameters:

Returns:

See Also:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/anthropic/resources/beta/files.rb', line 126

def upload(params)
  parsed, options = Anthropic::Beta::FileUploadParams.dump_request(params)
  header_params = {betas: "anthropic-beta"}
  @client.request(
    method: :post,
    path: "v1/files?beta=true",
    headers: {
      "content-type" => "multipart/form-data",
      **parsed.slice(*header_params.keys)
    }.transform_keys(
      header_params
    ),
    body: parsed.except(*header_params.keys),
    model: Anthropic::Beta::FileMetadata,
    options: {extra_headers: {"anthropic-beta" => "files-api-2025-04-14"}, **options}
  )
end