Need help with balena-sdk?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

123 Stars 37 Forks Apache License 2.0 2.3K Commits 78 Opened issues


The SDK to make balena powered JavaScript applications.

Services available


Need anything else?

Contributors list

Balena SDK

The official JavaScript balena SDK.

npm version dependencies Build Status Build status


The intention of this module is to provide developers a nice API to integrate their JavaScript applications with balena.


Install the balena SDK by running:

$ npm install --save balena-sdk


We currently support NodeJS (10+) and the browser.

The following features are node-only: - OS image streaming download (
), - balena settings client (

In Node you can simply

, but in the browser things are more complicated. The balena SDK provides a bundled single file for browsers, which allows you to include a single file with all dependencies included, available as balena-browser.min.js (or balena-browser.js if you'd like the much larger unminified version). This uses the UMD format, and will register itself as either a CommonJS or AMD module called
if possible, or create a
global if not. You can also use the
version if desired.

Bundling for browsers

If you're using webpack, browserify, or a similar tool then you probably want to bundle the balena SDK into your application yourself, rather than using the pre-built

bundle. If you do that, you should be aware that you may pick up some dependencies that are actually unnecessary in the browser, because they're only used in Node environments. You can safely exclude these dependencies, if you're not using them yourself, and significantly reduce the size of your resulting bundle.

In the browser the balena SDK doesn't use the following dependencies:

  • fs
  • path
  • balena-settings-client
  • node-localstorage

For the future we're looking at ways to automatically exclude these in downstream bundles. See #254 for more information.

Bundling with pkg

The balena SDK includes builds for various ECMAScript versions that are dynamically selected at runtime (using @balena/es-version). For this reason, packagers like pkg are not able to automatically detect which assets to include in the output package. The following sample

section should be added to your application's
file to instruct
to bundle the required assets:
  "pkg": {
    "scripts": [
    "assets": [

For more information, please refer to the respective documentation from the



The module exports a single factory function. Use it like this:

var balena = require('balena-sdk')({
    apiUrl: "",
    dataDirectory: "/opt/local/balena"

Where the factory method accepts the following options: *

, string, optional, is the balena API url. Defaults to
, *
, string, optional , is the balena builder url. Defaults to
, *
, string, optional, is the base balena device API url. Defaults to
, *
, string, optional, ignored in the browser, is the directory where the user settings are stored, normally retrieved like
. Defaults to
, *
, boolean, optional, is the flag to tell if the module works in the browser. If not set will be computed based on the presence of the global
value, *
, boolean, optional, when set will print some extra debug information.

See the JSDoc markdown documentation for the returned

object in


If you face any issues, please raise an issue on GitHub and the balena team will be happy to help.

Deprecation policy

The balena SDK uses semver versioning, with the concepts of major, minor and patch version releases.

The latest release of the previous major version of the balena SDK will remain compatible with the balenaCloud backend services for one year from the date when the next major version is released. For example, balena SDK v12.33.4, as the latest v12 release, would remain compatible with the balenaCloud backend for one year from the date when v13.0.0 is released.

At the end of this period, the older major version is considered deprecated and some of the functionality that depends on balenaCloud services may stop working at any time. Users are encouraged to regularly update the balena SDK to the latest version.


In order to run the balena SDK test suite, set the following environment variables from an account that exists and doesn't have a billing account code: WARNING: This will delete all applications and public keys of the test users. As such, all emails are required to contain the string

to avoid accidental deletion

    : The main account email.
    : The main account password.
    : The main account username.
    : The email of the account for the membership tests.
    : The password of the account for the membership tests.
    : The username of the account for the membership tests.

You also have to provide the following environment variables from an account that doesn't yet exist:

    : The email of the account to register.
    : The password of the account to register.
    : The username of the account to register.

In order to test the billing methods for a paid account, you also have to configure the following environment variables:

    : The email of the paid account.
    : The password of the account.

Note: The paid user's

account billing code
should be set to
so that it's tested against the test plan.

You can also, optionally, set the

environment variable in order to run the tests using a different API backend (eg:

You can persist these settings by putting them all into a

file in the root of this repo, in dotenv format (
). This will be automatically detected and used in the tests. Make sure you don't accidentally commit this file (
by default is gitignored, so hopefully this should be difficult).

Run the test suite by doing:

$ npm test

In order to make the develop & test cycle faster: * You can use mocha's

variants to only run the subset of the test cases that is relevant to your changes/additions. You should make sure to remove those from your code before you push and make sure that the complete test suite completes successfully. * You can use

npm run test:fast
which fixes linting issues, only builds for a single ES target and runs the tests only on node. This can save time when implementing a method that interacts with an API endpoint, but should be avoided if the feature might work different or only in the browser.


Before submitting a PR, please make sure that you * don't have uncommited changes on the documentation or the build output * don't have any

in your tests * include typings for new methods * include tests and that they pass
$ npm test


The project is licensed under the Apache 2.0 license.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.