> ## Documentation Index
> Fetch the complete documentation index at: https://studio.bjanczak.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript and TypeScript SDK

> Use a lightweight, workspace-bound REST client independently of React and Filament.

The API client is exported from `@useflex/media-studio/api`. It has no React runtime dependency. In this development checkout, import `packages/react/dist/api.js` after building. Package publication and installation availability are separate from the local build.

```ts theme={null}
import {createStudioApi, StudioApiError} from '@useflex/media-studio/api';

const studio = createStudioApi({
  baseUrl: 'https://your-app.example/media-studio/rest/v1',
  workspace: process.env.STUDIO_WORKSPACE!,
  token: () => process.env.STUDIO_API_TOKEN!,
  timeoutMs: 30_000,
});

const first = await studio.files({limit: 20});
if (first.nextCursor) {
  const next = await studio.files({limit: 20, cursor: first.nextCursor});
}
```

## Folder and file operations

```ts theme={null}
const folder = await studio.createFolder('Brand assets');
const page = await studio.files({parent: folder.id, limit: 20});
const file = page.items[0];
if (file) {
  const updated = await studio.rename(file.id, 'New filename.png', file.revision);
  await studio.trash(updated.id, updated.revision);
}
```

## Upload a file

```ts theme={null}
const source = new Blob([await fs.readFile('./cover.png')]);
const file = await studio.upload(source, 'cover.png', 'cover-import-attempt-0001');
```

Keep the same retry key when retrying the same upload. For larger files use the documented resumable upload endpoints through `studio.request()`. A chunk is sent as raw bytes with its SHA-256 header; direct S3 parts use the URL returned by the sign operation and must not receive the Studio bearer token.

## Call another documented endpoint

```ts theme={null}
const comments = await studio.request(`entries/${file.id}/comments`);
const controller = new AbortController();
const page = await studio.files({limit: 20}, controller.signal);
// controller.abort() cancels this request.
```

`request<T>()` accepts a relative path inside the configured workspace, plus `method`, `body`, `headers` and `signal`. It returns bounded JSON; use a streaming HTTP client for binary file downloads. JSON responses larger than 4 MiB are rejected and their stream is cancelled.

## Handle failures

```ts theme={null}
try {
  await studio.createFolder('Campaign');
} catch (error) {
  if (error instanceof StudioApiError && error.status === 429) {
    console.log('Retry after', error.retryAfter, 'seconds');
  }
  throw error;
}
```

The client omits browser cookies, rejects redirects that could forward credentials, applies a timeout and never automatically retries mutations. Use returned data URLs only with an appropriate delivery client; externally configured CDN redirects are not followed by the JSON client.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.