Repository navigation
Description
Summary
Make an explicitly selected provider connection authoritative for LLM routing, with one SDK-owned resolution path shared by validation and execution. Users should be able to enter a provider-native model ID without also knowing LiteLLM's routing-prefix conventions.
Keep the existing credential-sharing architecture. This is a routing-contract and normalization feature, not a replacement of provider/profile storage.
User story
As a user, when I select an OpenRouter provider connection and enter thinkingmachines/inkling-small:free, I expect the request to go through OpenRouter. I should not have to enter openrouter/thinkingmachines/inkling-small:free to repeat the provider choice in LiteLLM syntax.
This must work for profiles created through Canvas, the agent-server REST API, and the standalone SDK, including existing saved profiles.
Evidence and history
- Original report: [Bug]: Openrouter custom model support OpenHands#17233 (opened September 9, 2026).
- Current frontend-only workaround: fix(settings): save OpenRouter model IDs with the openrouter/ prefix OpenHands#19743. It qualifies OpenRouter IDs in Canvas's
buildProfileLlmConfigbased on the selected connection or inline OpenRouter URL. It does not fix other writers or already-saved profiles by itself. - SDK provider connections were introduced August 19, 2026: Add read-at-use LLM provider connections #4492 and 73fabfd.
- The matching Canvas UI was introduced in feat: add LLM provider-connections UI (local agent-server) OpenHands#16616.
The original feature deliberately defined connections as shared credentials (api_key plus optional base_url). From its introduction, LLMProfileStore._resolve_provider_connection() applied those values but did not translate connection.provider into routing. The initial resolution tests supplied already-qualified model IDs. Source history therefore indicates an original design omission, not a recent loss of prefix-handling behavior. Historical versions were inspected, not executed.
Current problem
A connection can contain provider: "openrouter", while the profile's model remains thinkingmachines/inkling-small:free. LiteLLM then attempts provider inference and can fail with LLM Provider NOT provided.
Provider intent is represented in multiple places without a sufficiently explicit precedence contract:
- Connection
provider. - Routing prefix embedded in
model. - Provider inferred from
base_url.
A related ambiguous-looking example is provider=openrouter, model=anthropic/claude-sonnet-4. Here anthropic/... is a valid OpenRouter-native ID; it must not be mistaken for an explicit request to bypass OpenRouter and call Anthropic directly.
Frontend-only normalization makes correctness depend on the client that wrote the profile and leaves existing saved configurations unfixed.
Proposed design
Establish a single SDK-owned process that combines a profile and its optional connection into an effective runnable LLM configuration:
Stored/draft profile + referenced provider connection
|
v
SDK effective-config resolution
- resolve credentials and endpoint
- determine effective provider
- normalize provider-native model/routing
- validate incompatible combinations
- refresh provider-dependent derived state
|
v
Runnable LLM
Resolution contract
- A recognized explicit connection provider determines routing. It must work even when its endpoint is a proxy/custom host, so hostname inference is not required for explicit selection.
- Provider-native model IDs are accepted according to that provider's naming rules.
- Already-qualified IDs are handled idempotently.
customor unspecified providers retain existing model/endpoint inference behavior for compatibility.- No connection means existing behavior remains unchanged, except for an explicitly documented inline OpenRouter inference improvement if included.
- Contradictions that can actually be identified are rejected with actionable errors; do not silently route to a different provider.
- Existing missing-connection, cipher, secret-redaction, credential-rotation, and endpoint-resolution contracts remain intact.
Do not implement this as a generic provider + "/" + model rule. Provider-native IDs can contain slashes, OpenRouter is a provider aggregator, and custom/OpenAI-compatible endpoints need distinct handling.
Implementation considerations / decisions to record
- Choose whether the effective runtime configuration uses canonical LiteLLM model IDs, an explicit provider override, or both. Verify compatibility with all SDK call paths rather than assuming one LiteLLM entry point is sufficient.
- Decide where normalization lives so that
LLMProfileStore.load(),resolve_provider_connection()for drafts/in-memory settings, and validation reach the same implementation. - Preserve the separation between a user's stored config and its effective runtime config. Prefer resolving at use time; do not require destructive rewrites of existing profile files to make them work.
- Audit provider-dependent derived state: model capabilities, request/API selection, model information, and other cached decisions. Current connection resolution uses
model_copy(update=...); field updates must not leave derived state inconsistent or rely on validators implicitly rerunning. - Define handling of existing arbitrary provider strings. The original field was free text; do not casually break previously valid saved connections by making it a strict enum. Either preserve legacy/custom behavior or provide an explicit compatibility/migration policy.
- Keep provider-specific normalization extensible without introducing a speculative framework for every provider.
Scope and delivery
Required first delivery
Fix the central routing contract for explicit OpenRouter connections in the SDK and agent-server, including existing profiles and draft validation. Establish the shared resolution entry point and compatibility rules. Cover standard providers/custom connections sufficiently to prove the change does not regress them.
Companion OpenHands work
Update the consumed SDK/agent-server version, retain an end-to-end Canvas regression test, and remove or avoid duplicate frontend-only authoritative routing rules once the backend supports the contract. UI hints or display of the effective qualified model may remain as convenience features.
Secondary, separately testable scope
Consider support for direct LLM(model=<OpenRouter-native ID>, base_url="https://openrouter.ai/api/v1", ...) without a connection. If included, implement inference centrally rather than only in Canvas. If deferred, explicitly document that boundary and track the follow-up; do not claim the inline-base-URL part of OpenHands#17233 is fixed.
Non-goals
- Replacing the encrypted provider-connection/profile stores.
- Changing credential rotation to mutate running conversations.
- Live provider model discovery or expanding the Basic tab's model catalog.
- Blindly prefixing every provider/model combination.
- Requiring all existing profiles to be resaved through Canvas.
Acceptance criteria
A. Core OpenRouter behavior
- A profile linked to
provider: "openrouter"acceptsthinkingmachines/inkling-small:free; its effective configuration routes through OpenRouter rather than failing provider inference. -
anthropic/claude-sonnet-4under an OpenRouter connection routes through OpenRouter, not direct Anthropic. - An already-qualified
openrouter/anthropic/claude-sonnet-4remains semantically unchanged; no duplicate prefix is introduced. - OpenRouter-native IDs with suffixes such as
:freeretain the complete model ID. - Explicit OpenRouter selection works with the default endpoint and a custom/proxy endpoint; provider identity does not depend on the endpoint hostname.
- Normalization is idempotent across repeated resolution/activation.
B. Coverage across entry points
- A previously saved, unprefixed OpenRouter-linked profile works after upgrade without editing/resaving it or manually modifying its JSON.
- A new profile created through the REST API receives the same effective routing as one created through Canvas.
- Standalone SDK profile loading resolves the same configuration.
- Draft profile validation and runtime execution use the same provider/model resolution and agree on whether a configuration is valid.
- Audit the consumers of the central resolver (including activation, profile-based launch, in-memory/draft resolution, switching, and the OpenAI-compatible gateway); add regression coverage for any distinct path that would otherwise bypass the fix. Preserve intentional snapshot semantics for already-running conversations.
C. Compatibility and precedence
-
custom/unspecified connections retain existing routing/inference semantics. - Unrelated standard provider configurations continue to work; provider-specific model naming is not corrupted by a generic prefix rule.
- Existing arbitrary provider labels have a documented backwards-compatible behavior or a deliberate migration path.
- The precedence among explicit connection provider, model qualification, and inferred endpoint provider is documented and tested.
- Detectable incompatible configurations fail with an actionable error identifying the conflicting fields, without exposing credentials.
- Valid aggregator-native IDs containing another vendor's name are not falsely rejected as conflicts.
- Existing rules for connection-owned keys/endpoints, including an authoritative
base_url: null, remain unchanged unless a separate, explicit compatibility decision is made. - Missing-connection errors, encryption/redaction, and read-at-use key rotation remain intact.
D. Runtime correctness
- Provider-dependent derived configuration is consistent with the resolved provider/model; no stale capability or API-selection state survives normalization.
- Supported LLM request paths relevant to the implementation use the effective routing consistently; verify Chat Completions and Responses behavior where applicable rather than testing only string manipulation.
- A credential-free local OpenAI-compatible stand-in/proxy test exercises real SDK resolution and request dispatch and verifies the request reaches the intended endpoint with the correct wire model ID.
- Error reporting never includes API keys or other secret values.
E. Inline endpoint behavior (if included)
- Direct SDK/REST configurations with an OpenRouter-native model and
https://openrouter.ai/api/v1resolve through OpenRouter. - Already-qualified IDs remain unchanged.
- Host matching does not classify lookalikes such as
openrouter.ai.example.comas OpenRouter. - The policy for subdomains, malformed URLs, and explicitly conflicting routing is documented and tested.
- Inference does not override an explicitly selected non-OpenRouter connection based on stale inline form values.
F. Delivery and verification
- Add regression tests demonstrating the original failure before the fix and success afterward.
- Include unit tests for normalization/precedence and integration tests for actual profile resolution and request dispatch. Use real code paths; mock only external network boundaries when necessary and explain why.
- Run relevant SDK LLM/profile and agent-server profile/provider-connection tests, plus lint/type checks.
- Document the user-facing provider/model contract and any intentionally deferred cases.
- Link the companion OpenHands dependency update/UI regression work and coordinate with PR #19743 so the SDK becomes the source of truth rather than leaving two diverging normalization implementations.
Suggested test matrix
| Connection provider | Input model | Endpoint | Expected |
|---|---|---|---|
| openrouter | thinkingmachines/inkling-small:free | default | OpenRouter route, native model preserved on wire |
| openrouter | anthropic/claude-sonnet-4 | default | OpenRouter, not direct Anthropic |
| openrouter | openrouter/anthropic/claude-sonnet-4 | default | Same route, no double prefix |
| openrouter | thinkingmachines/inkling-small:free | local proxy/stand-in | Explicit provider still authoritative |
| custom | existing working model | existing custom endpoint | Existing behavior preserved |
| standard non-OpenRouter provider | existing valid model | existing endpoint | Existing behavior preserved |
| legacy arbitrary label | existing working model | existing endpoint | Compatibility policy honored |
| missing connection | any | any | Existing actionable missing-connection error |
| no connection (optional scope) | OpenRouter-native ID | openrouter.ai | Shared SDK inference, if implemented |
| no connection | existing working model | unrelated/lookalike host | No accidental OpenRouter inference |
This issue was created by an AI agent (OpenHands) on behalf of Graham Neubig.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Verified against the repository: ProviderConnection.provider is stored as free text but never translated into routing — LLMProfileStore._resolve_provider_connection() applies only the connection's api_key and base_url via model_copy(update=...). A profile linked to an openrouter connection with model thinkingmachines/inkling-small:free therefore still fails LiteLLM provider inference. The repository already funnels every path that turns a stored or forwarded profile into a runnable LLM through one resolution entry point (LLMProfileStore.load() for activation, launch, the OpenAI-compatible gateway and meta-profiles; the public resolve_provider_connection() for draft validation and switch_llm), so extending that single mechanism is the authoritative way to deliver this, and no second normalization site may be introduced. Upstream evidence is real: OpenHands#17233 is a reproduced user report, and the OpenHands-side PR #19743 is a frontend-only workaround that leaves other writers and existing saved profiles unfixed.
Scope is the issue's required first delivery only: explicit provider connections become authoritative for routing with centralized model-ID normalization in the shared SDK resolution path, working for existing saved profiles, draft validation, and the REST/SDK/Canvas writers. Resolved decisions: an explicit connection provider takes precedence over endpoint-hostname inference for recognized providers; custom/unspecified connections keep today's inference behavior; unrecognized legacy provider labels keep today's routing semantics rather than becoming a strict enum (backward compatibility per repository guidance); aggregator-native IDs that contain another vendor's name are not treated as conflicts.
Non-goals (explicit): replacing the encrypted connection/profile stores; changing credential rotation to mutate running conversations; live model discovery or expanding the Basic tab catalog (per the maintainer decision on OpenHands#17577); a generic provider + "/" + model prefix rule; requiring existing profiles to be resaved. Deferred to a documented follow-up: inline OpenRouter inference for connection-less configs with https://openrouter.ai/api/v1 (issue section E). Until that follow-up, the inline-base-URL part of OpenHands#17233 is not claimed fixed; note that is_openrouter()/detect_provider() already key off a substring match on openrouter.ai in the base URL for headers and runtime metadata, which a lookalike host such as openrouter.ai.example.com satisfies — the deferred scope should address that when picked up. Companion Canvas/OpenHands work (dependency update, end-to-end regression, retiring the frontend-only rule) belongs to OpenHands/OpenHands per repository ownership and is linked, not implemented here.
Acceptance Criteria
- A profile linked to a connection with
provider: "openrouter"and modelthinkingmachines/inkling-small:freeresolves to an effective configuration that routes through OpenRouter; a regression test demonstrates the originalLLM Provider NOT providedfailure before the fix and success after. -
anthropic/claude-sonnet-4under an OpenRouter connection routes through OpenRouter, not direct Anthropic; an already-qualifiedopenrouter/anthropic/claude-sonnet-4remains semantically unchanged with no duplicate prefix; suffix-bearing IDs such as:freeare preserved verbatim. - Normalization is idempotent: resolving the same profile repeatedly (load, activation, switch) yields the same effective model ID with no accumulated prefixes.
- An explicit OpenRouter connection routes through OpenRouter with both the default endpoint and a custom/proxy
base_url; provider identity does not depend on endpoint hostname. - A previously saved, unprefixed OpenRouter-linked profile works after upgrade without being edited, resaved, or hand-modified; a new profile created through the agent-server REST API and one loaded via the standalone SDK resolve the same effective routing.
- Draft validation (
POST /profiles/{name}/validate) and runtime execution use the same resolution implementation and agree on whether a linked configuration is valid. - All consumers of the shared resolver (activation, profile-based launch including meta-profiles,
switch_llm, the OpenAI-compatible gateway, and in-memory draft resolution) are audited with regression coverage for any path that would otherwise bypass resolution; already-running conversations keep their snapshot semantics. -
custom/unspecified connections and standard non-OpenRouter provider configurations keep existing routing behavior; valid aggregator-native IDs containing another vendor's name are not falsely rejected. - Unrecognized legacy provider labels retain today's routing semantics, and the compatibility policy for them is documented.
- The precedence among explicit connection provider, model-ID qualification, and endpoint inference is documented and tested; detectable incompatible combinations fail with an actionable error naming the conflicting fields and never exposing credentials.
- Existing contracts remain intact: connection-owned
api_key/base_urlincluding authoritativebase_url: null, the missing-connection error, encryption/redaction, and read-at-use key rotation — covered by the existing suites passing unchanged or with explicit, reviewed updates. - Provider-dependent derived state (provider info, model capabilities, runtime metadata) is consistent with the resolved provider/model after resolution, verified with a credential-free local OpenAI-compatible stand-in test that dispatches a real request through SDK resolution and checks the receiving endpoint and wire model ID; error reporting never includes API keys or other secrets.
- Relevant SDK LLM/profile and agent-server profile/provider-connection tests plus lint and type checks pass.
- The user-facing provider/model contract is documented, including the intentionally deferred inline base-URL boundary tracked as a follow-up, and the companion OpenHands dependency-update/UI-regression work is linked so the SDK remains the single source of truth alongside PR #19743.
Activity
all-hands-bot commentedon Nov 15, 2026
#6862 is a broad feature/architecture request to make provider connections authoritative for LLM routing and centralize model-ID normalization; no existing issue matches its central ask, but it overlaps materially with #4247 (same 'LLM Provider NOT provided' root cause for unrecognized model IDs with a custom endpoint, already being fixed by open PR #6816 in the same LLMProvider path) and #5207 (same 'one store-owned resolver across runtime paths' goal for provider connections). It should stay open as its own thread, but linking the overlapping work would prevent competing/divergent fixes.
Found 3 possible duplicate issues:
These may not be exact duplicates, but the scope appears to overlap enough that keeping discussion in one place may be more useful.
This comment was created by an AI assistant (OpenHands) on behalf of the repository maintainer.