Skip to main content

Oauth 2.0 认证

如果你想使用 Oauth 2.0 令牌向 LiteLLM 代理发出 /chat/embeddings 请求,请使用此功能。

使用方法

  1. 设置环境变量:
export OAUTH_TOKEN_INFO_ENDPOINT="https://your-provider.com/token/info"
export OAUTH_USER_ID_FIELD_NAME="sub"
export OAUTH_USER_ROLE_FIELD_NAME="role"
export OAUTH_USER_TEAM_ID_FIELD_NAME="team_id"
  • OAUTH_TOKEN_INFO_ENDPOINT: 验证 OAuth 令牌的 URL
  • OAUTH_USER_ID_FIELD_NAME: 令牌信息响应中包含用户ID的字段
  • OAUTH_USER_ROLE_FIELD_NAME: 令牌信息中包含用户角色的字段
  • OAUTH_USER_TEAM_ID_FIELD_NAME: 令牌信息中包含用户团队ID的字段
  1. 在 litellm config.yaml 中启用

在你的 config.yaml 中设置此项

model_list:
- model_name: gpt-4
litellm_params:
model: openai/fake
api_key: fake-key
api_base: https://exampleopenaiendpoint-production.up.railway.app/

general_settings:
master_key: sk-1234
enable_oauth2_auth: true
  1. 在请求中使用令牌到 LiteLLM
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
]
}'

调试

使用 --detailed_debug 模式启动 LiteLLM 代理,你应该会看到更详细的日志

优云智算