Files

Upload files for use in tasks.

See REST overview — response format.


Upload File

Uploading is two requests: POST /files creates the file record and returns a presigned upload_url; the bytes are then PUT to that URL. The SDKs (client.files.upload) and belt file upload do both steps.

1. Create the record

POST /files

Content-Type: application/json

FieldTypeRequiredDescription
filesarrayYesOne entry per file
files[].uristringYesSend ""; the server assigns it
files[].filenamestringNoFile name
files[].content_typestringNoMIME type
files[].sizenumberYesLength in bytes; the upload must match it
files[].pathstringNoCustom storage path
categorystringNoStorage category

Response

An array of file DTOs, one per entry:

FieldTypeDescription
idstringFile ID
uristringFile URI for use in inputs
upload_urlstringPresigned URL to PUT the bytes to
filenamestringFile name
content_typestringMIME type
sizenumberSize in bytes
json
1[2  {3    "id": "file_abc123",4    "uri": "https://cloud.inference.sh/t/abc123/image.png",5    "upload_url": "https://storage.example/...signed...",6    "filename": "image.png",7    "content_type": "image/png",8    "size": 1024009  }10]

A missing or 0 size returns 400 size is required: the file's length in bytes, which its upload must match, and a size over the per-file maximum is refused. The upload URL accepts exactly size bytes.

Server-side scripts and executables are refused: a filename or path ending in, for example, .php, .jsp, .aspx, .cgi, .htaccess, .exe, .dll, .so, .dylib, .msi, .bat or .vbs, or a content_type naming one of those kinds, returns 400 validation_error (files of type .php cannot be uploaded: server-side scripts and executables are not accepted). Media, documents, archives and source such as .py or .sh are accepted.

2. Upload the bytes

PUT {upload_url} with the raw body and a Content-Type header. No inference.sh auth header; the URL is presigned and short-lived. A 2xx means the file is ready and uri can be used in task inputs. The body length must equal files[].size from step 1.


cURL Example

bash
1# 1. create the record2curl -X POST https://api.inference.sh/files \3  -H "Authorization: Bearer inf_your_key" \4  -H "Content-Type: application/json" \5  -d '{"files":[{"uri":"","filename":"image.png","content_type":"image/png","size":102400}]}'67# 2. upload the bytes to upload_url from the response8curl -X PUT "https://storage.example/...signed..." \9  -H "Content-Type: image/png" \10  --data-binary @/path/to/image.png

CLI equivalent: belt file upload <path> (add --json for {filename, size, type, uri}; supports multiple paths in one command).


Downloading files (CLI)

belt file download, belt app run --download, and other CLI paths that fetch file bytes use the same HTTP client. URLs come from API responses (presigned storage URLs, task output url fields, skill or knowledge file links) or from arguments you pass on the command line.

Allowed URLs

  • Schemes: https everywhere; http only for loopback hosts (localhost, 127.0.0.1, ::1) or for the same origin as your configured API endpoint (typical for a local API on http://127.0.0.1:3020).
  • Host required: Relative paths, file://, ftp://, and other schemes are rejected.

Presigned third-party URLs (for example Cloudflare R2 or S3) must use https.

API credentials on download

When the download URL points at the configured inference API (same scheme and host as INFERENCE_API_KEY / login target, with a matching API path prefix), the CLI sends your session or API key (Authorization, X-Team-ID, and cookies when present).

For any other host — including presigned object storage — those headers are not sent. Matching uses the parsed URL origin, not a string prefix on the URL, so lookalike hosts such as https://api.inference.sh.evil.example do not receive your credential.

If the server responds with a redirect, the CLI follows up to five hops. Each hop is checked with the same URL rules. When a redirect leaves the original request origin, Authorization, Cookie, and X-Team-ID are stripped before the next hop (presigned URLs should not rely on inference auth).

Common errors

MessageTypical cause
unsupported schemeNon-HTTP(S) URL, or a relative path passed where a full URL is required
https requiredPlain http to a non-loopback, non-API host (for example http://example.com/file)
stopped after 5 redirectsRedirect loop or a chain longer than five hops
missing hostMalformed URL

For command syntax and examples, see CLI — Files and CLI — Output files.


List Files

POST /files/list

Cursor-paginated list of files in your workspace. GET /files accepts the same query parameters.

Request body

FieldTypeDescription
limitnumberPage size (default 10)
cursorstringPagination cursor from a previous response
directionstringnext or prev
filtersarrayField filters (for example content_type with like operator)
searchobject{ "term", "fields" } for substring match (CLI --search / -q searches filename)

Response

Standard cursor list shape: items (array of file DTOs), has_next, has_previous, next_cursor, prev_cursor.

CLI equivalent: belt file list (add --json for the raw payload; --type image filters by MIME category; --search photo or -q avatar filters by filename).


Delete File

DELETE /files/{id}

Delete a file by ID. Its URI stops resolving, and workspace credentials cannot restore it. Requires files:write scope.

While live content still uses the file (a knowledge entry or skill version, an artifact, an app, agent or flow card image), delete answers 409 file_in_use and the file stays. meta names the users:

json
1{2  "type": "https://api.inference.sh/errors/file_in_use",3  "status": 409,4  "meta": {5    "file_id": "file_abc123",6    "total": 2,7    "users": [8      { "kind": "knowledge", "id": "kn_xyz", "name": "myteam/my-skill" },9      { "kind": "artifact", "id": "art_abc", "name": "quarterly-report" }10    ]11  }12}

total counts every user; users lists at most 10. kind is knowledge, artifact, app, agent or flow. A user you cannot read shows only its kind, with name set to a private <kind> and no id. Remove the file from those resources, or delete them, then try again.

CLI equivalent: belt file delete <id> (add --force or --yes to skip the confirmation prompt; it does not get past file_in_use).

To find the IDs of the files behind a task's input and output URLs, use GET /tasks/:id/files. To delete all of a task's files in one call, use DELETE /tasks/:id/files.


Read a file by storage key

GET /files/{key} · HEAD /files/{key}

Skill and knowledge versions list their files with a uri on this route (for example https://api.inference.sh/files/app/knowledge/…/SKILL.md). It checks that you may read the file, then redirects (302) to a short-lived storage URL. Public files need no key; others need a session or API key that can read them. App package keys (app/repos/…) open only with the signed ?token= the API hands out; a bad or expired token answers 401 file_token_invalid.

Add ?inline=1 to get the bytes from the API itself instead of a redirect. Browsers need this, since the storage URL has no CORS. Inline works only for knowledge and skill files (others answer 400 inline_unsupported) up to 10 MiB (larger answers 413 file_too_large). Text types such as Markdown, plain text, JSON and YAML are served for display; every other type is sent as an attachment.

bash
1curl -L -H "Authorization: Bearer inf_your_key" \2  "https://api.inference.sh/files/app/knowledge/…/helper.py"

Using Uploaded Files

Use the returned uri in task inputs:

bash
1curl -X POST https://api.inference.sh/run \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{5    "app": "image-processor",6    "input": {7      "image": "inf://files/abc123/image.png"8    }9  }'

Supported Types

Common MIME types:

  • image/png, image/jpeg, image/webp
  • audio/mpeg, audio/wav
  • video/mp4
  • application/pdf
  • text/plain

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.