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

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

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:



155
156
157
# File 'lib/anthropic/resources/beta/files.rb', line 155

def initialize(client:)
  @client = client
end

Instance Method Details

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

Delete File

Parameters:

Returns:

See Also:



57
58
59
60
61
62
63
64
65
66
# File 'lib/anthropic/resources/beta/files.rb', line 57

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::BetaDeletedFile,
    options: options
  )
end

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

Download File

Parameters:

Returns:

  • (StringIO)

See Also:



81
82
83
84
85
86
87
88
89
90
# File 'lib/anthropic/resources/beta/files.rb', line 81

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: options
  )
end

#list(ids: nil, limit: nil, page: nil, scope_id: nil, betas: nil, request_options: {}) ⇒ Anthropic::Internal::PageCursor<Anthropic::Models::Beta::BetaFileMetadata>

List Files

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

Parameters:

  • ids (Array<String>, nil)

    Query param: Restrict the result set to Files whose id is in this list. At mos

  • limit (Integer)

    Query param: Number of items to return per page.

  • page (String, nil)

    Query param: Opaque page cursor returned in a prior list response's next_page.

  • scope_id (String)

    Query param: Filter by scope ID. Only returns files associated with the specifie

  • 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:



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

def list(params = {})
  query_params = [:ids, :limit, :page, :scope_id]
  parsed, options = Anthropic::Beta::FileListParams.dump_request(params)
  query = Anthropic::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: "v1/files?beta=true",
    query: query,
    headers: parsed.except(*query_params).transform_keys(betas: "anthropic-beta"),
    page: Anthropic::Internal::PageCursor,
    model: Anthropic::Beta::BetaFileMetadata,
    options: options
  )
end

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

Get File Metadata

Parameters:

Returns:

See Also:



105
106
107
108
109
110
111
112
113
114
# File 'lib/anthropic/resources/beta/files.rb', line 105

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::BetaFileMetadata,
    options: options
  )
end

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

Upload File

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

Parameters:

  • file (Pathname, StringIO, IO, String, Anthropic::FilePart)

    Body param: The file to upload

  • expires_in_seconds (Integer)

    Body param: Seconds from upload until the file expires and its bytes become perm

  • 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:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/anthropic/resources/beta/files.rb', line 134

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::BetaFileMetadata,
    options: options
  )
end