Skip to content

PoeTokenStore

🛈 DocStrings

File-based storage for Poe API key.

Source code in src/llmling_models/auth/poe_auth.py
class PoeTokenStore:
    """File-based storage for Poe API key."""

    def __init__(self, path: Path = DEFAULT_TOKEN_PATH) -> None:
        self.path = path
        self.path.parent.mkdir(parents=True, exist_ok=True)

    def load(self) -> str | None:
        """Load stored API key."""
        if not self.path.exists():
            return None
        try:
            data = anyenv.load_json(self.path.read_text(), return_type=dict)
            api_key = data.get("api_key")
            return str(api_key) if api_key else None
        except (anyenv.JsonLoadError, KeyError) as e:
            logger.warning("Failed to load Poe API key from %s: %s", self.path, e)
            return None

    def save(self, api_key: str, expires_in: int | None = None) -> None:
        """Save API key."""
        data: dict[str, Any] = {"api_key": api_key}
        if expires_in is not None:
            data["expires_in"] = expires_in
        write_private_json(self.path, data)

    def clear(self) -> None:
        """Remove stored API key."""
        if self.path.exists():
            self.path.unlink()

clear

clear() -> None

Remove stored API key.

Source code in src/llmling_models/auth/poe_auth.py
def clear(self) -> None:
    """Remove stored API key."""
    if self.path.exists():
        self.path.unlink()

load

load() -> str | None

Load stored API key.

Source code in src/llmling_models/auth/poe_auth.py
def load(self) -> str | None:
    """Load stored API key."""
    if not self.path.exists():
        return None
    try:
        data = anyenv.load_json(self.path.read_text(), return_type=dict)
        api_key = data.get("api_key")
        return str(api_key) if api_key else None
    except (anyenv.JsonLoadError, KeyError) as e:
        logger.warning("Failed to load Poe API key from %s: %s", self.path, e)
        return None

save

save(api_key: str, expires_in: int | None = None) -> None

Save API key.

Source code in src/llmling_models/auth/poe_auth.py
def save(self, api_key: str, expires_in: int | None = None) -> None:
    """Save API key."""
    data: dict[str, Any] = {"api_key": api_key}
    if expires_in is not None:
        data["expires_in"] = expires_in
    write_private_json(self.path, data)

:fa-brands-github: Show source on GitHub