docs/en/concepts/11-multi-tenant.md
OpenViking multi-tenancy does not mean "deploy one isolated server per team." Instead, a single OpenViking Server uses three identity boundaries, account, user, and agent, to control sharing and isolation.
This model fits two common scenarios:
With multi-tenancy enabled, you can:
accountresources within the same accountuseragent_idaccount_idaccount is the outer tenant boundary. You can think of it as a workspace, team, or customer space.
account values by defaultaccountsresources, user, agent, and session all live inside an accountuser_iduser is the per-account user boundary.
user_idaccountagent_idagent_id separates agent-level space.
isolate_agent_scope_by_user = false means viking://agent/{agent_id}/...isolate_agent_scope_by_user = true means viking://agent/{agent_id}/user/{user_id}/...| Role | Scope | Typical capabilities |
|---|---|---|
| ROOT | Global | Create/delete accounts, cross-tenant access, user management |
| ADMIN | Single account | Manage users in the same account, regenerate user keys |
| USER | Single account | Access its own user/agent/session data and shared resources in the same account |
OpenViking Server supports two multi-tenant related authentication modes:
| Mode | Config | Identity source | Typical use case |
|---|---|---|---|
api_key | server.auth_mode = "api_key" | Root key or user key | Standard deployment |
trusted | server.auth_mode = "trusted" | Upstream-injected X-OpenViking-Account / X-OpenViking-User | Behind a trusted gateway |
root_api_key DoesOnce server.root_api_key is configured, OpenViking enters formal multi-tenant mode:
account_id, user_id, and role from the user keyIf auth_mode = "api_key" and root_api_key is not configured, the server runs in dev mode:
default/default/default| Data type | Shared across accounts | Shared inside one account | Default isolation boundary |
|---|---|---|---|
resources | No | Yes | account |
user | No | No | user |
agent | No | Depends on account namespace policy | Default: agent |
session | No | No | user / session |
For users, URIs still look like normal viking://... paths:
viking://resources/project-a/
viking://user/alice/memories/
viking://agent/91f3ab12cd34/memories/
But the underlying storage automatically gains an account prefix:
/local/{account_id}/resources/project-a/
/local/{account_id}/user/alice/memories/
/local/{account_id}/agent/91f3ab12cd34/memories/
So multi-tenant isolation does not rely on a special public URI format. It relies on request context, account_id, user_id, and agent_id, applied consistently through the stack.
Semantic retrieval is tenant-aware as well:
account_idresources can include account-shared resourcesmemory and skill are further filtered by the current user space and agent spaceThis keeps "what you can search" aligned with "what you can read."
{
"server": {
"auth_mode": "api_key",
"root_api_key": "your-secret-root-key"
}
}
curl -X POST http://localhost:1933/api/v1/admin/accounts \
-H "Content-Type: application/json" \
-H "X-API-Key: your-secret-root-key" \
-d '{
"account_id": "acme",
"admin_user_id": "alice"
}'
curl -X POST http://localhost:1933/api/v1/admin/accounts/acme/users \
-H "Content-Type: application/json" \
-H "X-API-Key: <admin-or-root-key>" \
-d '{
"user_id": "bob",
"role": "user"
}'
For normal reads, writes, searches, and session commits, prefer a user key:
curl http://localhost:1933/api/v1/fs/ls?uri=viking:// \
-H "X-API-Key: <bob-user-key>" \
-H "X-OpenViking-Agent: coding-agent"
This lets the server resolve identity directly from the key, without extra tenant headers.
ROOT does not need tenant headers for Admin APIs, but it does need them for tenant-scoped data APIs such as ls, find, and sessions:
curl http://localhost:1933/api/v1/fs/ls?uri=viking:// \
-H "X-API-Key: <root-key>" \
-H "X-OpenViking-Account: acme" \
-H "X-OpenViking-User: alice" \
-H "X-OpenViking-Agent: coding-agent"
The current OpenClaw plugin follows a "plugin holds one user identity" model:
baseUrl + apiKey + agent_prefixapiKey should normally be a user keyaccount_id and user_id from that user keyX-OpenViking-AgentTypical config:
openclaw config set plugins.entries.openviking.config.mode remote
openclaw config set plugins.entries.openviking.config.baseUrl "http://your-server:1933"
openclaw config set plugins.entries.openviking.config.apiKey "<user-api-key>"
openclaw config set plugins.entries.openviking.config.agent_prefix "<agent-prefix>"
Characteristics of this model:
agent_prefix distinguishes different OpenClaw instances or agent rolesresources can be shared inside the same account, while user and agent memory stay identity-scopedaccount / userIn api_key mode, a user key is already enough to express identity:
account and user are resolved server-side from the keyagent_prefixuser and agent memory scopes from the runtime identityIf you give the plugin a root key directly, normal tenant-scoped data APIs will lack X-OpenViking-Account and X-OpenViking-User, so that is not a good default for day-to-day access.
Vikingbot uses a different practice. It behaves more like a platform serving many end users:
account_idExample config:
{
"bot": {
"ov_server": {
"server_url": "http://127.0.0.1:1933",
"root_api_key": "test",
"account_id": "default",
"admin_user_id": "default"
}
}
}
Characteristics of this model:
resources| Scenario | Recommended pattern |
|---|---|
| One OpenClaw instance maps to one fixed identity | OpenClaw plugin + user key |
| One gateway or bot service serves many end users | Vikingbot + root-key-managed users |
| A trusted gateway injects identity upstream | trusted mode |
| Local single-user experience without formal tenant isolation | Dev mode without root_api_key |
root_api_key is not the normal business-access keyThe root key is mainly for:
Normal application traffic should prefer user keys.
agentId does not define the tenantagentId only defines the agent-level space.
account_iduser_idagent_idroot_api_key does not mean "formal single-tenant production mode"That is only dev mode:
root_api_key, auth_mode, and agent_id