Repository navigation
Description
Summary
OpenAIBackend currently accepts default_headers and default_query at construction time, mirroring the AsyncOpenAI client. It has no equivalent for extra_body, which is the only place vLLM (and other OpenAI-compatible servers) accept vendor-specific per-request fields such as chat_template_kwargs, guided_json, and structured_outputs.
This means there is no clean way to inject thinking-tier flags (e.g. {"chat_template_kwargs": {"enable_thinking": true}}) at construction time — the caller must reconstruct the backend for each tier, which discards the HTTP connection pool.
Motivation
We hit this when integrating Mellea into an evaluation harness that needs to forward a thinking-tier setting (enable_thinking: true/false/budget) into Mellea's internal draft calls. Without this feature:
- The OpenAI backend always sends requests without
chat_template_kwargs, so every Mellea draft runs as NOTHINK regardless of the tier the caller requested. - A LIGHT or DEEP request pays for the
_thinkpass and a full NOTHINK Mellea cycle — the reasoning trace is silently ignored. - The only workaround is to reconstruct the entire session per request, discarding the HTTP connection pool.
(Related to #1241, which fixes extra_body collision in the intrinsic path. This issue is about the complementary construction-time feature on the standard path.)
Proposed fix
Add an optional default_extra_body: dict | None = None parameter to OpenAIBackend.__init__() and merge it into extra_body at the chat.completions.create() call site:
# OpenAIBackend.__init__
self._default_extra_body: dict = default_extra_body or {}
# at chat.completions.create() call site (~line 703)
merged_extra_body = {**self._default_extra_body, **extra_body}
chat_response = await self._async_client.chat.completions.create(
...
extra_body=merged_extra_body,
**api_params,
)Caller side (our use-case):
backend = OpenAIBackend(
model_id=settings.LLM_MODEL,
base_url=base_url,
api_key=api_key or "EMPTY",
default_headers=_rits_headers(api_key),
load_embedded_adapters=load_adapters,
model_options=backend_model_options,
default_extra_body={"chat_template_kwargs": {"enable_thinking": True, "thinking_budget": 5000}},
)The change is:
- Additive — no existing callers affected (defaults to
{}). - Small — one new
__init__param, one merge at the call site. - Safe — per-call
extra_bodyfrommodel_optionstakes precedence via the merge order.
Environment
- Mellea v0.6.0
- vLLM 0.9.x
- See also:
feat(session): add per-call model_options override to instruct()(filed separately) — that issue unblocks session reuse; this issue unblocks thinking-tier forwarding.
Activity
planetf1 commentedon Jul 30, 2026
Part of some evaluation work but opened prematurely. Suggest leaving for now. will update & revalidate
planetf1 commentedon Aug 11, 2026
Update (2026-08-11) — revalidation against current main:
My original comment said this was opened prematurely. Having now traced the call stack in detail, I want to correct the status:
The original framing is no longer accurate. As of current main,
ModelOption.THINKINGis propagated correctly through the full IVR loop:instruct()→sample()→_subsample_iteration()→backend.generate_from_context()for every draft and validation call. If a caller passesmodel_options={ModelOption.THINKING: True}(or the equivalentextra_body.chat_template_kwargsform) toinstruct(), it reaches every internal generation call in the loop. This part works.The remaining genuine gap this issue describes: there is still no construction-time equivalent. If you want a thinking-tier setting to apply to all calls from a backend without passing it at every
instruct()/act()call site, there is no clean way to do that.OpenAIBackendacceptsdefault_headersanddefault_queryat construction time, but notdefault_extra_body. The workaround is to passmodel_optionsexplicitly on every call, which works but is verbose and error-prone in library code that wraps Mellea.Summary: the per-call path is fixed; the construction-time default feature is the remaining open ask. The issue title and proposed fix remain valid for that narrower scope.
fix: apply default_extra_body on the standard chat generation path
feat(backends): add default_extra_body to OpenAIBackend (generative-c…
fix: apply default_extra_body on the standard chat generation path
feat(backends): add default_extra_body to OpenAIBackend (generative-c…