Skip to content

feat: forward request headers to model providers#3243

Open
xingguo-yang wants to merge 5 commits into
volcengine:mainfrom
xingguo-yang:feat/dynamic-model-request-headers
Open

feat: forward request headers to model providers#3243
xingguo-yang wants to merge 5 commits into
volcengine:mainfrom
xingguo-yang:feat/dynamic-model-request-headers

Conversation

@xingguo-yang

@xingguo-yang xingguo-yang commented Jul 14, 2026

Copy link
Copy Markdown

Description / 说明

背景

OpenViking 接入企业内部的模型代理时,代理通常需要认证或租户路由请求头。当前 extra_headers 只能配置固定值,因此无法把调用 OpenViking 时携带的用户级 Authorization、租户 ID 等信息继续传给下游模型服务。

解决方案

本 PR 在现有 extra_headers 中增加一个显式的动态取值语法:

{
  "extra_headers": {
    "Authorization": "@request.header.Authorization",
    "X-Tenant-ID": "@request.header.X-OpenViking-Tenant",
    "X-Proxy-Route": "primary"
  }
}
  • @request.header.<请求头名>:每次调用模型时,从当前 OpenViking HTTP 请求中读取对应请求头。
  • 普通字符串(例如 "primary"):仍按原逻辑作为固定值发送。
  • 请求头名称不写死,支持转发任意合法请求头,名称匹配不区分大小写。

这样既能满足 Bearer Token、租户标识等动态认证场景,也不需要给 VLM、Embedding、Rerank 分别增加新配置字段。

影响范围

动态请求头已接入以下模型调用链路:

  • VLM 和 Query Planner
  • Embedding
  • Rerank

原有配置无需修改,未使用 @request.header.* 的用户行为保持不变。

兼容性与安全性

  • 只有完整值匹配 @request.header.<name> 时才会动态解析,普通字符串不会被误处理。
  • 每个 HTTP 请求独立保存请求头,并在请求结束后失效,避免并发请求串值或认证信息残留到异步任务。
  • LiteLLM 日志中的 api_keyextra_headers 已脱敏,避免认证信息出现在日志中。
  • HTTP 请求存在但来源请求头缺失时,下游发送空值;非 HTTP 调用场景会忽略动态项,并保留原有固定请求头和 api_key 回退行为。

Human Involvement / 人工参与

  • A human participated in the implementation or review loop(人工参与了需求确认和代码审核)
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue / 关联 Issue

暂无。

Type of Change / 变更类型

  • Bug fix
  • New feature(新增功能)
  • Breaking change
  • Documentation update(文档更新)
  • Refactoring
  • Performance improvement
  • Test update(测试更新)

Changes Made / 主要改动

  • 增加请求级请求头上下文和 @request.header.<name> 解析逻辑。
  • 在 VLM、Embedding、Rerank 的已有 extra_headers 调用链路中解析动态值。
  • 保持固定请求头和现有 api_key 回退行为兼容。
  • 补充中英文配置文档、单元测试和请求中间件测试。
  • 对 LiteLLM 日志中的认证配置进行脱敏。

Testing / 测试

  • 已增加测试覆盖本次功能
  • 本地完整测试套件全部通过
  • 测试平台:Windows

验证结果:

  • 请求头解析及模型调用相关测试:97 passed
  • 所有改动文件通过 Ruff 检查
  • 完整测试套件因本地缺少 ragfs_python 原生库未能执行;该限制与本次改动无关
  • 测试覆盖固定值兼容、动态值解析、大小写匹配、任意合法请求头、并发隔离和请求结束后失效

Checklist / 检查项

  • 代码符合项目现有风格
  • 已完成自查和安全性检查
  • 已同步更新中英文文档
  • 未引入新的警告
  • 存在需要预先合并或发布的依赖项(本 PR 无此类依赖)

@qin-ctx qin-ctx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该 PR 的请求内动态 header 解析实现清晰,但当前请求上下文无法覆盖 OpenViking 的后台 task 和 QueueManager 执行链路。默认资源导入、semantic/VLM、embedding、watch、reindex、session commit 等路径会在响应返回后或独立线程/event loop 中调用模型,因此需要先明确并补齐凭证 handoff 生命周期。

Comment thread openviking/utils/request_headers.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants