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:



207
208
209
# File 'lib/anthropic/resources/files.rb', line 207

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)
  • workspace_id: (String)
  • request_options: (Anthropic::request_opts)

Returns:

Raises:

See Also:



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/anthropic/resources/files.rb', line 70

def delete(file_id, params = {})
  parsed, options = Anthropic::FileDeleteParams.dump_request(params)
  @client.request(
    span_name: Anthropic::Internal::Tracing::SpanName::FILES_DELETE,
    span_attributes: {"anthropic.file.id" => file_id},
    span_route: "/v1/files/{file_id}",
    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)
  • workspace_id: (String)
  • request_options: (Anthropic::request_opts)

Returns:

  • (StringIO)

Raises:

See Also:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/anthropic/resources/files.rb', line 107

def download(file_id, params = {})
  parsed, options = Anthropic::FileDownloadParams.dump_request(params)
  @client.request(
    span_name: Anthropic::Internal::Tracing::SpanName::FILES_DOWNLOAD,
    span_attributes: {"anthropic.file.id" => file_id},
    span_route: "/v1/files/{file_id}/content",
    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)
  • ids: (::Array[String], nil)
  • limit: (Integer)
  • page: (String, nil)
  • workspace_id: (String)
  • request_options: (Anthropic::request_opts)

Returns:

Raises:

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/anthropic/resources/files.rb', line 31

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(
    span_name: Anthropic::Internal::Tracing::SpanName::FILES_LIST,
    span_route: "/v1/files",
    span_query: %w[ids limit page],
    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)
  • workspace_id: (String)
  • request_options: (Anthropic::request_opts)

Returns:

Raises:

See Also:



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

def (file_id, params = {})
  parsed, options = Anthropic::FileRetrieveMetadataParams.dump_request(params)
  @client.request(
    span_name: Anthropic::Internal::Tracing::SpanName::FILES_RETRIEVE_METADATA,
    span_attributes: {"anthropic.file.id" => file_id},
    span_route: "/v1/files/{file_id}",
    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

  • 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)
  • file: (Anthropic::Internal::file_input)
  • expires_in_seconds: (Integer)
  • workspace_id: (String)
  • request_options: (Anthropic::request_opts)

Returns:

Raises:

See Also:



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/anthropic/resources/files.rb', line 183

def upload(params)
  parsed, options = Anthropic::FileUploadParams.dump_request(params)
  header_params = {workspace_id: "anthropic-workspace-id"}
  @client.request(
    span_name: Anthropic::Internal::Tracing::SpanName::FILES_UPLOAD,
    span_created_id: "anthropic.file.id",
    span_route: "/v1/files",
    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