Skip to content

Add comprehensive file support to AnthropicClient#39

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-35
Closed

Add comprehensive file support to AnthropicClient#39
Copilot wants to merge 1 commit intomainfrom
copilot/fix-35

Conversation

Copy link

Copilot AI commented Jul 15, 2025

This PR implements complete file management capabilities for the Anthropic API, enabling users to upload, manage, and download files through the AnthropicClient.

📁 New File Operations

All file operations requested in the issue have been implemented:

  • Create a file - CreateFileAsync() with multipart form data support
  • List Files - ListFilesAsync() and ListAllFilesAsync() with pagination
  • Get File Metadata - GetFileAsync() to retrieve file information
  • Download a File - DownloadFileAsync() with proper content handling
  • Delete a File - DeleteFileAsync() to remove files

🏗️ Implementation Details

New Models

  • AnthropicFile - Represents file metadata with proper JSON serialization
  • FileRequest - Handles file upload requests with validation
  • FileDeleteResponse - Confirms file deletion operations
  • FileDownloadResponse - Contains downloaded file content and metadata

API Client Extensions

Extended IAnthropicApiClient and AnthropicApiClient with file operations following existing patterns:

  • Consistent error handling with AnthropicResult<T>
  • Full async/await support with cancellation tokens
  • Pagination support matching existing List/ListAll patterns

Example Usage

var client = new AnthropicApiClient("your-api-key", new HttpClient());

// Upload a file
var content = File.ReadAllBytes("document.pdf");
var request = new FileRequest(content, "document.pdf", "application/pdf");
var result = await client.CreateFileAsync(request);

// List files
var files = await client.ListFilesAsync();

// Download file content
var download = await client.DownloadFileAsync(fileId);
var fileBytes = download.Value.Content;

// Delete file
await client.DeleteFileAsync(fileId);

🧪 Testing

Comprehensive test coverage includes:

  • 22 file-related tests covering all operations
  • Unit tests for model serialization/deserialization
  • Integration tests with HTTP mocking
  • Input validation and error handling tests
  • Content-Disposition header parsing tests

🔄 Backwards Compatibility

This is a purely additive change - no existing functionality is modified. All existing tests continue to pass.

Fixes #35.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] [FEAT]: Add support for files Add comprehensive file support to AnthropicClient Jul 15, 2025
Copilot AI requested a review from StevanFreeborn July 15, 2025 00:42
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.

[FEAT]: Add support for files

2 participants