Overview
Agent runs can produce files such as CSV, JSON, JSONL, and reports in the sandbox. When code the model runs in thesandbox tool writes a file and delivers it with the share_file tool, the response output array includes a share_file item. The file content is not returned inline — retrieve it separately with the response files endpoints, using the response id.
Send a document
Add aninput_file part to a user message on POST /v1/agent or its /v1/responses alias. Set exactly one of file_data and file_url. Document inputs go to the model directly; you do not need the sandbox or file_search tool.
For a local file, set file_data to standard base64 or a base64 data URI, such as data:application/pdf;base64,.... PDF, DOC, DOCX, UTF-8 TXT, and RTF are recognized, but supported formats and sources depend on the selected model and provider. Known unsupported combinations return HTTP 400 before the response starts, including when stream=true.
filename is optional. For inline file_data, omitting it uses document and the recognized extension; a filename without an extension gets that extension automatically. The resulting basename, including any added extension, must be at most 255 UTF-8 bytes. For file_url, omit filename to use the PDF default, or supply a basename with a supported extension matching the remote document. Conflicting filename extensions or data-URI media types return HTTP 400.
The following HTTP examples read a local document.pdf. Set PERPLEXITY_API_KEY first. Keep the first response’s id to ask a follow-up without resending the file. For a fixed JSON response shape, add a JSON schema output format.
Use a URL
Replace the file part with a public HTTPS URL. URLs cannot contain credentials or fragments and must use port 443. The provider retrieves the document; the API does not download or verify its contents in advance. Withoutfilename, URL input is described as PDF. For another supported format, provide a filename with the correct extension. Ensure that this matches the remote document’s actual type.
Limits and continuation
These limits differ from Sonar’s attachment allowance of 50 MiB per file. Video input is not supported by this document contract. Requests that combine documents with browser tools return HTTP 400 before the response starts, including when a preset enables the browser tool or
previous_response_id inherits document context.
For inline files, use previous_response_id under the same API project to continue without sending the file again. Keep the total active document count and byte size within the limits, and choose a model that supports all inherited documents. Inline documents remain available for the original response’s retention period, up to 30 days. A follow-up does not extend that period. If the original response is deleted or expires, resend the document in a new conversation. Input documents are separate from the output-file listing described below.
Produce a file
Give the agent thesandbox tool and ask it to write a file. Here it generates a CSV of the latest AI news. Keep the resulting response.id — you use it to list and download the file.
For runs that take a while, submit with
background=true and poll before listing files. See Background mode.List a response’s files
GET /v1/agent/{id}/files
Use the response id from the run above to list the files it produced.
Download a file
GET /v1/agent/{id}/files/{file_id}/content
Use the file id to download its content. The file id is distinct from the response id.
This endpoint returns raw file bytes, not JSON. The response includes a
Content-Type matching the file and a Content-Disposition: attachment header carrying the original filename.