Skip to content

OpenAIBackend: user-supplied model in model_options collides with the hardcoded model kwarg (follow-up to #1142) #1575

Closed

Description

@planetf1

Epic: #929 | Blocked by: — | Phase: 2 | Related: #1516 restructures the intrinsic path and is the natural place to land the fix

Problem

On OpenAIBackend, any call whose model_options include a raw model entry crashes at the API call site with a bare Python duplicate-kwarg error, instead of either honouring the override or failing with a Mellea-side explanation:

TypeError: ...chat.completions.create... got multiple values for keyword argument 'model'

How it gets there

In OpenAIBackend._generate_from_intrinsic (mellea/backends/openai.py), the model key passes through three steps, in this order:

  1. The intrinsic rewriter sets model to the intrinsic name in its parameters (the Granite Switch convention: the model parameter selects the adapter) — mellea/formatters/granite/intrinsics/input.py.
  2. EmbeddedBinding.apply_activation pops it (mellea/backends/adapters/_core.py), because for an embedded adapter the real model is the base model already being served.
  3. The user overlay api_params.update(user_api_params) runs after the pop, and ModelOption.replace_keys copies unknown keys through (mellea/backends/model_options.py) — so a user-supplied model re-enters api_params.

The final call is create(model=self._model_id, ..., **api_params), so the re-injected key collides with the explicit keyword argument.

On the ordinary (non-intrinsic) chat path the same collision exists without steps 1-2: generate_from_chat_context also calls create(model=self._model_id, ..., **backend_specific), and backend_specific is built by the same key-copying overlay (mellea/backends/openai.py). The intrinsic path is simply where a user is likely to pass the key, because the rewriter's io.yaml defaults put model in the parameter space and the docs show it.

Reproduction

Verified locally (against the #1559 branch, adapter registered, OpenAI async client mocked at the network boundary):

backend.add_adapter(
    EmbeddedIntrinsicAdapter("answerability", config=config, technology="alora")
)
mot, _ = await mfuncs.aact(
    Intrinsic("answerability"), ctx, backend, strategy=None,
    model_options={"model": "answerability_alora"},
)
# -> TypeError: got multiple values for keyword argument 'model'

Decision (2026-08-20) — reject

Chosen during the PR #1559 review session: a user-supplied model in model_options should fail fast with a clear error that redirects to the established model-selection mechanism, rather than colliding at create() or being silently dropped. Rationale, all verified in the codebase:

  • Model selection in Mellea is a backend/session-level act, not a per-call option: OpenAIBackend fixes model_id at construction and sends it on every call.
  • The framework's own multi-model patterns use distinct backend objects, not model_options: SOFAISamplingStrategy takes separate s1_solver_backend / s2_solver_backend / judge_backend, and m serve's model-routing deliberately strips model out of model_options (cli/serve/app.py: "used for routing, not generation") and routes by starting a session against the chosen model.
  • A multi-model single endpoint is already expressible today as two backends sharing a base_url — honouring the key would introduce a parallel second selection mechanism instead of enabling anything new.
  • On intrinsic/Switch calls the field additionally carries adapter-selection semantics, so honouring it there would put two contradictory instructions in one request.

Suggested error wording: "model cannot be set via model_options on OpenAIBackend — model selection happens at the backend/session level (construct a backend per model, or start a session against the chosen model_id)."

Implementation note: one check in the per-call model-options handling covers both the chat and intrinsic paths (the collision is identical on both); add a test per path.

Expected behaviour (options considered)

The semantics are currently decided by accident (an obscure crash). One of:

  • Reject — calls reject a user-supplied model with a clear error (the backend's model is fixed at construction).
  • Honour — per-call model routing: create(model=<user value>), so one backend could target different models on a multi-model OpenAI-compatible server. Note this is not achievable cleanly on the intrinsic/Switch path, where the model field doubles as adapter-selection semantics — honouring it there would put two contradictory instructions in one request — so honouring would at minimum need an intrinsic exception (reject there, honour elsewhere).
  • Drop — ignore the key (the backend's model wins); the override is silently discarded.

Context

Activity

  1. added
    area/backends
    area/adapter-functions
    on Aug 20, 2026
  2. changed the title [-]Intrinsic calls: user-supplied model in model_options collides with the binding's model pop (follow-up to #1142)[/-] [+]OpenAIBackend: user-supplied model in model_options collides with the hardcoded model kwarg (follow-up to #1142)[/+] on Aug 20, 2026
  3. self-assigned this
    on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/adapter-functionsarea/backends

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions