Skip to content
中文

Deliver session files

When a service agent produces a report, spreadsheet or image, it saves the result in the session’s outputs directory, and the platform turns each file into an output of that session. This page shows how to list those files from your backend, exchange them for download URLs for your users, and what to do with the paths in reply text when you build your own interface.

A path such as /mnt/session/outputs/notes.md in a reply is a path on the agent’s machine, not an address any browser can open. If you render it as a link, the user’s click goes to the same path on your own site and gets a 404.

List and download with an organization API Key

Use your organization’s server-side API key; never put it in a browser. Session IDs start with sesn_ and come from the create-session response.

StepRequestResult
List session filesGET /file/v1/files?scope_id={session ID}A data array; each item has id, filename, bytes, mime_type, created_at and state
Create a download URLPOST /file/v1/files/{file_id}/content_url with body {"ttl_seconds": 300}url and expires_at; the lifetime defaults to 900 seconds and is at most 604800 seconds; request a new URL after it expires

Save the example as deliver-session-files.mjs, set PRAXIS_API_KEY and SESSION_ID, and run node deliver-session-files.mjs. It lists the session’s files, creates a URL for each, downloads it into downloads/ and checks the byte count.

import assert from "node:assert/strict";
import { mkdir, writeFile } from "node:fs/promises";
import { setTimeout as delay } from "node:timers/promises";
const { PRAXIS_API_KEY, SESSION_ID } = process.env;
assert(PRAXIS_API_KEY, "Set PRAXIS_API_KEY in the server process");
assert(SESSION_ID?.startsWith("sesn_"), "Set SESSION_ID to the public session id");
const base = process.env.PRAXIS_API_BASE ?? "https://api.deepraxis.com";
async function api(path, body) {
const response = await fetch(`${base}${path}`, {
method: body === undefined ? "GET" : "POST",
headers: { Authorization: `Bearer ${PRAXIS_API_KEY}`, "Content-Type": "application/json" },
...(body === undefined ? {} : { body: JSON.stringify(body) }),
signal: AbortSignal.timeout(30_000),
});
const result = await response.json();
if (!response.ok) {
throw new Error(`HTTP ${response.status}; code=${result.error?.code}; request=${response.headers.get("X-Request-Id")}`);
}
return result;
}
// Files appear a few seconds after the turn ends; poll until the listing stops changing.
async function listSessionFiles(sessionId, { timeoutMs = 120_000, intervalMs = 3_000 } = {}) {
const deadline = Date.now() + timeoutMs;
let previous = "";
while (Date.now() < deadline) {
const { data } = await api(`/file/v1/files?scope_id=${encodeURIComponent(sessionId)}&order=asc&limit=100`);
const fingerprint = data.map((file) => file.id).join(",");
if (data.length > 0 && fingerprint === previous) return data;
previous = fingerprint;
await delay(intervalMs);
}
return [];
}
const files = await listSessionFiles(SESSION_ID);
assert(files.length > 0, `No files listed for ${SESSION_ID}; see the troubleshooting section`);
await mkdir("downloads", { recursive: true });
for (const file of files) {
const { url, expires_at } = await api(`/file/v1/files/${file.id}/content_url`, { ttl_seconds: 300 });
// In your product, hand `url` to the end customer's browser instead of downloading it here.
const bytes = Buffer.from(await (await fetch(url)).arrayBuffer());
assert.equal(bytes.length, file.bytes, `size mismatch for ${file.filename}`);
await writeFile(`downloads/${file.id}-${file.filename.split("/").pop()}`, bytes);
console.log({ id: file.id, filename: file.filename, bytes: file.bytes, mime_type: file.mime_type, url_expires_at: expires_at });
}

Expected: The process exits normally and prints one line per file with id, filename, bytes, mime_type and url_expires_at; downloads/ holds the same number of files and the byte counts match the listing. The download URL needs no Authorization header and anyone holding it can read the file, so give it only to the user who owns the file and keep the lifetime short.

Wait for files to appear

Files are collected after the turn ends: when session.status_idle arrives the listing is usually still empty, files appeared 7 to 16 seconds later in testing, and larger files take longer (about a minute for 6 MiB). Do not treat an empty list as “no files”; poll as the example does. If creating a URL returns 409 FILE_NOT_READY, the file is still being processed; retry shortly.

Customer tokens cannot call these endpoints

In an embed, the token an end customer holds can only read and write that customer’s own sessions. It cannot call /file/v1/files: listing returns an empty list and creating a URL returns 404. To let an end customer fetch files directly, use the artifact endpoints below; with the file endpoints in this section, your backend must list the files and create URLs with the organization API key, then pass them to the user.

Custom interfaces: do not render the path as a link

Agents usually write a Markdown link to the file in the reply. When you build your own conversation UI, check each link target first. If it matches any rule below, do not render it as a clickable link; draw a file card (name, size, download button) from the file list above instead.

FormExample
Absolute path starting with /mnt/, /home/, /workspace/ or /tmp//mnt/session/outputs/notes.md
Starts with file://file:///mnt/session/outputs/notes.md
Starts with sandbox:sandbox:/mnt/data/notes.md
const machinePath = /^(?:\/(?:mnt|home|workspace|tmp)(?:\/|$)|file:|sandbox:)/i;
export const isMachinePath = (href) => machinePath.test(href.trim());

Site-relative paths such as /a and https:// addresses do not match; handle them as you normally would.

Artifact events and endpoints

The platform registers each file in outputs as an artifact of the session, and end customers can read the artifacts of their own session directly, without going through your backend:

  • Event agent.artifact_delivered: sent when an artifact is first registered and again for each new version; the artifact field is the full artifact object. It arrives after the same turn’s session.status_idle, so do not read idle as “no more artifacts”.
  • GET /agent/v1/sessions/{session_id}/artifacts (List session artifacts): lists artifacts in ascending creation order. Each artifact has id, name (relative path inside outputs), version, parts (file_id, filename, mime_type, bytes) and source_hrefs (the link targets in the reply that point to it, verbatim).
  • POST /agent/v1/sessions/{session_id}/artifacts/{artifact_id}/content_url (Create artifact content URL): the body may carry part (default 0) and ttl_seconds (60 to 300, default 300); it returns url and expire_time.
  • Organization API keys and the session’s own end customer can call them; an end customer can read only their own sessions.
  • The Kit conversation page shows a file card under the reply.

Compatible endpoints

Through the /anthropic compatible endpoints, listing files by session works unchanged, as in the “List and download with an organization API Key” section. The new event and artifact endpoints exist only on the native endpoints, not on the compatible ones.

Troubleshooting

SymptomCause and fix
The list is emptyThe turn just ended and collection is not finished: keep polling, for up to a few minutes
The list stays emptyThe agent did not save the file in the outputs directory: check the file-writing action in the session events and confirm the file is saved in outputs
Empty list or 404 when creating a URLYou used an end-customer token: call from your backend with the organization API key
Listing returns 404The session does not exist or belongs to another organization: check that scope_id is the session ID from the create response
Creating a URL returns 409 FILE_NOT_READYThe file is still being processed: retry shortly
Two records with the same filenameThe agent delivered a file with the same name again; today that adds a new record (new file ID) and keeps the old one: show the newest by created_at

Next: Inspect sessions and usage · File API · Agent API