---
title: Classic JavaScript SDK
summary: The classic, hand-written JavaScript SDK (the @bimworks/jssdk package) that the viewers build on — installation, the client factory and its login methods, the sub-APIs of a client, error handling, Node.js differences, and the generated TypeScript reference.
order: 91
languages: [javascript, typescript]
terms: [sdk, qid, api-token, auth-token]
see-also: [reference/sdk/typescript, reference/sdk, how-to/install/javascript, how-to/auth/log-in-with-an-api-token, how-to/query/run-a-bql-query]
---

# Classic JavaScript SDK

```note title="Classic SDK"
This is the classic, hand-written JavaScript [[term:sdk|SDK]]. The 3D and 2D viewers build on it, so a page with a viewer uses it. For an integration without a viewer, the [[page:reference/sdk/typescript|TypeScript SDK]] (`@bimworks/sdk`, for TypeScript and JavaScript) is generated from the OpenAPI document; [[page:reference/sdk]] compares the two.
```

`@bimworks/jssdk` is the classic API client for browsers and Node.js. The viewers (`@bimworks/viewer3d`, `@bimworks/viewer2d`, `@bimworks/viewercommon`) build on it; installing all of them is described in [[page:how-to/install/javascript]].

## Package {#package}

| | |
|---|---|
| Package | `@bimworks/jssdk` on `https://npm.bim.works` (scope `@bimworks`; `@sascom` for the transport packages it depends on) |
| Version | The same as your BIM.works server; the version pill at the top of this page is the server's |
| Module format | ES modules only (no ES5 or UMD builds); single-file builds exist for pages without a build step ([[page:how-to/install/downloads]]) |
| Requirements | A current browser, or Node.js 22.4 or later (the Node.js entry point uses the built-in `WebSocket`, stable since 22.4) |
| Types | `jssdk.d.ts` ships in the package |

## Client factory {#factory}

`BimWorksClientFactory(address[, settings])` is created once per application with the instance URL; every `create*` method returns a promise of a logged-in `BimWorksClient`.

| Method | Logs in with |
|---|---|
| `createClientWithApiToken(apiToken)` | An [[term:api-token|API token]] — the normal way for an application. |
| `createClientWithUsernamePassword(username, password)` | A user's credentials; for testing. |
| `createClientWithAuth(auth)` | An [[term:auth-token|auth token]] obtained elsewhere (a versions or nodes token, a token issued by your backend). |
| `createAnonymousClient()` | No credentials; a very small set of calls is allowed. |

```javascript {#factory-example}
import {BimWorksClientFactory} from "@bimworks/jssdk";

const factory = new BimWorksClientFactory("BIM_WORKS_ADDRESS");
const client = await factory.createClientWithApiToken("BIM_WORKS_API_TOKEN");
const results = await client.bim.query(["BIM_WORKS_FIRST_MODEL"], "GET qid, attribute.Name WHERE type = IFCWALL");
console.log(results);
client.close();
```

`client.registerExpiredTokenHandler(fn)` is called when the token expires, `client.addConnectionRestoredListener(fn)` after a reconnect, and `client.close()` releases the connection.

## Sub-APIs {#apis}

A client is a set of API objects, each a class in the TypeScript reference:

| Property | Class | What it does |
|---|---|---|
| `client.auth` | `Auth` | Account registration (`register`); the factory handles login. |
| `client.fs` | `Fs` | Nodes and versions: root node, paths, listing, creating, moving, deleting, node errors. |
| `client.upload` | `Upload` | Uploading a model from a `File`, a dropped item, an `ArrayBuffer` or (Node.js) a file name, with progress; `uploadFromUrl` fetches a URL in the page (same-origin, or from a server that allows the page's origin) and uploads the bytes. |
| `client.bim` | `Bim` | BQL: `query`, `queryCount`, `queryQids`, `validateQuery`, grouped queries and disciplines. |
| `client.ifc` | `Ifc` | IFC downloads (original, converted to another schema, ifcXML), IFC exports, and model compare (`compareModels` and the calls around it). |
| `client.checks` | `Checks` | Running model checks and IDS checks, fetching results. |
| `client.tokens` | `Tokens` | Versions, nodes and recursive-node tokens, and single-call 3D geometry download tokens. `queryDelegated` only posts a payload under the client's own credential ([[term:delegated-query|delegated query]]). |
| `client.gis` | `Gis` | Geo-references (reading, setting, copying from another version, and extracting them from an EPSG code, WKT, `IfcSite` or `IfcMapConversion`), CityGML 2 and 3 exports and 3D Tiles URLs. |
| `client.geometry3d` | `Geometry3d` | Geometry metadata, glTF downloads, alignments (`setAlignment`, `calculateAlignment`) and the semantics of DWG and PDF models. |
| `client.render` | `Render` | Server-side renders and snapshots. |
| `client.info` | `Info` | The server's application version (`getApplicationVersion`) and what the server made of the client's identification (`getClientInfo`). |
| `client.ai` | `Ai` | Natural-language text-to-action (`textToAction`). |

The viewers add `ModelManager`, which takes the client, and `ObjectStateManager` (both `@bimworks/viewercommon`), which drive `Viewer3d` and `Viewer2d`; `Qid`, `QidSet` and `QidMap` are the identifier types every call returns and accepts ([[term:qid]]).

## Errors {#errors}

Most API calls return a promise. The calls built on the transport's `execAsPromise()`, such as `Bim.query`, `Ai.textToAction` and the `Fs` and `Tokens` calls, reject on failure with an object `{task, error, response}`: `task` is the request's task (`task.taskName` names the server task that failed), `error` the server's error (its code, the constant's name, the enumeration and the message — the same codes as the [[page:api/errors|OpenAPI]] envelope) and `response` the raw response. `Render.render`, `Render.renderToStillImage`, the `Checks` downloads (`downloadCheckResultsAsBcf`, `downloadCheckResultsAsBcfDirect`, `downloadCheckGltf`) and `executePreSignedDownload` reject with the same object, also when the server answers without a download. `Auth.register`, the download and export calls (`Ifc.exportIfc`, `Geometry3d.downloadGltf`, …) and the `Gis` extract, CityGML and 3D Tiles calls reject with the server's error itself. `try`/`catch` around an `await` handles a rejection; codes are listed on the [[page:reference/errors|error codes]] page. Methods such as `close()` and `Bim.setVirtualFeatures()` return synchronously; `Checks.runChecksAsTask()` returns a transport `Task`, which is sent when you call its `execAsPromise()` (or `exec()` after `success` and `error` handlers).

```javascript {#error-example}
try {
  await client.bim.query(["BIM_WORKS_FIRST_MODEL"], "GET qid WHERE type = IFCWAL");
} catch (failure) {
  console.error(failure.task.taskName, failure.error); // Query2 …
}
```

## Node.js {#node}

Node.js selects the package's Node entry point automatically for `import {BimWorksClientFactory} from "@bimworks/jssdk"`; uploads from Node go over HTTP instead of the WebSocket transport. Logging is configured with `log.setLogger` and `bimworks.setLogLevel`.

JavaScript and TypeScript use the same package and API. TypeScript declarations include the client's `auth`, `info`, `ai` and reconnect callback, and `Bim.queryCount`; the catalogue below documents these members alongside the runtime APIs.

## Generated reference {#generated}

The [[page:reference/javascript/api|JavaScript API catalogue]] is generated from the `.d.ts` files of `@bimworks/jssdk`, `@bimworks/viewercommon`, `@bimworks/viewer3d`, `@bimworks/viewer2d` and the `@sascom` transport packages. Types and members share this site's navigation, styling and search, including signatures, overloads, parameters and remarks.

## Used in {#used-in}

- [[page:how-to/install/javascript]] — registry, packages, import maps.
- [[page:how-to/auth/log-in-with-an-api-token]] — the factory and the token.
- [[page:how-to/query/run-a-bql-query]] — `client.bim.query`.
