diff --git a/pyproject.toml b/pyproject.toml index 493a696..9c1d92a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "sonilo" -version = "0.21.1" +version = "0.21.2" description = "Official Python client for the Sonilo API" readme = "README.md" license = "MIT" diff --git a/src/sonilo/_client.py b/src/sonilo/_client.py index 0742d94..0726da1 100644 --- a/src/sonilo/_client.py +++ b/src/sonilo/_client.py @@ -32,12 +32,17 @@ #: distinguishable from direct SDK use in server-side analytics. DEFAULT_CLIENT_NAME = "sdk-python" +#: Where a missing-key error sends the user. The MCP server and the CLI print +#: the same link, so an agent can hand it straight to the person. +API_KEYS_URL = "https://platform.sonilo.com/dashboard/api-keys" + def _resolve_api_key(api_key: Optional[str]) -> str: key = api_key or os.environ.get("SONILO_API_KEY") if not key: raise SoniloError( - "Missing API key: pass api_key= or set the SONILO_API_KEY environment variable" + "Missing API key: pass api_key= or set the SONILO_API_KEY environment " + f"variable. Create a key at {API_KEYS_URL}" ) return key diff --git a/src/sonilo/_version.py b/src/sonilo/_version.py index 76f2458..3964f1e 100644 --- a/src/sonilo/_version.py +++ b/src/sonilo/_version.py @@ -1 +1 @@ -__version__ = "0.21.1" +__version__ = "0.21.2" diff --git a/tests/test_sync_client.py b/tests/test_sync_client.py index ce0e5ce..b4a9d1b 100644 --- a/tests/test_sync_client.py +++ b/tests/test_sync_client.py @@ -6,7 +6,7 @@ import respx import sonilo.resources.tasks as tasks_module -from sonilo import Sonilo +from sonilo import AsyncSonilo, Sonilo from sonilo._version import __version__ from sonilo.errors import AuthenticationError, GenerationError, SoniloError from sonilo.resources.tasks import parse_music_result @@ -74,6 +74,15 @@ def test_missing_api_key_raises(monkeypatch): Sonilo() +def test_missing_api_key_error_links_to_the_keys_page(monkeypatch): + # The MCP server and the CLI print this link; an agent passes it on. + monkeypatch.delenv("SONILO_API_KEY", raising=False) + with pytest.raises(SoniloError, match="https://platform.sonilo.com/dashboard/api-keys"): + Sonilo() + with pytest.raises(SoniloError, match="https://platform.sonilo.com/dashboard/api-keys"): + AsyncSonilo() + + def test_env_api_key_used(monkeypatch): monkeypatch.setenv("SONILO_API_KEY", "sk_env") client = Sonilo()