fix: prefer model-level api from runtime config over inferApiFromProvider fallback#500
Merged
jalehman merged 2 commits intoApr 28, 2026
Conversation
…ider fallback Resolves Martian-Engineering#251. When a user declares `models.providers.<p>.models[*].api` in runtime config, that declaration should win over the hardcoded `inferApiFromProvider()` map. Concrete repro: setting `summaryModel: "openai-codex/gpt-5.4-mini"` against the paid OpenAI API endpoint (where the `openai-codex` provider is configured with `baseUrl: https://api.openai.com/v1` and the model declares `api: "openai-completions"`) was failing every compaction call with `error_message=Not Found`. The dispatch-site fallback chain at `src/plugin/index.ts:1535-1556` couldn't see the user-declared api because: - `mod.getModel(provider, model)` returned a model object without `.api` - `resolveProviderApiFromRuntimeConfig` only looked at provider-level `api` - The first-models-list fallback hit a different model So the chain bottomed out at `inferApiFromProvider("openai-codex")` → `"openai-codex-responses"`, sending Codex Responses-shaped requests to api.openai.com which doesn't speak that protocol. Fix: add `resolveModelApiFromRuntimeConfig(config, provider, model)` that walks `models.providers.<p>.models[]` and returns the matching model's `api` if declared. Slot it into the dispatch chain right after the provider-level runtime resolver and before the first-models-list and `inferApiFromProvider` fallbacks. Behavior is purely additive: users who don't declare `models[].api` see no change, and `inferApiFromProvider`'s existing semantics for Codex CLI auth users (no explicit api) are preserved. - Adds: `resolveModelApiFromRuntimeConfig` (exported for testability) - Tests: 7 new cases covering happy path, case-insensitive provider match, multi-provider disambiguation, missing/malformed config, missing api field - All 782 tests pass (43 + 1 new file, 775 + 7 new cases) - Build clean (esbuild → 624kb)
This was referenced Apr 28, 2026
Merged
This was referenced May 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ider fallback
Resolves #251. When a user declares
models.providers.<p>.models[*].apiin runtime config, that declaration should win over the hardcodedinferApiFromProvider()map.Concrete repro: setting
summaryModel: "openai-codex/gpt-5.4-mini"against the paid OpenAI API endpoint (where theopenai-codexprovider is configured withbaseUrl: https://api.openai.com/v1and the model declaresapi: "openai-completions") was failing every compaction call witherror_message=Not Found. The dispatch-site fallback chain atsrc/plugin/index.ts:1535-1556couldn't see the user-declared api because:mod.getModel(provider, model)returned a model object without.apiresolveProviderApiFromRuntimeConfigonly looked at provider-levelapiinferApiFromProvider("openai-codex")→"openai-codex-responses", sending Codex Responses-shaped requests to api.openai.com which doesn't speak that protocol.Fix: add
resolveModelApiFromRuntimeConfig(config, provider, model)that walksmodels.providers.<p>.models[]and returns the matching model'sapiif declared. Slot it into the dispatch chain right after the provider-level runtime resolver and before the first-models-list andinferApiFromProviderfallbacks.Behavior is purely additive: users who don't declare
models[].apisee no change, andinferApiFromProvider's existing semantics for Codex CLI auth users (no explicit api) are preserved.resolveModelApiFromRuntimeConfig(exported for testability)