[DOCS] Python SDK file upload example uses invalid raw bytes syntax
Documentation Type
Incorrect/outdated documentation
Documentation Location
https://platform.claude.com/docs/en/api/python/beta/files/upload
Section/Topic
Example section
Current Documentation
file_metadata = client.beta.files.upload(
file=b"raw file contents",
)
What's Wrong or Missing?
The code example passes raw bytes (b"raw file contents") to the file parameter without specifying a filename.
In the Python httpx library (used by the Anthropic SDK) and the API's FileTypes definition, uploading raw bytes typically requires a tuple format (filename, bytes) to:
- Assign a filename for the uploaded file
- Properly construct the multipart form data
Without the tuple format, the API may:
- Reject the request
- Assign a generic/empty filename
- Fail to properly identify the file type
Suggested Improvement
Update the example to use the tuple format:
Before:
file_metadata = client.beta.files.upload(
file=b"raw file contents",
)
After:
file_metadata = client.beta.files.upload(
file=("filename.txt", b"raw file contents"),
)
Or use a file-like object:
from pathlib import Path
file_metadata = client.beta.files.upload(
file=Path("document.pdf"),
)
Impact
High - Prevents users from using a feature
Additional Context
Affected Pages:
| Page | Line | Context |
|------|------|---------|
| https://platform.claude.com/docs/en/api/python/beta/files/upload | 109 | Example code block |
| https://platform.claude.com/docs/en/api/python/beta/files | (same) | Rolled-up page |
| https://platform.claude.com/docs/en/api/python/beta | (same) | Rolled-up page |
Total scope: 3 pages affected (same content, different aggregation levels).
Pattern searched: file=b"
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗