---
title: Files
url: https://platform.claude.com/docs/en/api/ruby/files
---

# Files

## Upload File

`files.upload(**kwargs) -> FileMetadata`

**POST** `/v1/files`

Upload File

### Parameters

- `file: String`

  The file to upload. Only the final path component of the part's `filename` is kept; an absent or empty `filename` is replaced with `unnamed` plus the extension for the file's stored `mime_type`, when known.

  format: binary

- `expires_in_seconds: Integer`

  Seconds from upload until the file expires and its bytes become permanently unavailable. Must be between 3600 (one hour) and 7776000 (ninety days).

  minimum: 3600, maximum: 7776000

- `workspace_id: String` (header parameter)

  Optional header to select the Workspace for this request. The value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).

  Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.

### Returns

- `class FileMetadata`

  - `type: :file`

    Object type.

    For files, this is always `"file"`.

  - `id: String`

    Unique object identifier.

    The format and length of IDs may change over time.

  - `created_at: Time`

    RFC 3339 datetime string representing when the file was created.

    format: date-time

  - `filename: String`

    Original filename of the uploaded file.

    minLength: 1, maxLength: 500

  - `mime_type: String`

    MIME type of the file.

    minLength: 1, maxLength: 255

  - `size_bytes: Integer`

    Size of the file in bytes.

    minimum: 0

  - `downloadable: bool`

    Whether the file can be downloaded.

  - `expires_at: Time`

    RFC 3339 datetime string representing when the file will expire and become unavailable for download. Null if the file does not expire. For files uploaded with `expires_in_seconds`, this is the upload time plus that value.

    format: date-time

### Example

```ruby
require "anthropic"

anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")

file_metadata = anthropic.files.upload(file: StringIO.new("Example data"))

puts(file_metadata)
```

#### Response (200)

```json
{
  "id": "file_011CNha8iCJcU1wXNR6q4V8w",
  "created_at": "2025-04-15T18:37:24.100435Z",
  "filename": "document.pdf",
  "mime_type": "application/pdf",
  "size_bytes": 102400,
  "type": "file",
  "downloadable": false,
  "expires_at": "2025-05-15T18:37:24.100435Z"
}
```

## List Files

`files.list(**kwargs) -> PageCursor<FileMetadata>`

**GET** `/v1/files`

List Files

### Parameters

- `ids: Array[String]` (query parameter)

  Restrict the result set to Files whose `id` is in this list. At most 100 entries (after de-duplication). Mutually exclusive with `page` and `limit`. When supplied, the response is always a single page (`next_page` is null). IDs that do not resolve to a visible File — including deleted Files — are silently omitted.

- `limit: Integer` (query parameter)

  Number of items to return per page.

  Defaults to `20`. Ranges from `1` to `1000`.

  minimum: 1, maximum: 1000

- `page: String` (query parameter)

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

- `workspace_id: String` (header parameter)

  Optional header to select the Workspace for this request. The value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).

  Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.

### Returns

- `class FileMetadata`

  - `type: :file`

    Object type.

    For files, this is always `"file"`.

  - `id: String`

    Unique object identifier.

    The format and length of IDs may change over time.

  - `created_at: Time`

    RFC 3339 datetime string representing when the file was created.

    format: date-time

  - `filename: String`

    Original filename of the uploaded file.

    minLength: 1, maxLength: 500

  - `mime_type: String`

    MIME type of the file.

    minLength: 1, maxLength: 255

  - `size_bytes: Integer`

    Size of the file in bytes.

    minimum: 0

  - `downloadable: bool`

    Whether the file can be downloaded.

  - `expires_at: Time`

    RFC 3339 datetime string representing when the file will expire and become unavailable for download. Null if the file does not expire. For files uploaded with `expires_in_seconds`, this is the upload time plus that value.

    format: date-time

### Example

```ruby
require "anthropic"

anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")

page = anthropic.files.list

puts(page)
```

#### Response (200)

```json
{
  "data": [
    {
      "id": "file_011CNha8iCJcU1wXNR6q4V8w",
      "created_at": "2025-04-15T18:37:24.100435Z",
      "filename": "document.pdf",
      "mime_type": "application/pdf",
      "size_bytes": 102400,
      "type": "file",
      "downloadable": false,
      "expires_at": "2025-05-15T18:37:24.100435Z"
    }
  ],
  "next_page": "next_page"
}
```

## Download File

`files.download(file_id, **kwargs) -> StringIO`

**GET** `/v1/files/{file_id}/content`

Download File

### Parameters

- `file_id: String` (path parameter)

  ID of the File.

- `workspace_id: String` (header parameter)

  Optional header to select the Workspace for this request. The value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).

  Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.

### Returns

- `StringIO`

### Example

```ruby
require "anthropic"

anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")

response = anthropic.files.download("file_id")

puts(response)
```

## Get File Metadata

`files.retrieve_metadata(file_id, **kwargs) -> FileMetadata`

**GET** `/v1/files/{file_id}`

Get File Metadata

### Parameters

- `file_id: String` (path parameter)

  ID of the File.

- `workspace_id: String` (header parameter)

  Optional header to select the Workspace for this request. The value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).

  Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.

### Returns

- `class FileMetadata`

  - `type: :file`

    Object type.

    For files, this is always `"file"`.

  - `id: String`

    Unique object identifier.

    The format and length of IDs may change over time.

  - `created_at: Time`

    RFC 3339 datetime string representing when the file was created.

    format: date-time

  - `filename: String`

    Original filename of the uploaded file.

    minLength: 1, maxLength: 500

  - `mime_type: String`

    MIME type of the file.

    minLength: 1, maxLength: 255

  - `size_bytes: Integer`

    Size of the file in bytes.

    minimum: 0

  - `downloadable: bool`

    Whether the file can be downloaded.

  - `expires_at: Time`

    RFC 3339 datetime string representing when the file will expire and become unavailable for download. Null if the file does not expire. For files uploaded with `expires_in_seconds`, this is the upload time plus that value.

    format: date-time

### Example

```ruby
require "anthropic"

anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")

file_metadata = anthropic.files.retrieve_metadata("file_id")

puts(file_metadata)
```

#### Response (200)

```json
{
  "id": "file_011CNha8iCJcU1wXNR6q4V8w",
  "created_at": "2025-04-15T18:37:24.100435Z",
  "filename": "document.pdf",
  "mime_type": "application/pdf",
  "size_bytes": 102400,
  "type": "file",
  "downloadable": false,
  "expires_at": "2025-05-15T18:37:24.100435Z"
}
```

## Delete File

`files.delete(file_id, **kwargs) -> DeletedFile`

**DELETE** `/v1/files/{file_id}`

Delete File

### Parameters

- `file_id: String` (path parameter)

  ID of the File.

- `workspace_id: String` (header parameter)

  Optional header to select the Workspace for this request. The value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).

  Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.

### Returns

- `class DeletedFile`

  - `type: :file_deleted`

    Deleted object type.

    For file deletion, this is always `"file_deleted"`.

  - `id: String`

    ID of the deleted file.

### Example

```ruby
require "anthropic"

anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")

deleted_file = anthropic.files.delete("file_id")

puts(deleted_file)
```

#### Response (200)

```json
{
  "id": "file_011CNha8iCJcU1wXNR6q4V8w",
  "type": "file_deleted"
}
```

## Domain types

### Deleted File

- `class DeletedFile`

  - `type: :file_deleted`

    Deleted object type.

    For file deletion, this is always `"file_deleted"`.

  - `id: String`

    ID of the deleted file.

### File Metadata

- `class FileMetadata`

  - `type: :file`

    Object type.

    For files, this is always `"file"`.

  - `id: String`

    Unique object identifier.

    The format and length of IDs may change over time.

  - `created_at: Time`

    RFC 3339 datetime string representing when the file was created.

    format: date-time

  - `filename: String`

    Original filename of the uploaded file.

    minLength: 1, maxLength: 500

  - `mime_type: String`

    MIME type of the file.

    minLength: 1, maxLength: 255

  - `size_bytes: Integer`

    Size of the file in bytes.

    minimum: 0

  - `downloadable: bool`

    Whether the file can be downloaded.

  - `expires_at: Time`

    RFC 3339 datetime string representing when the file will expire and become unavailable for download. Null if the file does not expire. For files uploaded with `expires_in_seconds`, this is the upload time plus that value.

    format: date-time
