Spaces:
Sleeping
Sleeping
| """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 | |
| class ProxyEndpoint: | |
| host: str = DEFAULT_HOST | |
| port: int = DEFAULT_PORT | |
| api_key: str = "" | |
| 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}" | |