Skip to content

Move remaining app_api imports out of inference_api to complete service decoupling #120

@colinmxs

Description

@colinmxs

Summary

The Inference API (inference_api) still has direct Python imports from app_api modules. This was originally a much larger problem (7+ modules), and most have been migrated to apis.shared. Three imports remain and should be moved to complete the separation.

Remaining Imports

In backend/src/apis/inference_api/chat/converse_routes.py:

from apis.app_api.costs.calculator import CostCalculator
from apis.app_api.costs.pricing_config import create_pricing_snapshot
# Lazy import inside _validate_api_key()
from apis.app_api.auth.api_keys.service import get_api_key_service

Impact

  • Inference API Docker image must include app_api code
  • App API log namespaces (apis.app_api.*) appear in AgentCore Runtime CloudWatch logs
  • Changes to app_api cost or auth modules can break inference_api
  • Cannot test inference_api in true isolation

Proposed Fix

Move the remaining modules to apis.shared:

  1. apis.app_api.costs.calculatorapis.shared.costs.calculator
  2. apis.app_api.costs.pricing_configapis.shared.costs.pricing_config
  3. apis.app_api.auth.api_keys.serviceapis.shared.auth.api_keys (or have inference_api validate API keys via an HTTP call to app_api)

Update imports in both app_api and inference_api to use the shared location.

Context

This is the last piece of a long-running effort to decouple the two services. The original issue (identified Jan 2025) had 7+ cross-service imports. Most were resolved by creating apis.shared.sessions, apis.shared.files, apis.shared.rbac, etc. These three are the stragglers.

Acceptance Criteria

  • No from apis.app_api imports exist anywhere in backend/src/apis/inference_api/
  • Cost calculator and pricing config live in apis.shared
  • API key validation either lives in apis.shared or uses an HTTP call
  • Existing tests pass
  • Inference API Docker image can be built without app_api source (stretch goal)

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech debtNot Critical: fix eventually

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions