Sub topic 16
Workspace-level versus account-level APIs
This chapter assumes you can authenticate the CLI with OAuth or a personal access token (PAT), that you know what a profile is, and that you have called a workspace REST endpoint with curl or Python. It explains the second set of Databricks APIs, the account-level ones, and shows how to tell which set a task needs.
Two scopes, two hosts
A Databricks deployment has two layers.
- A workspace is the environment where you run notebooks, jobs, clusters, and SQL warehouses. Each workspace has its own URL, such as
https://<workspace-host>. - An account sits above your workspaces. It holds the things that span them: the list of workspaces, users and groups, service principals, Unity Catalog metastores, and billing and usage data.
The REST API follows the same split. Workspace-level APIs are served from the workspace host. Account-level APIs are served from a separate account console host and include your account ID in the path. On AWS the account console host is https://accounts.cloud.databricks.com. Azure and GCP use different account console hosts, so check the documentation for your cloud.
| Property | Workspace-level API | Account-level API |
|---|---|---|
| Host | Workspace URL | Account console URL |
| Path | `/api/2.1/jobs/list` | `/api/2.0/accounts/<account-id>/...` |
| Typical resources | Jobs, clusters, notebooks, SQL warehouses | Workspaces, account users and groups, service principals, metastores |
| Who can call it | Users and service principals in that workspace | Account admins, or principals granted account-level roles |
| CLI profile needs | `host` | `host`, `account_id` |
A token or OAuth credential for one scope does not work for the other. A workspace PAT sent to the account host is rejected, and the reverse is also true. Most 401 and 403 errors in account automation come from using the wrong host or the wrong credential.
Why you would call account-level APIs
Typical automation tasks that need the account scope:
- Creating a service principal once and assigning it to several workspaces.
- Adding users to groups so the groups apply in every workspace they are assigned to.
- Creating or deleting workspaces as part of environment provisioning.
- Creating a Unity Catalog metastore and attaching it to workspaces.
- Pulling billable usage and audit data for the whole organization.
Tasks about running work, such as starting a job or resizing a cluster, stay at the workspace level.
Configuring a CLI profile for the account
The CLI decides which scope to use from the profile. A profile for the account console looks like this in ~/.databrickscfg:
[ACCOUNT]
host = https://accounts.cloud.databricks.com
account_id = <account-id>Log in with OAuth by passing both values. The CLI opens a browser and stores the profile:
databricks auth login \
--host https://accounts.cloud.databricks.com \
--account-id <account-id> \
--profile ACCOUNTAccount commands live under the databricks account command group. Pass the profile with -p:
databricks account workspaces list -p ACCOUNT
databricks account groups list -p ACCOUNT --output json \
| jq -r '.[] | "\(.id)\t\(.displayName)"'The jq pattern is the one from the scripting chapter. Only the profile and the command group changed.
The same databricks binary serves both scopes, and the profile selects which one is used. Keep one workspace profile and one account profile per environment, and name them clearly, for example prod-ws and prod-account. Running a workspace command with the account profile, or an account command with a workspace profile, fails with an error about the host or the missing account ID.
Calling account endpoints with curl and the `api` command
Account REST paths include the account ID. To list workspaces with a bearer token obtained through OAuth:
curl -sS "https://accounts.cloud.databricks.com/api/2.0/accounts/$DATABRICKS_ACCOUNT_ID/workspaces" \
-H "Authorization: Bearer $DATABRICKS_TOKEN"Here DATABRICKS_TOKEN holds an OAuth access token for the account, not a workspace PAT. Access tokens from OAuth expire after a short time, so a long-running script should refresh them. The CLI and SDK do this for you, which is one reason they are preferred over hand-built requests for account work.
The databricks api command works the same way as for workspace endpoints. It takes the host and credentials from the profile:
databricks api get "/api/2.0/accounts/$DATABRICKS_ACCOUNT_ID/workspaces" -p ACCOUNTResponses, pagination behavior, error bodies, and rate-limit handling follow the same patterns as in the earlier chapter on errors. Some account list endpoints return a bare JSON array rather than an object with a named field, so check the shape before writing a jq filter.
The SDK has a separate client
The Python SDK uses two client classes. WorkspaceClient talks to a workspace. AccountClient talks to the account console and needs the account ID.
from databricks.sdk import AccountClient
a = AccountClient(profile="ACCOUNT") # host and account_id come from the profile
for ws in a.workspaces.list():
print(ws.workspace_id, ws.workspace_name, ws.workspace_status)
for group in a.groups.list():
print(group.id, group.display_name)The AccountClient constructor can also read DATABRICKS_HOST and DATABRICKS_ACCOUNT_ID from the environment, using the same unified authentication rules as WorkspaceClient. If the host is not an account console host, calls fail, so a mismatch is caught early.
Some identity resources exist in both scopes. For example, you can list users in a workspace with w.users.list() and in the account with a.users.list(). The account list is the source of truth when identity federation is enabled. Workspace-level identity APIs show only what has been assigned to that workspace.
Choosing the right scope
Use these questions in order:
- Does the resource exist only inside one workspace, such as a job, notebook, or cluster? Use the workspace API.
- Does it span workspaces or define the workspaces themselves, such as a group, a metastore, or the workspace list? Use the account API.
- Can both scopes manage it, such as users or service principals? Prefer the account API when identity federation is on, so one change applies everywhere.
Permissions and least privilege
Account-level calls need an account-level role. Account admins can do everything in the account, so avoid using an admin identity for routine automation. Create a dedicated service principal for each automation purpose, give it only the roles it needs, and use separate service principals for account provisioning and for workspace deployments such as bundles. If a deployment pipeline is compromised, the attacker then gets workspace access but not the power to create workspaces or change who belongs to the account.
Common errors:
- Wrong host: an account command sent to a workspace URL returns a not-found or authentication error. Check the profile's
host. - Missing
account_id: account commands fail before sending a request. Add it to the profile or setDATABRICKS_ACCOUNT_ID. - Workspace PAT used for the account: returns 401. Switch to OAuth.
- Valid login but 403: the identity is not an account admin and lacks the role for that operation.
Exercise
A deployment script uses a profile with host = https://<workspace-host> and runs databricks account groups list. It fails. Name two changes that would make the call work, and say which scope each of your services would then use.
Show answer
The profile must point at the account console host (for AWS, https://accounts.cloud.databricks.com) and include account_id, and the identity must authenticate with OAuth and hold an account-level role such as account admin. You can fix this by creating a separate account profile and passing it with -p, for example databricks account groups list -p ACCOUNT. The account profile uses the account scope for group management. The original workspace profile remains correct for workspace commands such as databricks jobs list.
Exercise
Why should a CI pipeline that deploys bundles use a different service principal from the one that creates workspaces?
Show answer
Least privilege. The bundle deployment only needs workspace permissions, so its service principal should have no account-level roles. If its credentials leak, an attacker cannot create or delete workspaces or change account membership. The provisioning service principal holds the broader account role and runs only in a separate, tightly controlled pipeline.