Authentication
Using API Tokens in LM Studio
Requires LM Studio 0.4.0 or newer.
LM Studio supports API Tokens for authentication, providing a secure and convenient way to access the LM Studio API.
By default, the LM Studio API runs without enforcing authentication. For production or shared environments, enable API Token authentication for secure access.
Info
To enable API Token authentication, create tokens and control granular permissions, check this guide for more details.
Providing the API Token
The API Token can be provided in two ways:
- Environment Variable (Recommended): Set the
LM_API_TOKENenvironment variable, and the SDK will automatically read it. - Function Argument: Pass the token directly as the
api_tokenparameter.
import lmstudio as lms
# Configure the default client with an API token
lms.configure_default_client(api_token="your-token-here")
model = lms.llm()
result = model.respond("What is the meaning of life?")
print(result)