UploadKit
SDK@uploadkitdev/core

API Reference

Complete API reference for @uploadkitdev/core — all types, methods, and error codes.

createUploadKit

Factory function. Creates and returns an UploadKitClient.

function createUploadKit(config: UploadKitConfig): UploadKitClient

UploadKitConfig

PropertyTypeRequiredDefaultDescription
apiKeystringYesAPI key prefixed uk_live_ or uk_test_.
baseUrlstringNo'https://api.uploadkit.dev'Override the API endpoint.
maxRetriesnumberNo3Retry attempts on transient failures. 0 disables retries.

UploadKitClient

The main SDK client. Created by createUploadKit().

Methods

MethodSignatureDescription
upload(options: UploadOptions) => Promise<UploadResult>Upload a file. Automatically uses multipart for files >10 MB.
listFiles(options?: ListFilesOptions) => Promise<ListFilesResult>List files for this API key's project.
deleteFile(key: string) => Promise<void>Permanently delete a file by its storage key.

upload

client.upload(options: UploadOptions): Promise<UploadResult>

UploadOptions

PropertyTypeRequiredDescription
fileFileYesThe file to upload.
routestringYesRoute name from your server-side file router.
metadataRecord<string, unknown>NoJSON-serializable metadata forwarded to onUploadComplete.
onProgress(percentage: number) => voidNoCalled with progress percentage (0–100).
signalAbortSignalNoCancellation signal from AbortController.

UploadResult

PropertyTypeDescription
idstringUploadKit file ID.
keystringStorage key (e.g. 'imageUploader/abc123/photo.jpg'). Use for deletion.
namestringOriginal filename.
sizenumberFile size in bytes.
typestringMIME type (e.g. 'image/jpeg').
urlstringCDN URL for the file.
statusstringUpload status — 'completed' on success.
metadataRecord<string, unknown>Metadata returned from onUploadComplete, if any.
createdAtstringISO 8601 timestamp.

listFiles

client.listFiles(options?: ListFilesOptions): Promise<ListFilesResult>

ListFilesOptions

PropertyTypeDefaultDescription
limitnumber20Maximum number of files to return (1–100).
cursorstringPagination cursor from a previous response's nextCursor.

ListFilesResult

PropertyTypeDescription
filesUploadResult[]Array of file records for the current page.
nextCursorstring | undefinedPass as cursor in the next call to get the next page. undefined means no more pages.

deleteFile

client.deleteFile(key: string): Promise<void>

Permanently deletes the file with the given storage key. Returns Promise<void> on success. Throws UploadKitError on failure (including 404 if the file does not exist).


UploadKitError

Thrown by all client methods on API or network errors. Import from @uploadkitdev/core.

import { UploadKitError } from '@uploadkitdev/core';

try {
  await client.upload({ file, route: 'imageUploader' });
} catch (err) {
  if (err instanceof UploadKitError) {
    console.error(err.code, err.message, err.status);
  }
}

UploadKitError properties

PropertyTypeDescription
codestringMachine-readable error code (e.g. 'FILE_TOO_LARGE', 'INVALID_FILE_TYPE', 'UNAUTHORIZED').
messagestringHuman-readable error description.
statusnumberHTTP status code from the API.
suggestionstringActionable hint for resolving the error.

Common error codes

CodeStatusWhen it occurs
MISSING_API_KEY400createUploadKit() called without apiKey.
UNAUTHORIZED401Invalid or revoked API key.
FILE_TOO_LARGE413File exceeds the route's maxFileSize.
INVALID_FILE_TYPE415MIME type not in the route's allowedTypes.
ROUTE_NOT_FOUND404Route name does not exist in your file router.
UPLOAD_FAILED500Unexpected error during upload.

Internal types

These types are exported for advanced use cases (custom wrappers, testing). The SDK does not rely on them being stable.

UploadRequestResponse

Internal response from POST /api/v1/upload/request (single-part upload).

PropertyTypeDescription
fileIdstringID of the pending file record.
uploadUrlstringPresigned PUT URL for direct-to-storage upload.
keystringStorage key for the file.
cdnUrlstringCDN URL that will serve the file after upload.

MultipartInitResponse

Internal response from POST /api/v1/upload/multipart/init (files >10 MB).

PropertyTypeDescription
fileIdstringID of the pending file record.
uploadIdstringMultipart upload ID (from R2/S3).
keystringStorage key for the file.
partsArray<{ partNumber: number; uploadUrl: string }>Array of presigned PUT URLs, one per part.

VERSION

import { VERSION } from '@uploadkitdev/core';
// '0.1.0'

On this page