Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion src/sonilo/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/sonilo/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.21.1"
__version__ = "0.21.2"
11 changes: 10 additions & 1 deletion tests/test_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Loading