Files
You're Claude Code, working in my repository.
Task
Wrap Meta's Files API in a small module in my app: upload (POST /v1/files), list (GET /v1/files), retrieve (GET /v1/files/{file_id}), download (GET /v1/files/{file_id}/content) and delete (DELETE /v1/files/{file_id}), then use an uploaded file's id in a Responses request.
Read this first
Meta's docs page "Files" as Markdown: https://dev.meta.ai/docs/api-reference/files.md
It's the source of truth for request and response shapes. The same page for people: https://dev.meta.ai/docs/api-reference/files
Setup
- Base URL: https://api.meta.ai/v1
- Auth: send Authorization: Bearer $MODEL_API_KEY, reading MODEL_API_KEY from the environment. Never hard-code, print or commit the key.
- Model: muse-spark-1.3-contributor (Contributor mode: Meta may use what you send to train future models; drop -contributor for Standard mode)
- Python: the OpenAI SDK (pip install openai) with base_url="https://api.meta.ai/v1" and api_key=os.environ["MODEL_API_KEY"] works, or plain requests.
Facts to get right
- Upload: multipart purpose (user_data, or batch for Batch input), optional expires_after[anchor]=created_at and expires_after[seconds] (3600 to 2592000), the file part last.
- FileObject: {"id": "file-<digits>", "bytes", "created_at", "expires_at", "filename", "object": "file", "purpose", "status"}; expires_at may be null or missing when the file never expires.
- GET /v1/files takes purpose, limit (1 to 10,000), order (asc or desc) and after (a file id), and answers {object: list, data, first_id, last_id, has_more}.
- Content answers raw bytes, not JSON; delete answers {id, object: file, deleted: true}. Reference an upload as {"type": "input_file", "file_id": ...}.
Starter code (Python)
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.meta.ai/v1", api_key=os.environ["MODEL_API_KEY"])
with open("document.pdf", "rb") as f:
file = client.files.create(purpose="user_data", file=f)
print(client.files.list(purpose="user_data").data)
print(client.files.retrieve(file.id))
with open("copy.pdf", "wb") as out:
out.write(client.files.content(file.id).read())
answer = client.responses.create(
model="muse-spark-1.3-contributor",
input=[{"type": "message", "role": "user", "content": [
{"type": "input_text", "text": "Summarize this document."},
{"type": "input_file", "file_id": file.id},
]}],
)
print(answer.output_text)
print(client.files.delete(file.id))
Done when
- Upload, list, retrieve, download and delete each run once against the real API.
- The downloaded bytes match the uploaded file.
- A Responses request with the uploaded file_id answers about the file.
- The key comes from MODEL_API_KEY and never appears in code, logs or commits.
- API errors (4xx, 429) surface their message instead of failing silently.2,845 characters
The files endpoints upload files for use in inference requests and manage previously uploaded files.
For supported file types, upload examples, and how to reference files in requests, see the Files feature page.
Mirrored from dev.meta.ai/docs/api-reference/files (synced Oct 30, 2026). Text and examples © Meta. Live demos run on Muse Muse's key.