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:



180
181
182
# File 'lib/anthropic/resources/beta/files.rb', line 180

def initialize(client:)
  @client = client
end

Instance Method Details

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

Delete File

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

Parameters:

  • file_id (String)

    ID of the File.

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

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

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



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

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", workspace_id: "anthropic-workspace-id"),
    model: Anthropic::Beta::BetaDeletedFile,
    options: options
  )
end

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

Download File

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

Parameters:

  • file_id (String)

    ID of the File.

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

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

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



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/anthropic/resources/beta/files.rb', line 96

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",
      workspace_id: "anthropic-workspace-id"
    ),
    model: StringIO,
    options: options
  )
end

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

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



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

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",
      workspace_id: "anthropic-workspace-id"
    ),
    page: Anthropic::Internal::PageCursor,
    model: Anthropic::Beta::BetaFileMetadata,
    options: options
  )
end

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

Get File Metadata

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

Parameters:

  • file_id (String)

    ID of the File.

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

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

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



128
129
130
131
132
133
134
135
136
137
# File 'lib/anthropic/resources/beta/files.rb', line 128

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", workspace_id: "anthropic-workspace-id"),
    model: Anthropic::Beta::BetaFileMetadata,
    options: options
  )
end

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

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

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

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



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/anthropic/resources/beta/files.rb', line 159

def upload(params)
  parsed, options = Anthropic::Beta::FileUploadParams.dump_request(params)
  header_params = {betas: "anthropic-beta", workspace_id: "anthropic-workspace-id"}
  @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