---
title: Tokens and delegation
summary: API tokens versus auth tokens, what a login creates, the tokens a backend issues for a browser, anonymous tokens, scopes, expiry and the BIM context.
order: 50
featured: true
see-also: [explanation/accounts-and-organisations, how-to/auth, how-to/auth/create-an-api-token, how-to/auth/log-in-with-an-api-token, how-to/auth/create-a-versions-token, how-to/auth/refresh-an-expired-token, api]
terms: [api-token, auth-token, scope, versions-token, nodes-token, recursive-node-token, anonymous-token, bim-context, node, delegated-query]
---

# Tokens and delegation

Every request to BIM.works carries a credential, and there are exactly two kinds: the long-lived secret you were given, and the short-lived signed token a login turns it into. Most confusion about BIM.works authentication comes from mixing the two up, so this page keeps them apart and then explains the tokens a backend creates for a browser — the pattern behind every embedded viewer. The step-by-step guides are under [[page:how-to/auth]].

## Two kinds of credential

An **[[term:api-token]]** is what an integration is given: a string of the form `BAT-` followed by forty hexadecimal characters, created by an account in the UI or through the API, bound to one node, and shown exactly once. It is a secret to keep in a vault or an environment variable. A username and password is the human equivalent.

An **[[term:auth-token]]** is what a login returns: a JSON object with a payload — who you are, what you may reach, when it expires — and an HMAC signature the server verifies on every call. It is not secret in the same way; it expires, and it is what the SDKs attach to every request and what the OpenAPI takes as a bearer credential. The API token itself is sent once, at login, and never again.

The distinction matters because everything downstream is designed around it: revocation and allow-lists apply to the API token record, which the server re-reads on every request; expiry and scopes are baked into the auth token; and a backend can mint auth tokens for others without ever handing out its API token.

## What a login creates

Logging in with an API token gives an auth token valid for ninety days (`auth.api_token_validity`), capped at the API token's own expiry date so a login blob never outlives the token it came from. Logging in with a username and password gives seven days, and ninety with "remember me", which returns a second token for that purpose. Signing in with a code sent by e-mail gives the same seven days, but "remember me" then lasts thirty (`sign_in.email_code.remember_validity`): the code is asked again once a month. An anonymous token gives one hour, a published workspace eight. When an auth token expires the client logs in again with the original credential; the SDKs have a hook for that, described in [[page:how-to/auth/refresh-an-expired-token]].

The auth token carries the API token's scopes, or the legacy READ/WRITE credentials mapped onto scopes for tokens created before scopes existed. It is checked twice per request: the signature and expiry from the token itself, then the API token's record — status, expiry, IP rules and, where the instance requires them, CORS rules — from the database. Deleting or expiring an API token therefore takes effect immediately, not when the auth tokens run out.

## API tokens {#api-tokens}

An API token is bound to a **[[term:node]]** and sees that node and everything below it, the way a chrooted process sees one directory as its root. This is the coarse access control: a token for the folder `Project X` cannot list, query or download anything outside it, whatever scopes it holds. Bind integration tokens to the narrowest folder that works.

**[[term:scope|Scopes]]** are the fine control: `fs:read`, `fs:write`, `model:read`, `model:write`, `model:upload`, `geometry:read`, `query:run`, `gis:read`, `gis:write`, `checks:read`, `checks:run`, `checks:write`, `checks:java`, `actions:read`, `actions:write`, `collab:read`, `collab:write`, `workspaces:read`, `workspaces:write`, `ai:use`, `bsdd:read`, `bsdd:sync`, `tokens:issue`, `account:read`, `account:write`, `admin:read`, `admin:write`, plus [[scope:superadmin]] and the universal [[scope:*]] (each described in the [[page:glossary/scope#all-scopes|scope table]]). Every task and every OpenAPI operation declares what it needs. `write` implies `read` within a family and nothing else is implied, so a token that uploads (`model:upload`) cannot edit (`model:write`) unless given both. [[scope:*]] covers everything except [[scope:superadmin]] and [[scope:system]], including scopes added in later releases — that auto-widening is its purpose and its risk, so anything narrower must be an explicit list. A token cannot be created with more scopes than its creator holds, and a few scopes are further gated by what the account has: a feature (the `bsdd` scopes need [[feature:BSDD]], `checks:java` needs [[feature:JAVA_ACTIONS]]), a module switched on for the instance, or ownership of an organisation — the *Needs* lines of the [[page:glossary/scope#all-scopes|scope table]] list every gate.

**Expiry** is mandatory. A token expires one month after creation unless the creator picks a date, and never more than three years out; reminders are e-mailed seven, three and one day before, and an expired token is refused at login and on every request. **Allow-lists** narrow where a token may be used from: `white_listed_ip_addresses` lists the addresses, with a flag that makes the list exclusive, and `cors_enabled_domains` the origins a browser may present it from. The origin list only counts on an instance whose `web_security.cors` is `REQUIRED`, where a browser origin is let in only when an active API token lists it; the default, `WILDCARD`, accepts every origin, and the token's `only_cors_enabled_addresses` flag is not enforced. Tokens created before credentials existed at all are refused with a message to regenerate them.

A token also carries a **[[term:bim-context]]**, explained below. Only an account creates API tokens: an API token issues the shorter-lived delegated tokens below, never another API token, which would outlive it.

## Tokens a backend issues for others {#issued-tokens}

The typical web integration has a backend that owns an API token and a page in a visitor's browser that must show a model. Putting the API token in the page is out of the question. Instead the backend logs in, asks the server for an auth token with a narrower reach and a short life, and hands that to the page. Three shapes exist, differing only in what they name:

- A **[[term:versions-token]]** names a fixed set of versions — the models the page may load.
- A **[[term:nodes-token]]** names a fixed set of nodes.
- A **[[term:recursive-node-token]]** names one node and everything below it, including nodes created later — the shape for a page that uploads into a folder.

All three take `expires_seconds` (required), a list of `scopes` — typically `geometry:read` for the viewers and `query:run` for queries, or `model:upload` for an upload page — optional `ip_addresses`, `lock_to_caller_ip` (`lock_to_called_ip` over HTTP) and `link_account`. The older `tasks` allow-list, a list of task names, still works but is deprecated: the response carries a notice, and scopes keep working when new tasks are added to a family whereas a task list has to be maintained.

Two rules keep delegation honest. *Issued ⊆ issuer*: a token can never hold more than the credential that created it, and when the issuer is scoped and no scopes are requested, the new token gets the issuer's scopes minus `tokens:issue` rather than an unscoped grant. *Auth tokens are terminal*: a versions token, a nodes token, an anonymous or a workspace authorisation cannot create further credentials, so delegation cannot chain and a leaked page token cannot be laundered into a fresh one. Only accounts and API tokens issue them, and only accounts create API tokens. No issued token outlives its issuer: `expires_seconds` is cut to 90 days (`auth.issued_token_max_validity`) and, for a token an API token issues, to that API token's own expiry.

## The pattern {#backend-issues-tokens}

The backend keeps the API token, decides which versions this visitor may see, calls the versions-token task with a short expiry and the minimal scopes, and puts the resulting JSON into the page. The page creates its client from that JSON (`createClientWithAuth` in the JavaScript SDK), loads the versions and runs its queries with the token's own rights; when it expires, the page asks the backend for a new one. Nothing secret leaves the backend, the token's blast radius is a handful of versions for a few minutes, and the server's per-request checks apply unchanged. [[page:how-to/auth/create-a-versions-token]] shows it in each SDK, and [[page:how-to/viewer3d/show-your-users-models]] builds the whole of it, backend endpoint and viewer page, with a live demo.

The **[[term:delegated-query]]** of older documentation — a backend signing one specific query for the browser to execute — is no longer supported; the server dropped that envelope. A versions token with `query:run` replaces it: the page runs the query itself, and the token limits what it can run against.

**Single-call signed handles** exist for one purpose: letting a browser `fetch` a download (viewer geometry, a query result, an upload target) with a URL. The `Generate…Token` tasks sign one exact task and input, require the underlying scope rather than `tokens:issue`, cannot be widened or re-delegated, and are minted by an account, an API token or a workspace session, never by an issued token. They are not a delegation mechanism.

## Anonymous tokens

Where an instance allows use without an account, an [[term:anonymous-token]] is the credential: created without any login when `features.anonymous_tokens` is on, prefixed `at-`, owning a private folder under `/Ephimeral`, and logging in for one hour at a time. It cannot issue tokens, and when the secret is lost so is the folder. It is a browser-side convenience for try-it deployments, not a way for software to authenticate.

## BIM context {#bim-context}

Every API token carries a `bim_context`, `DEFAULT` unless set otherwise, and every version uploaded with the token records it. A [[term:bim-context]] is a set of regional defaults for model processing — above all how the geo reference is extracted and which coordinate reference system a bare site placement is assumed to be in: `NL` (EPSG:7415), `MKM` (Estonia, EPSG:3301), `HONG_KONG` (EPSG:2326), `GB` (EPSG:27700), and `DEFAULT`, which reads `IfcMapConversion` and falls back to the `IfcSite` latitude and longitude. Putting the context on the token means a customer's integration gets its country's conventions on every upload without passing them each time. [[page:explanation/geo-referencing-in-ifc]] has the details of what each method reads.

## Choosing

Use username and password only for people and for trying things out. Give every integration its own API token, bound to the narrowest folder, with an explicit scope list and an expiry you will notice. Never put an API token in a browser; issue a versions or recursive-node token from a backend with the smallest scopes and the shortest life the page can live with, and refresh it. Use [[scope:*]] only for a trusted server-side integration that must keep working as the API grows. Leave `tasks` lists behind when you touch old code.
