AccessRegistry for token-based authorization, the OpenAI-compatible API surface, and the management of provider credentials via the openai_auth surface.
AccessRegistry and Token Authorization
TheAccessRegistry is the central authority for managing feature flags, API tokens, and workspace-level permissions within the daemon. It persists state to a JSON file and enforces Role-Based Access Control (RBAC) through predefined permissions associated with WorkspaceRole levels.
Workspace Roles and Permissions
Permissions are granular strings used to gate specific API handlers. The system defines three primary roles:| Role | Description | Key Permissions |
|---|---|---|
Owner | Full control over the daemon and workspaces. | api_tokens.manage, workspace.manage, trust.operate |
Admin | Management of memberships and tokens. | api_tokens.manage, workspace.memberships.manage |
Operator | Standard usage of agent features. | compat.chat.create, sessions.use, memory.use |
[crates/palyra-daemon/src/access_control.rs#74-135](http://crates/palyra-daemon/src/access_control.rs#74-135), [crates/palyra-daemon/src/access_control.rs#24-36](http://crates/palyra-daemon/src/access_control.rs#24-36)
Token Implementation
API tokens are represented byApiTokenRecord objects. Authentication involves verifying a token prefix and a SHA-256 hash of the full secret.
- Rate Limiting: Every token can define a
rate_limit_per_minute(default 120) crates/palyra-daemon/src/access_control.rs#16-16. - Scopes: Tokens are restricted to specific permission strings stored in the
scopesvector crates/palyra-daemon/src/access_control.rs#157-157.
Access Control Data Flow
The following diagram illustrates how a request is authorized using theAccessRegistry.
Figure 1: Access Control Authorization Flow
Sources: [crates/palyra-daemon/src/transport/http/handlers/compat.rs#105-121](http://crates/palyra-daemon/src/transport/http/handlers/compat.rs#105-121), [crates/palyra-daemon/src/access_control.rs#151-173](http://crates/palyra-daemon/src/access_control.rs#151-173)
OpenAI Compatibility Surface
Palyra provides an OpenAI-compatible HTTP surface located at/v1/*. This allows existing tools and SDKs designed for OpenAI to interact with Palyra agents as if they were standard models.
Key Endpoints
/v1/chat/completions: Proxies chat requests to the PalyraGatewayService. It supports both standard and streaming responses crates/palyra-daemon/src/transport/http/handlers/compat.rs#128-175./v1/models: Returns a list of available models based on the currentModelProviderstatus crates/palyra-daemon/src/transport/http/handlers/compat.rs#105-126./v1/responses: A Palyra-specific extension for non-chat completions crates/palyra-daemon/src/transport/http/handlers/compat.rs#177-233 .
Implementation Detail: prepare_compat_run
When a request hits the compatibility surface, the daemon converts the OpenAI-formatted payload into a Palyra Run. This involves:
- Authorization: Calling
authorize_compat_api_tokencrates/palyra-daemon/src/transport/http/handlers/compat.rs#110-110. - Prompt Rendering: Converting the
messagesarray into a single prompt string viarender_compat_messages_promptcrates/palyra-daemon/src/transport/http/handlers/compat.rs#133-133. - Run Creation: Initializing a
TonicRequestto the internal gRPCRunStreamcrates/palyra-daemon/src/transport/http/handlers/compat.rs#78-88.
[crates/palyra-daemon/src/transport/http/handlers/compat.rs#1-100](http://crates/palyra-daemon/src/transport/http/handlers/compat.rs#1-100)
OpenAI Auth and API Key Management
Theopenai_auth surface handles the secure acquisition and storage of API keys for providers like OpenAI and Anthropic. It ensures that raw keys are never stored in plain text in the main configuration.
Credential Storage via Vault
When a user connects an API key (e.g., via the Web Console), the following occurs:- Validation: The daemon performs a pre-flight check against the provider’s
/v1/modelsendpoint to ensure the key is valid crates/palyra-daemon/src/openai_surface.rs#34-40. - Vaulting: The key is stored in the
palyra-vault. Only aVaultRef(a secure reference) is stored in theAuthProfileViewcrates/palyra-daemon/src/openai_surface.rs#42-57. - Profile Creation: An
AuthProfileViewis persisted, associating theVaultRefwith aprofile_idand ascope(Global or Agent-specific) crates/palyra-daemon/src/openai_surface.rs#61-61.
Code Entity Mapping: Auth Flow
The following diagram maps the UI actions in the React Console to the backend Rust functions. Figure 2: API Key Connection Flow Sources:[apps/web/src/console/hooks/useAuthDomain.ts#130-166](http://apps/web/src/console/hooks/useAuthDomain.ts#130-166), [crates/palyra-daemon/src/openai_surface.rs#18-78](http://crates/palyra-daemon/src/openai_surface.rs#18-78), [crates/palyra-cli/src/commands/auth.rs#20-23](http://crates/palyra-cli/src/commands/auth.rs#20-23)
Dangerous Remote Bind Guards
For security, Palyra implements “dangerous remote bind” guards. If the daemon is configured to bind to a non-loopback interface (making it accessible over the network), it requires explicit acknowledgement.- Security Audit: The CLI
security auditcommand checks for remote binds without TLS crates/palyra-cli/src/commands/security.rs#169-177. - Acknowledgements: Users must acknowledge the risk via the
dangerous_remote_bind_acksetting in the config or thePALYRA_DANGEROUS_REMOTE_BIND_ACKenvironment variable crates/palyra-cli/src/commands/security.rs#179-185.
[crates/palyra-cli/src/commands/security.rs#152-190](http://crates/palyra-cli/src/commands/security.rs#152-190)