Skip to content
Draft
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 src/together/lib/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def block_requests_for_api_key(_: httpx.Request) -> None:
"[red]x[/red] api key missing.\n\nThe api key must be set either by passing --api-key to the command or by setting the TOGETHER_API_KEY environment variable",
)
console.print("You can find your api key at https://api.together.ai/settings/api-keys")
sys.exit(1)
raise CliDiagnosticExit("Together API key missing")

client._client.event_hooks["request"].append(block_requests_for_api_key)
else:
Expand Down
24 changes: 24 additions & 0 deletions tests/cli/test_command_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@ def _exit_1() -> None:
assert "error" in failed


@pytest.mark.usefixtures("isolated_cli_config")
@pytest.mark.asyncio
async def test_missing_api_key_preserves_diagnostic(
track_cli_capture: list[tuple[CliTrackingEvents, dict[str, Any]]],
monkeypatch: pytest.MonkeyPatch,
) -> None:
from together.lib.cli import launcher

monkeypatch.delenv("TOGETHER_API_KEY", raising=False)
monkeypatch.setenv("TOGETHER_DISABLE_VERSION_CHECK", "1")

with pytest.raises(SystemExit) as exc_info:
await launcher("endpoints", "list", project_id="project")

assert exc_info.value.code == 1
assert _event_kinds(track_cli_capture) == [
CliTrackingEvents.CommandStarted.value,
CliTrackingEvents.CommandFailed.value,
]
failed = track_cli_capture[1][1]
assert failed["command"] == "endpoints list"
assert failed["error"] == "Together API key missing"


@pytest.mark.usefixtures("isolated_cli_config")
@pytest.mark.asyncio
async def test_interactive_missing_required_argument_preserves_diagnostic(
Expand Down
Loading