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:



164
165
166
# File 'lib/anthropic/resources/files.rb', line 164

def initialize(client:)
  @client = client
end

Instance Method Details

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

Delete File

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

Parameters:

  • file_id (String)

    ID of the File.

  • workspace_id (String)

    Optional header to select the Workspace for this request. The value is a Workspa

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

Returns:

See Also:



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

def delete(file_id, params = {})
  parsed, options = Anthropic::FileDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["v1/files/%1$s", file_id],
    headers: parsed.transform_keys(workspace_id: "anthropic-workspace-id"),
    model: Anthropic::DeletedFile,
    options: options
  )
end

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

Download File

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

Parameters:

  • file_id (String)

    ID of the File.

  • workspace_id (String)

    Optional header to select the Workspace for this request. The value is a Workspa

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

Returns:

  • (StringIO)

See Also:



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

def download(file_id, params = {})
  parsed, options = Anthropic::FileDownloadParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v1/files/%1$s/content", file_id],
    headers: {
      "accept" => "application/binary",
      **parsed
    }.transform_keys(workspace_id: "anthropic-workspace-id"),
    model: StringIO,
    options: options
  )
end

#list(ids: nil, limit: nil, page: nil, workspace_id: 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)

    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.

  • workspace_id (String)

    Header param: Optional header to select the Workspace for this request. The valu

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

Returns:

See Also:



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

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

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

Get File Metadata

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

Parameters:

  • file_id (String)

    ID of the File.

  • workspace_id (String)

    Optional header to select the Workspace for this request. The value is a Workspa

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

Returns:

See Also:



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

def (file_id, params = {})
  parsed, options = Anthropic::FileRetrieveMetadataParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v1/files/%1$s", file_id],
    headers: parsed.transform_keys(workspace_id: "anthropic-workspace-id"),
    model: Anthropic::FileMetadata,
    options: options
  )
end

#upload(file:, expires_in_seconds: nil, workspace_id: 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)

    Body param: The file to upload. Only the final path component of the part's `fil

  • expires_in_seconds (Integer)

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

  • workspace_id (String)

    Header param: Optional header to select the Workspace for this request. The valu

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

Returns:

See Also:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/anthropic/resources/files.rb', line 143

def upload(params)
  parsed, options = Anthropic::FileUploadParams.dump_request(params)
  header_params = {workspace_id: "anthropic-workspace-id"}
  @client.request(
    method: :post,
    path: "v1/files",
    headers: {
      "content-type" => "multipart/form-data",
      **parsed.slice(*header_params.keys)
    }.transform_keys(
      header_params
    ),
    body: parsed.except(*header_params.keys),
    model: Anthropic::FileMetadata,
    options: options
  )
end