-
[OPIK-6652] [BE] fix: send Comet-Workspace header on Studio gateway LLM calls (#6944)
发布于
2026-06-03 14:33:31 +00:00 - [OPIK-6652] [BE] fix: send Comet-Workspace header on Studio gateway LLM calls
Optimization Studio routes every LiteLLM completion through the Opik
backend gateway (OPENAI_API_BASE), which authenticates each request per
workspace via the Comet-Workspace header. LiteLLM's OpenAI-compatible
path forwards only Authorization, so the gateway received no workspace
and rejected every server-side run with 403 "Workspace name should be
provided". Wrap litellm.completion/acompletion in the optimizer runner to
inject the workspace header (sourced from the job's workspace name,
independent of the project name), guarded on OPENAI_API_BASE.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
- [OPIK-6652] [BE] refactor: address review on gateway workspace header
- Read OPENAI_API_BASE once into a module-level constant (mirrors OPIK_URL
in studio/config.py) and use it in the guard instead of os.environ.get at
call time. - Make the wrappers read the workspace from a shared mutable container so a
subsequent call with a different workspace updates the injected value in
place, instead of returning early and keeping a stale header. Still wraps
at most once (no nested wrappers). - Cover the workspace-change path with a new unit test; patch the module
constant in tests rather than the environment.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Co-authored-by: Douglas Blank doug@comet.com
Co-authored-by: Claude Opus 4.8 (1M context) noreply@anthropic.com下载附件