---
title: TypeScript SDK
summary: The TypeScript and JavaScript SDK generated from the OpenAPI document (npm @bimworks/sdk) — installation, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
order: 30
languages: [typescript]
terms: [sdk, openapi, api-token, auth-token, scope]
see-also: [reference/sdk, how-to/install/javascript, api, reference/javascript]
---

# TypeScript SDK

The TypeScript [[term:sdk|SDK]] is generated from the [[term:openapi|OpenAPI]] document: one API class per group of operations, one method per operation, and an interface per request and response. It is written in TypeScript and runs as JavaScript too, in Node.js and in browsers, over `fetch`. A page with the 3D or 2D viewer uses the [[page:reference/javascript|classic JavaScript SDK]] instead, which the viewers take.

## Package {#package}

| | |
|---|---|
| Package | `@bimworks/sdk` on `https://npm.bim.works`, version equal to your BIM.works server |
| Runtime | Node.js 20 or later (global `fetch`, `FormData` and `File`), or a current browser |
| TypeScript | 5 or later; the package ships its `.d.ts` files |
| Module | One package; import every class and function from `@bimworks/sdk` |

```text {#npmrc}
@bimworks:registry=https://npm.bim.works
```

```shell {#install}
npm install @bimworks/sdk@3.0.0-beta.192
```

The registry needs your company credentials ([[page:how-to/install/javascript]]). The examples are ES modules with top-level `await`: give your `package.json` `"type": "module"`. To type-check them, use a `tsconfig.json` with `"lib": ["es2022", "dom"]` (the package's types name `fetch` types from the DOM library) and, on Node.js, `"types": ["node"]`.

## Connect and log in {#connect}

A `Configuration` holds the address of your instance's OpenAPI root (`BIM_WORKS_ADDRESS/openapi`) and the bearer token. The login, [[openapi:LoginWithApiToken]] with your [[term:api-token|API token]], answers an `AuthResult`: the `Auth` object, whose `base64` is the [[term:auth-token|auth token]], or that token alone when you ask for `response_format: "base64"`. A `Configuration` cannot change, so the login uses one without a token and the client one with it; every API class is made from that client.

```sdk-example {#quick-start}
operation: GetRootNodeUuid
languages: typescript
```

## Every example in four steps {#example-shape}

Every example on these pages and on the operation pages of the [[page:api|API part]] is a complete program in the same four steps ([[page:reference/sdk#example-shape]]):

1. **Connect** — the client, logged in as above. An operation that needs no login (the logins, [[openapi:GetApplicationVersion]]) skips the login.
2. **The request** — `<Model>FromJSON(json)` makes the request from the JSON with the wire names that the operation's page shows. Multipart operations take their form fields as one object instead.
3. **The call** — `await new <Api>(client).<method>({ <request parameter>: request })`.
4. **The result** — `<Model>ToJSON(result)` turns a result back into the JSON with the wire names, which the example prints; a file is written to disk, and a call without a result prints `Done`.

So the same JSON goes into every language, and copying an example is enough once the package is installed. With several calls, keep one client and repeat steps 2 to 4.

## Classes {#classes}

<table class="dense">
<thead><tr><th>Class</th><th>Group</th><th>Methods</th></tr></thead>
<tbody>
<tr><td>[[page:reference/sdk/typescript/actionsapi|ActionsApi]]</td><td>Actions</td><td>[[page:reference/sdk/typescript/actionsapi#addaction|addAction]], [[page:reference/sdk/typescript/actionsapi#deleteaction|deleteAction]], [[page:reference/sdk/typescript/actionsapi#getaction|getAction]], [[page:reference/sdk/typescript/actionsapi#listactions|listActions]], [[page:reference/sdk/typescript/actionsapi#undeleteaction|undeleteAction]], [[page:reference/sdk/typescript/actionsapi#updateaction|updateAction]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/linkeddataapi|LinkedDataApi]]</td><td>Linked data</td><td>[[page:reference/sdk/typescript/linkeddataapi#addlinktargets|addLinkTargets]], [[page:reference/sdk/typescript/linkeddataapi#confirmlinkmatch|confirmLinkMatch]], [[page:reference/sdk/typescript/linkeddataapi#deletelinkeddata|deleteLinkedData]], [[page:reference/sdk/typescript/linkeddataapi#downloadlinkeddata|downloadLinkedData]], [[page:reference/sdk/typescript/linkeddataapi#endlink|endLink]], [[page:reference/sdk/typescript/linkeddataapi#getlinkeddata|getLinkedData]], [[page:reference/sdk/typescript/linkeddataapi#getlinkeddatacounts|getLinkedDataCounts]], [[page:reference/sdk/typescript/linkeddataapi#getlinkeddatapolicy|getLinkedDataPolicy]], [[page:reference/sdk/typescript/linkeddataapi#linkdata|linkData]], [[page:reference/sdk/typescript/linkeddataapi#listlinkeddata|listLinkedData]], [[page:reference/sdk/typescript/linkeddataapi#reattachlink|reattachLink]], [[page:reference/sdk/typescript/linkeddataapi#replacelinkeddata|replaceLinkedData]], [[page:reference/sdk/typescript/linkeddataapi#restorelinkeddata|restoreLinkedData]], [[page:reference/sdk/typescript/linkeddataapi#unlinkdata|unlinkData]], [[page:reference/sdk/typescript/linkeddataapi#updatelinkeddata|updateLinkedData]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/modelapi|ModelApi]]</td><td>Model</td><td>[[page:reference/sdk/typescript/modelapi#addmodelwithurl|addModelWithUrl]], [[page:reference/sdk/typescript/modelapi#augmentbcf|augmentBcf]], [[page:reference/sdk/typescript/modelapi#download|download]], [[page:reference/sdk/typescript/modelapi#downloadifcxml|downloadIfcXml]], [[page:reference/sdk/typescript/modelapi#exportgeometry|exportGeometry]], [[page:reference/sdk/typescript/modelapi#exportvectorsvg|exportVectorSvg]], [[page:reference/sdk/typescript/modelapi#getcheckin|getCheckin]], [[page:reference/sdk/typescript/modelapi#getvalidationreport|getValidationReport]], [[page:reference/sdk/typescript/modelapi#lookupmodelhashes|lookupModelHashes]], [[page:reference/sdk/typescript/modelapi#render|render]], [[page:reference/sdk/typescript/modelapi#schemaconversionreport|schemaConversionReport]], [[page:reference/sdk/typescript/modelapi#uploadmodel|uploadModel]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/accountapi|AccountApi]]</td><td>Account</td><td>[[page:reference/sdk/typescript/accountapi#changepassword|changePassword]], [[page:reference/sdk/typescript/accountapi#getsettings|getSettings]], [[page:reference/sdk/typescript/accountapi#listreferencevalues|listReferenceValues]], [[page:reference/sdk/typescript/accountapi#logout|logout]], [[page:reference/sdk/typescript/accountapi#register|register]], [[page:reference/sdk/typescript/accountapi#requestpasswordreset|requestPasswordReset]], [[page:reference/sdk/typescript/accountapi#requestvalidationemail|requestValidationEmail]], [[page:reference/sdk/typescript/accountapi#savesettings|saveSettings]], [[page:reference/sdk/typescript/accountapi#signoutothersessions|signOutOtherSessions]], [[page:reference/sdk/typescript/accountapi#validateemailaddress|validateEmailAddress]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/ifcapi|IFCApi]]</td><td>IFC - Industry Foundation Classes</td><td>[[page:reference/sdk/typescript/ifcapi#check|check]], [[page:reference/sdk/typescript/ifcapi#committransaction|commitTransaction]], [[page:reference/sdk/typescript/ifcapi#comparemodels|compareModels]], [[page:reference/sdk/typescript/ifcapi#compareobjects|compareObjects]], [[page:reference/sdk/typescript/ifcapi#deletecomparepairoverride|deleteComparePairOverride]], [[page:reference/sdk/typescript/ifcapi#exportcompareresult|exportCompareResult]], [[page:reference/sdk/typescript/ifcapi#getcomparebul|getCompareBul]], [[page:reference/sdk/typescript/ifcapi#getcompareresult|getCompareResult]], [[page:reference/sdk/typescript/ifcapi#getmatchcandidates|getMatchCandidates]], [[page:reference/sdk/typescript/ifcapi#getobjecthistory|getObjectHistory]], [[page:reference/sdk/typescript/ifcapi#getversionchanges|getVersionChanges]], [[page:reference/sdk/typescript/ifcapi#listbuildingstoreys|listBuildingStoreys]], [[page:reference/sdk/typescript/ifcapi#listcomparepairoverrides|listComparePairOverrides]], [[page:reference/sdk/typescript/ifcapi#mapqids|mapQids]], [[page:reference/sdk/typescript/ifcapi#parsequery|parseQuery]], [[page:reference/sdk/typescript/ifcapi#query|query]], [[page:reference/sdk/typescript/ifcapi#recorduploadastransaction|recordUploadAsTransaction]], [[page:reference/sdk/typescript/ifcapi#resolvebvl|resolveBvl]], [[page:reference/sdk/typescript/ifcapi#setcomparepairoverride|setComparePairOverride]], [[page:reference/sdk/typescript/ifcapi#textsearch|textSearch]], [[page:reference/sdk/typescript/ifcapi#upgradesyntax|upgradeSyntax]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/gisapi|GISApi]]</td><td>GIS - Geographic Information Systems</td><td>[[page:reference/sdk/typescript/gisapi#copygeoreference|copyGeoReference]], [[page:reference/sdk/typescript/gisapi#exportcitygml3|exportCityGML3]], [[page:reference/sdk/typescript/gisapi#extractgeoreference|extractGeoReference]], [[page:reference/sdk/typescript/gisapi#generate3dtilesurl|generate3DTilesUrl]], [[page:reference/sdk/typescript/gisapi#getgeoreference|getGeoReference]], [[page:reference/sdk/typescript/gisapi#setgeoreference|setGeoReference]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/authapi|AuthApi]]</td><td>Auth - Authentication</td><td>[[page:reference/sdk/typescript/authapi#createanonymoustoken|createAnonymousToken]], [[page:reference/sdk/typescript/authapi#createapitoken|createApiToken]], [[page:reference/sdk/typescript/authapi#createnodestoken|createNodesToken]], [[page:reference/sdk/typescript/authapi#createrecursivenodetoken|createRecursiveNodeToken]], [[page:reference/sdk/typescript/authapi#createversionstoken|createVersionsToken]], [[page:reference/sdk/typescript/authapi#deleteapitoken|deleteApiToken]], [[page:reference/sdk/typescript/authapi#getsession|getSession]], [[page:reference/sdk/typescript/authapi#listapitokens|listApiTokens]], [[page:reference/sdk/typescript/authapi#loginanonymous|loginAnonymous]], [[page:reference/sdk/typescript/authapi#loginwithanonymoustoken|loginWithAnonymousToken]], [[page:reference/sdk/typescript/authapi#loginwithapitoken|loginWithApiToken]], [[page:reference/sdk/typescript/authapi#loginwithusernamepassword|loginWithUsernamePassword]], [[page:reference/sdk/typescript/authapi#updateapitoken|updateApiToken]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/fsapi|FsApi]]</td><td>Fs - FileSystem</td><td>[[page:reference/sdk/typescript/fsapi#createnode|createNode]], [[page:reference/sdk/typescript/fsapi#deletenode|deleteNode]], [[page:reference/sdk/typescript/fsapi#deletenodeerror|deleteNodeError]], [[page:reference/sdk/typescript/fsapi#deleteversion|deleteVersion]], [[page:reference/sdk/typescript/fsapi#downloadaszip|downloadAsZip]], [[page:reference/sdk/typescript/fsapi#getnode|getNode]], [[page:reference/sdk/typescript/fsapi#getrootnodeuuid|getRootNodeUuid]], [[page:reference/sdk/typescript/fsapi#getversion|getVersion]], [[page:reference/sdk/typescript/fsapi#listnodeerrors|listNodeErrors]], [[page:reference/sdk/typescript/fsapi#listnodes|listNodes]], [[page:reference/sdk/typescript/fsapi#listnodesrecursive|listNodesRecursive]], [[page:reference/sdk/typescript/fsapi#listversions|listVersions]], [[page:reference/sdk/typescript/fsapi#movenode|moveNode]], [[page:reference/sdk/typescript/fsapi#undeletenode|undeleteNode]], [[page:reference/sdk/typescript/fsapi#updatenode|updateNode]], [[page:reference/sdk/typescript/fsapi#updateversion|updateVersion]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/workspacesapi|WorkspacesApi]]</td><td>Workspaces</td><td>[[page:reference/sdk/typescript/workspacesapi#createworkspace|createWorkspace]], [[page:reference/sdk/typescript/workspacesapi#deleteworkspace|deleteWorkspace]], [[page:reference/sdk/typescript/workspacesapi#listworkspaces|listWorkspaces]], [[page:reference/sdk/typescript/workspacesapi#publishworkspace|publishWorkspace]], [[page:reference/sdk/typescript/workspacesapi#updateworkspace|updateWorkspace]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/infoapi|InfoApi]]</td><td>Info</td><td>[[page:reference/sdk/typescript/infoapi#getapplicationversion|getApplicationVersion]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/viewerapi|ViewerApi]]</td><td>Viewer</td><td>[[page:reference/sdk/typescript/viewerapi#getgeometrymetadata|getGeometryMetaData]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/adminapi|AdminApi]]</td><td>Admin</td><td>[[page:reference/sdk/typescript/adminapi#listaccountuserfeatures|listAccountUserFeatures]], [[page:reference/sdk/typescript/adminapi#listaccounts|listAccounts]], [[page:reference/sdk/typescript/adminapi#listorganizations|listOrganizations]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/aiapi|AIApi]]</td><td>AI - Artificial Intelligence</td><td>[[page:reference/sdk/typescript/aiapi#texttoaction|textToAction]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/versionsapi|VersionsApi]]</td><td>Versions</td><td>[[page:reference/sdk/typescript/versionsapi#version|version]]</td></tr>
<tr><td>[[page:reference/sdk/typescript/models|Models]]</td><td>Requests and responses</td><td>289 model classes</td></tr>
</tbody>
</table>

A model is an interface with camelCase properties (`versionUuid`); `<Model>FromJSON` and `<Model>ToJSON` convert between it and the wire's snake_case JSON. `FromJSON` reads only the names it knows: a misspelled key, an explicit `null` or a model item with a wrong `type` is left out of the request, so use the names on the [[page:reference/sdk/typescript/models|models page]].

## Errors {#errors}

A call that the server answers with an error status throws a `ResponseError`; its `response` is the HTTP response, whose JSON is the server's error ([[page:api/errors]]).

```typescript {#error-example}
import { ResponseError } from "@bimworks/sdk";

try {
  await new IFCApi(client).query({ queryRequest: request });
} catch (e) {
  if (e instanceof ResponseError) {
    console.error(e.response.status, await e.response.json());
  } else {
    throw e;
  }
}
```

## Files {#files}

- **Downloads** return a `Blob`; the examples write it with `writeFileSync(path, Buffer.from(await result.arrayBuffer()))`. For a large file, stream it instead: the `…Raw` variant of every method (`downloadRaw`) gives the `Response`, whose `body` you pipe to a file.
- **Uploads** take a `File`: `new File([await openAsBlob("model.ifc")], "model.ifc")` reads the file lazily and gives the part its name, which the server uses as the model's name when no `filename` field is sent (a bare `Blob` would arrive as `blob`).
- [[openapi:UploadModel]] with `wait_ms` can answer `202` with the checkin's status instead of the version; `uploadModelRaw` gives the status and the body to tell them apart.
