Skip to content

feat(backends): add default_extra_body to OpenAIBackend for vLLM/vendor-specific per-request fields #1453

Closed

Description

@planetf1

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 _think pass 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_body from model_options takes 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

  1. added
    enhancement
    on Jul 28, 2026
  2. self-assigned this
    on Jul 30, 2026
  3. planetf1 commented on Jul 30, 2026

    @planetf1
    ContributorAuthor

    Part of some evaluation work but opened prematurely. Suggest leaving for now. will update & revalidate

  4. added
    area/backends
    p1
    on Aug 10, 2026
  5. planetf1 commented on Aug 11, 2026

    @planetf1
    ContributorAuthor

    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.THINKING is propagated correctly through the full IVR loop: instruct() → sample() → _subsample_iteration() → backend.generate_from_context() for every draft and validation call. If a caller passes model_options={ModelOption.THINKING: True} (or the equivalent extra_body.chat_template_kwargs form) to instruct(), 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. OpenAIBackend accepts default_headers and default_query at construction time, but not default_extra_body. The workaround is to pass model_options explicitly 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/backendsenhancementp1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions