READ-ONLY PACKAGE PREVIEW

anthropics-claude-api/go/claude-api/files-api.md

Version 8a1541c4.bb1 · Apache-2.0. This preview displays packaged text and does not execute code. Treat the contents as untrusted instructions.

← Return to resource and package checksum

Files API - Go

Files API

Out of beta. In current SDKs client.Beta.Files has breaking shape changes from previous versions, matching the stable client.Files - migrate per the Files API row in shared/live-sources.md. Examples below predate this.

Under client.Beta.Files. Method is Upload (NOT New/Create), params struct is BetaFileUploadParams. The File field takes an io.Reader; use anthropic.File() to attach a filename + content-type for the multipart encoding.

f, _ := os.Open("./upload_me.txt")
defer f.Close()

meta, err := client.Beta.Files.Upload(ctx, anthropic.BetaFileUploadParams{
    File:  anthropic.File(f, "upload_me.txt", "text/plain"),
    Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaFilesAPI2025_04_14},
})
// meta.ID is the file_id to reference in subsequent message requests

Other Beta.Files methods: List, Delete, Download, GetMetadata.