Skip to main content
The Palyra HTTP Transport Layer is built on the axum framework and serves as the primary gateway for web-based management, canvas interactions, and third-party LLM integrations. It handles request routing, authentication via session cookies and bearer tokens, CSRF protection, and multi-tier rate limiting.

Router Architecture

The central router is constructed in crates/palyra-daemon/src/transport/http/router.rs and divides the API surface into four distinct domains, each with its own middleware stack and security requirements.

API Surface Overview

API DomainPath PrefixPurposeAuth Mechanism
Admin API/admin/v1/*System-level control and diagnostics.Bearer Token / Custom Headers
Console API/console/v1/*Backend for the React Web Console.Session Cookie + CSRF Header
Canvas API/canvas/v1/*Interactive UI component streaming.Session Cookie
OpenAI Compat/v1/*OpenAI-compatible completions API.API Key (Bearer)
Web UI/Static asset serving for the dashboard.Public (Internal Redirects)

Router Construction Data Flow

The build_router function crates/palyra-daemon/src/transport/http/router.rs#17-17 composes these routes and applies specialized layers. Sources: crates/palyra-daemon/src/transport/http/router.rs#17-258, crates/palyra-daemon/src/transport/http/middleware.rs#28-204

Security and Middleware

Authentication and Session Management

The daemon supports several authentication flows:
  1. Admin Bearer Auth: Used by the CLI and local tools. Validates the Authorization: Bearer <token> header against the configured admin_token crates/palyra-daemon/tests/admin_surface.rs#19-19.
  2. Console Sessions: Issued via /console/v1/auth/login. It sets a SET_COOKIE header with a secure, HTTP-only session token crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#105-106.
  3. CSRF Protection: Console mutations require a x-palyra-csrf-token header which is validated against the session state stored in AppState.console_sessions crates/palyra-daemon/src/app/state.rs#50-50.

Rate Limiting

Rate limiting is enforced at the IP level for Admin and Canvas APIs, and at the Token level for the Compatibility API.

Security Headers

The apply_admin_console_security_headers function crates/palyra-daemon/src/transport/http/middleware.rs#37-37 injects protective headers:
  • Cache-Control: no-store
  • X-Content-Type-Options: nosniff
  • X-Frame-Options: DENY
  • Content-Security-Policy: frame-ancestors 'none'
Sources: crates/palyra-daemon/src/transport/http/middleware.rs#37-52, crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#19-111, crates/palyra-daemon/src/app/state.rs#44-46

API Surface Details

Admin API (/admin/v1)

Provides low-level access to the daemon’s internal state.

Console API (/console/v1)

Supports the Web Console’s rich features.

OpenAI Compatibility API (/v1)

Implements the OpenAI Chat Completions and Models schema to allow drop-in replacement for existing AI tools.

Code Entity Mapping

This diagram associates natural language API concepts with the specific Rust structs and handlers in the codebase. Sources: crates/palyra-daemon/src/app/state.rs#30-61, crates/palyra-daemon/src/transport/http/router.rs#17-157, crates/palyra-daemon/src/transport/http/middleware.rs#1-204

Implementation Flow: Console Login

The following sequence describes the transition from raw HTTP request to an established session. Sources: crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#19-111, crates/palyra-daemon/src/app/state.rs#73-73

Static Asset Serving

The Web UI is served via web_ui_entry_handler crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#16-16. It attempts to resolve the dashboard root from the following locations:
  1. PALYRA_WEB_DIST_DIR environment variable crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#13-13.
  2. The web/ directory relative to the executable crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#135-135.
  3. The apps/web/dist path within the repository crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#138-138.
If assets are missing, it serves a fallback HTML page indicating the dashboard is unavailable crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#36-111. Sources: crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#1-210