Calling Project File API
Overview
Perform file operations against an Azure AI Foundry project's data-plane Files API
({PROJECT_ENDPOINT}/files). Use the bundled scripts/file_api.py — it is stdlib-only
(no pip installs), so it runs on a bare Python image such as a harness sandbox.
Prerequisites
Provide two things (via env vars or CLI flags):
PROJECT_ENDPOINT—https://<resource>.services.ai.azure.com/api/projects/<project>A token — resolved automatically in this order:
--tokenflag orPROJECT_API_TOKEN/AZURE_AI_TOKENenv varazure-identityDefaultAzureCredential(managed identity / sandbox identity /az login)az account get-access-tokenCLI fallback
Token scope is
https://ai.azure.com/.default. In a managed harness the sandbox identity is used automatically viaDefaultAzureCredential— no token needs to be passed.
Usage
export PROJECT_ENDPOINT="https://<resource>.services.ai.azure.com/api/projects/<project>"
python scripts/file_api.py list
python scripts/file_api.py upload ./notes.txt --purpose assistants # -> returns { "id": "assistant-...", ... }
python scripts/file_api.py get assistant-abc123
python scripts/file_api.py download assistant-abc123 --out ./notes.txt # omit --out to stream to stdout
python scripts/file_api.py delete assistant-abc123
All commands print the JSON response (download writes bytes). Non-2xx responses print
ERROR: HTTP <code> ... with the server body and exit non-zero.
Key rules (enforced by the API)
purposeis required on upload:assistants(default) |batch|fine-tune|vision.- File extension allow-list — uploads with an unsupported extension fail with HTTP 400.
Notably
.jsonlis rejected; rename batch/fine-tune data to.jsonor.txtfirst. Allowed:c cpp css csv doc docx gif go html java jpeg jpg js json md pdf php pkl png pptx py rb tar tex ts txt webp xlsx xml zip. - api-version is mandatory and defaults to
2025-05-15-preview(override with--api-version). - If
listreturns 401/403, the caller identity lacks a data-plane role on the project — report that plainly instead of retrying.
Reference
For endpoint details, response shapes, raw curl equivalents, and the full list of
gotchas learned from live testing, see references/files-api.md.