MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / serve

Function serve

uncommon_route/proxy.py:5982–6053  ·  view source on GitHub ↗

Start the proxy server (blocking).

(
    port: int = DEFAULT_PORT,
    host: str = "127.0.0.1",
    upstream: str | None = DEFAULT_UPSTREAM,
    spend_control: SpendControl | None = None,
    route_stats: RouteStats | None = None,
)

Source from the content-addressed store, hash-verified

5980
5981
5982def serve(
5983 port: int = DEFAULT_PORT,
5984 host: str = "127.0.0.1",
5985 upstream: str | None = DEFAULT_UPSTREAM,
5986 spend_control: SpendControl | None = None,
5987 route_stats: RouteStats | None = None,
5988) -> None:
5989 """Start the proxy server (blocking)."""
5990 import uvicorn
5991
5992 if os.environ.get("UNCOMMON_ROUTE_DEBUG_ROUTING"):
5993 logging.basicConfig(level=logging.DEBUG, format="%(name)s %(message)s")
5994 _debug_log.setLevel(logging.DEBUG)
5995
5996 app = create_app(
5997 upstream=upstream,
5998 spend_control=spend_control,
5999 route_stats=route_stats,
6000 )
6001 effective = resolve_primary_connection(
6002 cli_upstream=str(upstream or "").strip() or None,
6003 store=ConnectionsStore(),
6004 )
6005 providers = load_providers()
6006 base = f"http://{host}:{port}"
6007 bar = "─" * 45
6008
6009 has_dashboard = False
6010 try:
6011 import importlib.resources as _pr
6012 has_dashboard = (_pr.files("uncommon_route") / "static" / "index.html").is_file()
6013 except Exception: # noqa: BLE001
6014 pass
6015
6016 print()
6017 print(f" UncommonRoute v{VERSION}")
6018 print(f" {bar}")
6019 if effective.upstream:
6020 short = effective.upstream.replace("https://", "").replace("http://", "").rstrip("/v1").rstrip("/")
6021 print(f" Upstream: {short}")
6022 print(f" Proxy: {base}")
6023 if has_dashboard:
6024 print(f" Dashboard: {base}/dashboard/")
6025 print()
6026 print(" Quick test:")
6027 print(f" curl {base}/health")
6028 elif providers.providers:
6029 names = ", ".join(sorted(providers.providers.keys()))
6030 print(" Upstream: (not configured)")
6031 print(f" BYOK: {names}")
6032 print(f" Proxy: {base}")
6033 if has_dashboard:
6034 print(f" Dashboard: {base}/dashboard/")
6035 print()
6036 print(" Ready in BYOK mode:")
6037 print(" Requests will use your configured provider keys.")
6038 print(" Run `uncommon-route doctor` to review the active setup.")
6039 else:

Callers 1

_cmd_serveFunction · 0.90

Calls 6

ConnectionsStoreClass · 0.90
load_providersFunction · 0.90
create_appFunction · 0.85
runMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected