LM StudioLM Studio

身份验证

在 LM Studio 中使用 API 令牌

需要 LM Studio 0.4.0 或更高版本。

LM Studio 支持通过 API 令牌进行身份验证,为访问 LM Studio API 提供了一种安全且便捷的方式。

默认情况下,LM Studio API 在运行时 不强制执行身份验证。对于生产或共享环境,请启用 API 令牌 (Token) 身份验证以实现安全访问。

信息

若要启用 API 令牌身份验证、创建令牌并控制细粒度权限,请查看此指南了解更多详情。

提供 API 令牌

可以通过两种方式提供 API 令牌

  1. 环境变量(推荐):设置 LM_API_TOKEN 环境变量,SDK 将会自动读取它。
  2. 函数参数:直接将令牌作为 api_token 参数传递。
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)
© . This site is unofficial and not affiliated with Element Labs, Inc.