Spaces:
Sleeping
Sleeping
File size: 1,546 Bytes
d094faf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """ProxyEndpoint — single source of truth for "where is the proxy + what key".
Every agent runner reads this from environment, then hands the resulting
object to `agents.cliproxyapi.env.*` to build SDK-specific configuration.
Env vars:
CLIPROXYAPI_HOST default 127.0.0.1
CLIPROXYAPI_PORT default 8317 (CLIProxyAPI's stock port)
CLIPROXYAPI_KEY required — must match one of the api-keys: entries
in your CLIProxyAPI config.yaml
"""
from __future__ import annotations
import os
from dataclasses import dataclass
DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 8317
@dataclass(frozen=True)
class ProxyEndpoint:
host: str = DEFAULT_HOST
port: int = DEFAULT_PORT
api_key: str = ""
@classmethod
def from_env(cls) -> "ProxyEndpoint":
host = os.environ.get("CLIPROXYAPI_HOST", DEFAULT_HOST)
port = int(os.environ.get("CLIPROXYAPI_PORT", str(DEFAULT_PORT)))
api_key = os.environ.get("CLIPROXYAPI_KEY", "").strip()
if not api_key:
raise SystemExit(
"CLIPROXYAPI_KEY is unset. Set it to one of the api-keys "
"you've configured in your CLIProxyAPI config.yaml.\n"
"Example:\n"
" export CLIPROXYAPI_KEY=$(grep -A1 'api-keys:' "
"~/.cli-proxy-api/config.yaml | tail -1 | tr -d ' \"-')"
)
return cls(host=host, port=port, api_key=api_key)
def base_url(self, scheme: str = "http") -> str:
return f"{scheme}://{self.host}:{self.port}"
|