列出文件
Parameters
params BetaFileListParams
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 param.Opt[int64] OptionalQuery parameterNumber of items to return per page.
Number of items to return per page.
Defaults to 20. Ranges from 1 to 1000.
Opaque page cursor returned in a prior list response's next_page. Prefixed page_.
Filter by scope ID. Only returns files associated with the specified scope (e.g., a session ID).
Betas []AnthropicBeta OptionalHeader parameterOptional header to specify the beta version(s) you want to use.
Optional header to specify the beta version(s) you want to use.
const AnthropicBetaMessageBatches2024_09_24 AnthropicBeta = "message-batches-2024-09-24"Deprecated
const AnthropicBetaPromptCaching2024_07_31 AnthropicBeta = "prompt-caching-2024-07-31"Deprecated
const AnthropicBetaPDFs2024_09_25 AnthropicBeta = "pdfs-2024-09-25"Deprecated
const AnthropicBetaTokenCounting2024_11_01 AnthropicBeta = "token-counting-2024-11-01"Deprecated
const AnthropicBetaTokenEfficientTools2025_02_19 AnthropicBeta = "token-efficient-tools-2025-02-19"Deprecated
const AnthropicBetaFilesAPI2025_04_14 AnthropicBeta = "files-api-2025-04-14"Deprecated
const AnthropicBetaExtendedCacheTTL2025_04_11 AnthropicBeta = "extended-cache-ttl-2025-04-11"Deprecated
const AnthropicBetaSkills2025_10_02 AnthropicBeta = "skills-2025-10-02"Deprecated
const AnthropicBetaCacheDiagnosis2026_04_07 AnthropicBeta = "cache-diagnosis-2026-04-07"Deprecated
const AnthropicBetaCEUserManagement2026_07_13 AnthropicBeta = "ce-user-management-2026-07-13"Deprecated
WorkspaceID param.Opt[string] OptionalHeader parameterOptional header to select the Workspace for this request. The value is a Workspace ID (for example, wrkspc_011CZkZaBF1tNoB5wlCeusgy).
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
type BetaFileMetadata struct { Type: "file"; ID; CreatedAt; /* 6 more */ }
Type FileObject type.
Object type.
For files, this is always "file".
ID stringUnique object identifier.
Unique object identifier.
The format and length of IDs may change over time.
CreatedAt TimeRFC 3339 datetime string representing when the file was created.
RFC 3339 datetime string representing when the file was created.
Filename stringOriginal filename of the uploaded file.
Original filename of the uploaded file.
MimeType stringMIME type of the file.
MIME type of the file.
SizeBytes int64Size of the file in bytes.
Size of the file in bytes.
Downloadable bool OptionalWhether the file can be downloaded.
Whether the file can be downloaded.
ExpiresAt Time OptionalRFC 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.
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.
Scope BetaFileScope OptionalThe scope of this file, indicating the context in which it was created (e.g., a session).
The scope of this file, indicating the context in which it was created (e.g., a session).
The type of scope (e.g., "session").
The ID of the scoping resource (e.g., the session ID).
Errors
Any method can also return the general HTTP errors.
The API key belongs to the Claude Code workspace, and the user who created it is no longer a member of the organization or of that workspace.
The workspace's customer-managed encryption key is disabled or revoked. Re-enable the key, then retry.
The key management service's network access controls blocked the request to the workspace's customer-managed encryption key. The key itself may be healthy.
Anthropic has disabled the organization for trust and safety reasons. An organization disabled for any other reason, such as billing, does not get this code. appeal_url, when present, is where the organization can appeal.
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go/v2"
"github.com/anthropics/anthropic-sdk-go/v2/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("my-anthropic-api-key"),
)
page, err := client.Beta.Files.List(context.TODO(), anthropic.BetaFileListParams{})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", page)
}{
"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",
"scope": {
"id": "id",
"type": "session"
}
}
],
"next_page": "next_page"
}Returns Examples
{
"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",
"scope": {
"id": "id",
"type": "session"
}
}
],
"next_page": "next_page"
}