Skip to content

Files API ​

The Files API is bucket-based. Files live in buckets, and buckets are backed by providers (S3-compatible storage, Azure Blob, etc).

text
files.providers   → manage the underlying storage providers (admin-level)
files.buckets     → list / inspect available buckets
files                → CRUD on objects inside a bucket

Buckets ​

client.files.buckets.list() ​

typescript
const { buckets, count } = await client.files.buckets.list();

client.files.buckets.get(bucketKey) ​

typescript
const { bucket } = await client.files.buckets.get('user-uploads');

Objects ​

client.files.list(bucketKey, query?) ​

typescript
const { files, count, nextCursor } = await client.files.list('user-uploads', {
  limit: 50,
  search: 'invoice',
});

Browse by folder ​

Browse a bucket by folder with prefix (a path such as agent-sessions/support-bot/; a trailing / is added when missing; '' is the root). The answer then lists the folder's files and its sub-folders:

typescript
const { files, folders, prefix } = await client.files.list('user-uploads', {
  prefix: 'agent-sessions/support-bot/',
  purpose: 'conversation', // only files attached to agent sessions; 'other' = only the rest
});
// folders: ['agent-sessions/support-bot/<sessionId>/', ...]
QueryDescription
searchMatch by name. With prefix, every match under it, however deep
limit / cursorPagination (nextCursor in the answer)
prefixList one folder. The answer adds folders (sub-folder paths ending in /) and prefix (the folder, normalised)
purpose'conversation' — only files attached to agent sessions; 'other' — only the rest

Files that agents keep for their sessions are ordinary objects here: they carry purpose: 'conversation', conversationId, agentKey, expiresAt and uploadedBy. Manage them through client.agents.sessions.files; a bucket an agent keeps session files in cannot be deleted or disabled until the agent uses another one (409 bucket_in_use from the Files management API).

client.files.upload(bucketKey, data) ​

Upload a file using a base64 / data-URL payload. Set convertToMarkdown: true to ask the server to extract markdown text from PDFs and other documents.

typescript
import { readFileSync } from 'node:fs';

const pdf = readFileSync('./report.pdf');

const { file } = await client.files.upload('user-uploads', {
  fileName: 'report.pdf',
  contentType: 'application/pdf',
  data: pdf.toString('base64'),
  convertToMarkdown: true,
});

console.log(file.markdownContent?.slice(0, 200));

keyHint chooses the key the file is stored under. A keyHint that ends in / names a folder: the file is stored in it under a generated name. Any other keyHint is the whole key, and uploading to a key that already has a file replaces that file. It is text of at most 512 characters with no . or .. segment, no control characters and no unpaired surrogate; the server refuses anything else with 400. Without a keyHint the key is generated from fileName. The rules, with their messages, are under Keys in the Files API reference.

typescript
const { file } = await client.files.upload('user-uploads', {
  fileName: 'report.pdf',
  contentType: 'application/pdf',
  data: pdf.toString('base64'),
  keyHint: '2026/q3/', // stored as 2026/q3/<generated name>
});

client.files.get(bucketKey, objectKey) ​

typescript
const { file } = await client.files.get('user-uploads', 'report.pdf');

client.files.delete(bucketKey, objectKey) ​

typescript
await client.files.delete('user-uploads', 'report.pdf');

client.files.download(bucketKey, objectKey) ​

Returns the raw bytes plus the response Content-Type header.

typescript
import { writeFileSync } from 'node:fs';

const { data, contentType } = await client.files.download('user-uploads', 'report.pdf');
writeFileSync('./local-report.pdf', data);
console.log(contentType); // application/pdf

Providers ​

client.files.providers.list(query?) ​

typescript
const providers = await client.files.providers.list({ status: 'active' });

client.files.providers.create(data) ​

typescript
const provider = await client.files.providers.create({
  key: 'tenant-minio',
  driver: 's3-compatible-files',
  label: 'Tenant files (MinIO)',
  credentials: { accessKeyId: '…', secretAccessKey: '…' },
  settings: { endpoint: 'https://minio.internal:9000', bucket: 'tenant-files' },
});

The driver ids are s3-compatible-files, aws-s3-files (Amazon S3), azure-blob-files, mongodb-gridfs-files and local-filesystem. Secrets go in credentials (stored encrypted, never returned); bucket, endpoint and the other options go in settings. The fields of each driver, the sign-in methods of Azure Blob and the errors a refused value answers with (provider_settings_invalid, provider_endpoint_not_allowed, with the field to change) are listed under Create a file provider in the Files API reference.

Available from the next Console release

The s3-compatible-files and azure-blob-files drivers, and the validation of keyHint, arrive with the next Console release.

Types ​

typescript
interface FileBucket {
  _id: string;
  key: string;
  name: string;
  description?: string;
  provider: string;
  status: string;
  metadata?: Record<string, unknown>;
  createdAt: string;
  updatedAt: string;
}

interface FileObject {
  _id: string;
  key: string;
  bucketKey: string;
  fileName: string;
  contentType: string;
  size: number;
  metadata?: Record<string, unknown>;
  markdownContent?: string | null;
  createdAt: string;
  updatedAt: string;
}

interface UploadFileRequest {
  fileName: string;
  contentType?: string;
  data: string;             // base64 or data URL
  metadata?: Record<string, unknown>;
  convertToMarkdown?: boolean;
  keyHint?: string;
}

interface FileProvider {
  _id: string;
  key: string;
  driver: string;
  label: string;
  description?: string;
  status: string;
  credentials?: Record<string, unknown>;
  settings?: Record<string, unknown>;
  metadata?: Record<string, unknown>;
  capabilities?: string[] | Record<string, unknown>;
  createdAt?: string;
  updatedAt?: string;
}
  • Vectors API — indexed knowledge bases on top of buckets.
  • OCR API — extract text from files without persisting them.
  • Chat API — feed file contents into conversations.

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub