mstar.api_server.auth#
Optional API key for the HTTP and WebSocket surface.
Off unless --api-key or MSTAR_API_KEY sets a key. When set, every
request except the probe and scrape paths in UNAUTHENTICATED_PATHS must carry
Authorization: Bearer <key> (what the OpenAI SDKs send for api_key);
WebSocket routes are checked at the handshake. The check is one ASGI
middleware over the whole app rather than a per-route dependency, so a route
added later is covered without anyone remembering to opt it in.
Module Attributes
liveness probes from load balancers and orchestrators, and the Prometheus scrape endpoint (request counts, latencies and the model name; never prompts or outputs). |
Functions
|
Only the HTTP frontend needs the key. |
|
The deployment's key: |
|
Classes
|
Holds the key (if any) and checks a request's headers against it. |
|
Pure ASGI (not |
- class mstar.api_server.auth.APIKeyGuard(key=None)[source]#
Bases:
objectHolds the key (if any) and checks a request’s headers against it.
Mutable so the module-level app can install the middleware at import and the CLI can set the key once its flags are parsed.
- Parameters:
key (str | None)
- class mstar.api_server.auth.APIKeyMiddleware(app, guard)[source]#
Bases:
objectPure ASGI (not
BaseHTTPMiddleware), so it sees WebSocket scopes and never buffers a streamed response.- Parameters:
guard (APIKeyGuard)
- mstar.api_server.auth.UNAUTHENTICATED_PATHS = frozenset({'/health', '/metrics'})#
liveness probes from load balancers and orchestrators, and the Prometheus scrape endpoint (request counts, latencies and the model name; never prompts or outputs).
- Type:
Served without a key
- mstar.api_server.auth.keep_api_key_from_children(api_key)[source]#
Only the HTTP frontend needs the key. Drop it from the environment and
sys.argv(the spawn start method copies both into each child) before this process spawns the conductor, workers or media subprocesses.- Parameters:
api_key (str | None)
- Return type:
None