TypeScript SDK: Files

⚠️
Preview — this feature is being built; the design below is the spec.

Upload once, reference by id.

import Syntic from '@syntic/sdk'
 
const client = new Syntic() // reads SYNTIC_API_KEY
MethodEndpointReturns
files.uploadPOST /v1/filesFileObject
files.listGET /v1/filesSyncPage[FileObject]
files.retrieveGET /v1/files/{file_id}FileObject
files.contentGET /v1/files/{file_id}/contentBinaryResponse
files.deleteDELETE /v1/files/{file_id}FileDeleted

Methods

files.upload

Upload from a path, bytes or a file object. Multipart encoding is handled for you. Maps to POST /v1/files.

const result = await client.files.upload({
  path: "contract.pdf",
  purpose: "document"
})

files.list

List files, newest first, filtered by purpose. Maps to GET /v1/files.

for await (const item of client.files.list({
  purpose: "batch"
})) {
  console.log(item)
}

files.retrieve

Metadata for one file. Maps to GET /v1/files/{file_id}.

const result = await client.files.retrieve("file_01JC3D5F7H9K1M3P5R7T")

files.content

Download bytes. .write_to_file(path) streams to disk. Maps to GET /v1/files/{file_id}/content.

const result = await client.files.content("file_01JC3D5F7H9K1M3P5R7T")

files.delete

Delete a file. Maps to DELETE /v1/files/{file_id}.

const result = await client.files.delete("file_01JC3D5F7H9K1M3P5R7T")

Conventions

Every method accepts a final options object with headers, query, timeout, maxRetries and signal (an AbortSignal). List methods return pages that work with for await across all pages.

See the TypeScript SDK overview for installation, errors and retries.

Was this page helpful?