Skip to content

Add Files API resource#17

Merged
mozex merged 6 commits intomainfrom
files-resource
Apr 18, 2026
Merged

Add Files API resource#17
mozex merged 6 commits intomainfrom
files-resource

Conversation

@mozex
Copy link
Copy Markdown
Owner

@mozex mozex commented Apr 18, 2026

Summary

Adds $client->files() with five methods — upload, list, retrieveMetadata, download, delete. Anthropic's Files API lets you upload a document once and reference it by file_id in later Messages calls, which is useful for repeated PDFs or images and for consuming outputs from the code execution tool and Skills.

$file = $client->files()->upload(['file' => fopen('/path/to/doc.pdf', 'r')]);

$response = $client->messages()->create([
    'model' => 'claude-opus-4-6',
    'max_tokens' => 1024,
    'betas' => ['files-api-2025-04-14'],
    'messages' => [[
        'role' => 'user',
        'content' => [
            ['type' => 'text', 'text' => 'Summarise this.'],
            ['type' => 'document', 'source' => ['type' => 'file', 'file_id' => $file->id]],
        ],
    ]],
]);

@mozex mozex merged commit c02bf8c into main Apr 18, 2026
28 checks passed
@mozex mozex deleted the files-resource branch April 18, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant