基于团队/密钥的日志记录
允许每个密钥/团队使用自己的 Langfuse 项目 / 自定义回调
这使您能够执行以下操作
Team 1 -> Logs to Langfuse Project 1
Team 2 -> Logs to Langfuse Project 2
Team 3 -> Disabled Logging (for GDPR compliance)
基于团队的日志记录
通过 config.yaml
设置团队日志记录
为特定团队 ID 开启/关闭日志记录和缓存。
示例
此配置将根据团队 ID,将 langfuse 日志发送到 2 个不同的 langfuse 项目
litellm_settings:
default_team_settings:
- team_id: "dbe2f686-a686-4896-864a-4c3924458709"
success_callback: ["langfuse"]
langfuse_public_key: os.environ/LANGFUSE_PUB_KEY_1 # Project 1
langfuse_secret: os.environ/LANGFUSE_PRIVATE_KEY_1 # Project 1
- team_id: "06ed1e01-3fa7-4b9e-95bc-f2e59b74f3a8"
success_callback: ["langfuse"]
langfuse_public_key: os.environ/LANGFUSE_PUB_KEY_2 # Project 2
langfuse_secret: os.environ/LANGFUSE_SECRET_2 # Project 2
现在,当您为此团队 ID生成密钥时
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{"team_id": "06ed1e01-3fa7-4b9e-95bc-f2e59b74f3a8"}'
使用这些密钥发出的所有请求都将把数据记录到其团队特定的日志中。-->
[BETA]通过 API 进行团队日志记录
✨ 这是企业版专属功能 在此处开始使用企业版
按团队设置回调
1. 为团队设置回调
我们向 POST /team/{team_id}/callback
发出请求以添加回调,用于
curl -X POST 'http:/localhost:4000/team/dbe2f686-a686-4896-864a-4c3924458709/callback' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"callback_name": "langfuse",
"callback_type": "success",
"callback_vars": {
"langfuse_public_key": "pk",
"langfuse_secret_key": "sk_",
"langfuse_host": "https://cloud.langfuse.com"
}
}'
支持的值
字段 | 支持的值 | 备注 |
---|---|---|
callback_name | "langfuse" , "gcs_bucket" | 当前仅支持 "langfuse" , "gcs_bucket" |
callback_type | "success" , "failure" , "success_and_failure" | |
callback_vars | 回调设置字典 | |
langfuse_public_key | 字符串 | Langfuse 所需 |
langfuse_secret_key | 字符串 | Langfuse 所需 |
langfuse_host | 字符串 | Langfuse 可选 (默认为 https://cloud.langfuse.com) |
gcs_bucket_name | 字符串 | GCS Bucket 所需。您的 GCS 桶名称 |
gcs_path_service_account | 字符串 | GCS Bucket 所需。您的服务账号 json 文件路径 |
2. 为团队创建密钥
为团队 dbe2f686-a686-4896-864a-4c3924458709
创建的所有密钥都将记录到 步骤 1. 为团队设置回调 中指定的 langfuse 项目
curl --location 'http://0.0.0.0:4000/key/generate' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data '{
"team_id": "dbe2f686-a686-4896-864a-4c3924458709"
}'
3. 为团队发起 /chat/completion
请求
curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-KbUuE0WNptC0jXapyMmLBA" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "user", "content": "Hello, Claude gm!"}
]
}'
预期此请求将记录到 步骤 1. 为团队设置回调 中指定的 langfuse 项目
禁用团队日志记录
要禁用特定团队的日志记录,您可以使用以下端点
POST /team/{team_id}/disable_logging
此端点会移除指定团队的所有成功和失败回调,从而有效地禁用日志记录。
步骤 1. 禁用团队日志记录
curl -X POST 'http://localhost:4000/team/YOUR_TEAM_ID/disable_logging' \
-H 'Authorization: Bearer YOUR_API_KEY'
将 YOUR_TEAM_ID 替换为实际的团队 ID
响应 成功请求将返回类似以下的响应
{
"status": "success",
"message": "Logging disabled for team YOUR_TEAM_ID",
"data": {
"team_id": "YOUR_TEAM_ID",
"success_callbacks": [],
"failure_callbacks": []
}
}
步骤 2. 测试 - /chat/completions
使用为 team = team_id
生成的密钥 - 您应该在配置的成功回调(例如 Langfuse)中看不到任何日志
curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-KbUuE0WNptC0jXapyMmLBA" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "user", "content": "Hello, Claude gm!"}
]
}'
调试 / 排障
- 使用
GET /team/{team_id}/callback
检查团队的活动回调
使用此方法检查 team=team_id
有哪些成功/失败回调处于活动状态
curl -X GET 'http://localhost:4000/team/dbe2f686-a686-4896-864a-4c3924458709/callback' \
-H 'Authorization: Bearer sk-1234'
团队日志记录端点
[BETA]基于密钥的日志记录
使用 /key/generate
或 /key/update
端点为特定密钥添加日志记录回调。
✨ 这是企业版专属功能 在此处开始使用企业版
基于密钥的日志记录工作原理:
- 如果密钥未配置回调,它将使用 config.yaml 文件中指定的默认回调
- 如果密钥已配置回调,它将使用密钥中指定的回调
- Langfuse
- GCS Bucket
- Langsmith
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"logging": [{
"callback_name": "langfuse", # "otel", "gcs_bucket"
"callback_type": "success", # "success", "failure", "success_and_failure"
"callback_vars": {
"langfuse_public_key": "os.environ/LANGFUSE_PUBLIC_KEY", # [RECOMMENDED] reference key in proxy environment
"langfuse_secret_key": "os.environ/LANGFUSE_SECRET_KEY", # [RECOMMENDED] reference key in proxy environment
"langfuse_host": "https://cloud.langfuse.com"
}
}]
}
}'
创建虚拟密钥以记录到特定的 GCS Bucket
在您的环境中设置
GCS_SERVICE_ACCOUNT
为服务账号 json 文件路径export GCS_SERVICE_ACCOUNT=/path/to/service-account.json # GCS_SERVICE_ACCOUNT=/Users/ishaanjaffer/Downloads/adroit-crow-413218-a956eef1a2a8.json
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"logging": [{
"callback_name": "gcs_bucket", # "otel", "gcs_bucket"
"callback_type": "success", # "success", "failure", "success_and_failure"
"callback_vars": {
"gcs_bucket_name": "my-gcs-bucket", # Name of your GCS Bucket to log to
"gcs_path_service_account": "os.environ/GCS_SERVICE_ACCOUNT" # environ variable for this service account
}
}]
}
}'测试 -
/chat/completions
请求使用步骤 3 中的虚拟密钥发起
/chat/completions
请求在成功请求后,您应该在 GCS Bucket 中看到日志
curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-Fxq5XSyWKeXDKfPdqXZhPg" \
-d '{
"model": "fake-openai-endpoint",
"messages": [
{"role": "user", "content": "Hello, Claude"}
],
"user": "hello",
}'
创建虚拟密钥以记录到特定的 Langsmith 项目
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"logging": [{
"callback_name": "langsmith", # "otel", "gcs_bucket"
"callback_type": "success", # "success", "failure", "success_and_failure"
"callback_vars": {
"langsmith_api_key": "os.environ/LANGSMITH_API_KEY", # API Key for Langsmith logging
"langsmith_project": "pr-brief-resemblance-72", # project name on langsmith
"langsmith_base_url": "https://api.smith.langchain.com"
}
}]
}
}'测试 -
/chat/completions
请求使用步骤 3 中的虚拟密钥发起
/chat/completions
请求在成功请求后,您应该在您的 Langsmith 项目中看到日志
curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-Fxq5XSyWKeXDKfPdqXZhPg" \
-d '{
"model": "fake-openai-endpoint",
"messages": [
{"role": "user", "content": "Hello, Claude"}
],
"user": "hello",
}'
通过在此处提交工单帮助我们改进此功能
检查密钥回调是否配置正确 /key/health
调用 /key/health
并附带密钥,以检查回调设置是否配置正确
在请求头中传递密钥
curl -X POST "http://localhost:4000/key/health" \
-H "Authorization: Bearer <your-key>" \
-H "Content-Type: application/json"
- 密钥配置正确时的响应
- 密钥配置不正确时的响应
日志记录回调设置正确时的响应
当日志记录回调设置正确时,密钥是健康的 (healthy)。
{
"key": "healthy",
"logging_callbacks": {
"callbacks": [
"gcs_bucket"
],
"status": "healthy",
"details": "No logger exceptions triggered, system is healthy. Manually check if logs were sent to ['gcs_bucket']"
}
}
日志记录回调设置不正确时的响应
当日志记录回调设置不正确时,密钥是不健康的 (unhealthy)。
{
"key": "unhealthy",
"logging_callbacks": {
"callbacks": [
"gcs_bucket"
],
"status": "unhealthy",
"details": "Logger exceptions triggered, system is unhealthy: Failed to load vertex credentials. Check to see if credentials containing partial/invalid information."
}
}
禁用/启用消息脱敏
当您全局禁用了提示词日志记录时,使用此选项为特定密钥启用日志记录
全局禁用提示词日志记录(消息脱敏)的 config.yaml 示例
model_list:
- model_name: gpt-4o
litellm_params:
model: gpt-4o
litellm_settings:
callbacks: ["datadog"]
turn_off_message_logging: True # 👈 Globally logging prompt / response is disabled
为密钥启用提示词日志记录
将您要启用提示词日志记录的密钥的 turn_off_message_logging
设置为 false
。这将覆盖全局 turn_off_message_logging
设置。
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{
"metadata": {
"logging": [{
"callback_name": "datadog",
"callback_vars": {
"turn_off_message_logging": false # 👈 Enable prompt logging
}
}]
}
}'
来自 /key/generate
的响应
{
"key_alias": null,
"key": "sk-9v6I-jf9-eYtg_PwM8OKgQ",
"metadata": {
"logging": [
{
"callback_name": "datadog",
"callback_vars": {
"turn_off_message_logging": false
}
}
]
},
"token_id": "a53a33db8c3cf832ceb28565dbb034f19f0acd69ee7f03b7bf6752f9f804081e"
}
使用密钥发起 /chat/completions
请求
此密钥将把提示词记录到请求中指定的回调
curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-9v6I-jf9-eYtg_PwM8OKgQ" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "hi my name is ishaan what key alias is this"}
]
}'