From d66e622ef5e36d726c8eceef0b61c4e1011cd19d Mon Sep 17 00:00:00 2001 From: shr00mie <7096317+shr00mie@users.noreply.github.com> Date: Mon, 2 Feb 2026 12:29:30 -0800 Subject: [PATCH] Fix api_token not applied when using configure_default_client When calling configure_default_client(api_host, api_token=...) and then using the convenience API (e.g. list_downloaded_models()), the LM Studio server could return 'An LM Studio API token is required to make requests to this server, but none was provided.' The token was never sent because the module-level _default_api_token was never updated. Root cause: In configure_default_client only _default_api_host was declared global. The assignment _default_api_token = api_token therefore created a local variable; the global _default_api_token remained None. Later, get_default_client() created Client(_default_api_host, _default_api_token) with the token still None. Fix: Declare both _default_api_host and _default_api_token as global in configure_default_client so the assignment updates the module-level variable. One-line change; no other behavior change. --- src/lmstudio/sync_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmstudio/sync_api.py b/src/lmstudio/sync_api.py index ba73958..5751d4b 100644 --- a/src/lmstudio/sync_api.py +++ b/src/lmstudio/sync_api.py @@ -1709,7 +1709,7 @@ def list_loaded_models( @sdk_public_api() def configure_default_client(api_host: str, api_token: str | None = None) -> None: """Set the server API host for the default global client (without creating the client).""" - global _default_api_host + global _default_api_host, _default_api_token if _default_client is not None: raise LMStudioClientError( "Default client is already created, cannot set its API host or token."