Skip to content

api.py blueprint is never registered — token endpoints and other routes are dead code #555

@swinney

Description

@swinney

Summary

src/interfaces/chat_app/api.py defines a Flask Blueprint with 20+ routes under /api, but register_api(app) is never called from app.py. All routes in this blueprint are unreachable at runtime.

This includes the token management endpoints needed for the OpenAI-compatible /v1 API:

  • POST /api/users/me/api-token — generate a bearer token
  • GET /api/users/me/api-token — check if user has a token
  • DELETE /api/users/me/api-token — revoke a token

Without these endpoints, there is no way for users to obtain an archi_ API token for authenticated access to /v1/chat/completions.

Root Cause

The codebase uses two Flask routing patterns:

  1. Legacyself.add_endpoint() calls in FlaskAppWrapper.__init__ (~50 routes in app.py)
  2. Blueprintregister_blueprint() used by openai_compat.py and service_alerts.py

api.py follows the blueprint pattern and defines register_api(app) at line 1157, but no code in app.py (or anywhere else) calls it.

Route Conflicts

Registering the full blueprint will cause 3 conflicts with existing add_endpoint() routes (same path + method):

Route app.py (legacy) api.py (blueprint) Notes
GET /api/health Always returns {"status": "OK"} — no real check Tests DB connectivity, returns 503 on failure Blueprint version is better
GET /api/agents/template Richer tool data (name + description), has auth Flat tool list, no auth decorator Legacy version is better
POST /api/agents Create + edit modes, auto-filenames, rename tracking, session auth Create only, manual filenames, weaker auth Legacy version is better

These must be resolved before wiring up the blueprint.

Suggested Fix

  1. Remove the 2 inferior duplicate routes from api.py (agents/template GET, agents POST) and their 5 now-dead helper functions (_get_agents_dir_from_config, _get_agent_class_name_from_config, _get_agent_tool_registry, _build_agent_template, _sanitize_filename)
  2. Remove the health stub from app.py's add_endpoint calls (let the blueprint's real DB health check replace it)
  3. Add register_api(self.app) in app.py next to the other blueprint registrations
  4. Clean up dead imports (os, Path, AgentSpecError, load_agent_spec)

Pyright Type Errors in api.py

The blueprint also has pre-existing type issues that should be fixed:

  • User model missing attributes: api_key_openrouter, api_key_openai, api_key_anthropic
  • display_name not a valid parameter in a constructor call
  • None passed where str expected (set_api_key, fromisoformat)
  • int passed where str | None expected (get_enabled_document_ids)

Impact

  • Users cannot generate API tokens for authenticated /v1 access
  • The real health check endpoint (with DB connectivity test) is unreachable
  • Config, analytics, document selection, and prompt management routes in the blueprint are all dead code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions