Class: Anthropic::Resources::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/anthropic/resources/files.rb,
sig/anthropic/resources/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:



129
130
131
# File 'lib/anthropic/resources/files.rb', line 129

def initialize(client:)
  @client = client
end

Instance Method Details

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

Delete File

Parameters:

Returns:

See Also:



48
49
50
51
52
53
54
55
# File 'lib/anthropic/resources/files.rb', line 48

def delete(file_id, params = {})
  @client.request(
    method: :delete,
    path: ["v1/files/%1$s", file_id],
    model: Anthropic::DeletedFile,
    options: params[:request_options]
  )
end

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

Download File

Parameters:

Returns:

  • (StringIO)

See Also:



68
69
70
71
72
73
74
75
76
# File 'lib/anthropic/resources/files.rb', line 68

def download(file_id, params = {})
  @client.request(
    method: :get,
    path: ["v1/files/%1$s/content", file_id],
    headers: {"accept" => "application/binary"},
    model: StringIO,
    options: params[:request_options]
  )
end

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

List Files

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

Parameters:

  • ids (Array<String>, nil)

    Restrict the result set to Files whose id is in this list. At most 100 entries

  • limit (Integer)

    Number of items to return per page.

  • page (String, nil)

    Opaque page cursor returned in a prior list response's next_page. Prefixed `pa

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

Returns:

See Also:



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/anthropic/resources/files.rb', line 24

def list(params = {})
  parsed, options = Anthropic::FileListParams.dump_request(params)
  query = Anthropic::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "v1/files",
    query: query,
    page: Anthropic::Internal::PageCursor,
    model: Anthropic::FileMetadata,
    options: options
  )
end

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

Get File Metadata

Parameters:

Returns:

See Also:



89
90
91
92
93
94
95
96
# File 'lib/anthropic/resources/files.rb', line 89

def (file_id, params = {})
  @client.request(
    method: :get,
    path: ["v1/files/%1$s", file_id],
    model: Anthropic::FileMetadata,
    options: params[:request_options]
  )
end

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

Upload File

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

Parameters:

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

    The file to upload

  • expires_in_seconds (Integer)

    Seconds from upload until the file expires and its bytes become permanently unav

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

Returns:

See Also:



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/anthropic/resources/files.rb', line 114

def upload(params)
  parsed, options = Anthropic::FileUploadParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/files",
    headers: {"content-type" => "multipart/form-data"},
    body: parsed,
    model: Anthropic::FileMetadata,
    options: options
  )
end