# ApifyStorageBackend<!-- -->

Bridges `apify-client`'s synchronous resource accessors (`dataset(id)`, `keyValueStore(id)`, `requestQueue(id, options?)`) to crawlee v4's `StorageBackend` interface (async factory methods accepting an `id`, a `name`, or an `alias`).

Retries of storage calls are the client's — configure them on the `ApifyClient`. Request queue calls also end early when the caller's `signal` aborts.

`Actor` wires this up automatically; construct it directly only to use Apify platform storage with crawlee's storage classes outside of `Actor` — e.g. to read another run's output with an explicit token:

```
import { ApifyClient, ApifyStorageBackend, Dataset } from 'apify';



const client = new ApifyClient({ token });

const dataset = await Dataset.open(datasetId, { storageBackend: new ApifyStorageBackend(client) });

const { items } = await dataset.getData();
```

### Implements

* StorageBackend

## Index[](#Index)

### Constructors

* [constructor](#constructor)

### Accessors

* [stats](#stats)

### Methods

* [createDatasetBackend](#createDatasetBackend)
* [createKeyValueStoreBackend](#createKeyValueStoreBackend)
* [createRequestQueueBackend](#createRequestQueueBackend)
* [getStorageBackendCacheKey](#getStorageBackendCacheKey)
* [storageExists](#storageExists)

## Constructors<!-- -->[](#Constructors)

### [](#constructor)[](https://github.com/apify/apify-sdk-js/blob/56d34bf548452109719e494db05860534d997e43/src/apify_storage_backend.ts#L113)constructor

* **new ApifyStorageBackend**(client, options): [ApifyStorageBackend](https://docs.apify.com/sdk/js/reference/class/ApifyStorageBackend.md)

- #### Parameters

  * ##### client: [ApifyClient](https://docs.apify.com/sdk/js/reference/class/ApifyClient.md)
  * ##### options: [ApifyStorageBackendOptions](https://docs.apify.com/sdk/js/reference/interface/ApifyStorageBackendOptions.md) = <!-- -->{}

  #### Returns [ApifyStorageBackend](https://docs.apify.com/sdk/js/reference/class/ApifyStorageBackend.md)

## Accessors<!-- -->[](#Accessors)

### [](#stats)[](https://github.com/apify/apify-sdk-js/blob/56d34bf548452109719e494db05860534d997e43/src/apify_storage_backend.ts#L130)stats

* get stats(): undefined | { rateLimitErrors: number\[] }

- Implementation of StorageBackend.stats

  Lets crawlee's storage load signal see the API's rate-limit errors.

  ***

  #### Returns undefined | { rateLimitErrors: number\[] }

## Methods<!-- -->[](#Methods)

### [](#createDatasetBackend)[](https://github.com/apify/apify-sdk-js/blob/56d34bf548452109719e494db05860534d997e43/src/apify_storage_backend.ts#L152)createDatasetBackend

* **createDatasetBackend**(options): Promise\<DatasetBackend\<Dictionary>>

- Implementation of StorageBackend.createDatasetBackend

  Create (or open) a dataset backend. If `id` is provided, opens the dataset with that ID. If `name` is provided, opens an existing dataset with that name or creates a new one. If neither is provided, opens or creates the default dataset.

  ***

  #### Parameters

  * ##### optionaloptions: StorageIdentifier

  #### Returns Promise\<DatasetBackend\<Dictionary>>

### [](#createKeyValueStoreBackend)[](https://github.com/apify/apify-sdk-js/blob/56d34bf548452109719e494db05860534d997e43/src/apify_storage_backend.ts#L157)createKeyValueStoreBackend

* **createKeyValueStoreBackend**(options): Promise\<KeyValueStoreBackend>

- Implementation of StorageBackend.createKeyValueStoreBackend

  Create (or open) a key-value store backend. If `id` is provided, opens the key-value store with that ID. If `name` is provided, opens an existing store with that name or creates a new one. If neither is provided, opens or creates the default key-value store.

  ***

  #### Parameters

  * ##### optionaloptions: StorageIdentifier

  #### Returns Promise\<KeyValueStoreBackend>

### [](#createRequestQueueBackend)[](https://github.com/apify/apify-sdk-js/blob/56d34bf548452109719e494db05860534d997e43/src/apify_storage_backend.ts#L162)createRequestQueueBackend

* **createRequestQueueBackend**(options): Promise\<RequestQueueBackend>

- Implementation of StorageBackend.createRequestQueueBackend

  Create (or open) a request queue backend. If `id` is provided, opens the request queue with that ID. If `name` is provided, opens an existing queue with that name or creates a new one. If neither is provided, opens or creates the default request queue.

  ***

  #### Parameters

  * ##### optionaloptions: StorageIdentifier

  #### Returns Promise\<RequestQueueBackend>

### [](#getStorageBackendCacheKey)[](https://github.com/apify/apify-sdk-js/blob/56d34bf548452109719e494db05860534d997e43/src/apify_storage_backend.ts#L125)getStorageBackendCacheKey

* **getStorageBackendCacheKey**(): string

- Implementation of StorageBackend.getStorageBackendCacheKey

  Partitions crawlee's storage-instance cache by API base URL and token, so the same storage opened through two differently-authenticated backends is cached separately. The request queue access mode is deliberately not part of the key — opening the same queue in `single` and `shared` mode at once is not supported, and whichever backend opens it first wins.

  ***

  #### Returns string

### [](#storageExists)[](https://github.com/apify/apify-sdk-js/blob/56d34bf548452109719e494db05860534d997e43/src/apify_storage_backend.ts#L142)storageExists

* **storageExists**(id, type): Promise\<boolean>

- Implementation of StorageBackend.storageExists

  Check whether a storage with the given ID exists.

  Used internally to resolve ambiguous `idOrName` strings passed to `Dataset.open()`, `KeyValueStore.open()`, and `RequestQueue.open()`.

  ***

  #### Parameters

  * ##### id: string
  * ##### type: StorageType

  #### Returns Promise\<boolean>
