Skip to content

Conversation

@b3nw
Copy link
Contributor

@b3nw b3nw commented Jan 4, 2026

Context

Enables dynamic model selection for OpenAI Compatible providers by fetching available models from the /v1/models endpoint. Previously, users had to manually enter model IDs. This also fixes a bug where model names with multiple slashes (e.g., chutes/moonshotai/Kimi-K2-Instruct) were being truncated to only show the first two path segments.

Closes #3271

Implementation

Dynamic Model Fetching

  • Added new src/api/providers/fetchers/openai.ts that fetches models from OpenAI-compatible /v1/models endpoints
  • Models are returned with displayName property set to the raw model ID for proper display
  • Integrated with the existing RouterModels system for caching and provider-based model lists

Model Name Parsing Fix

  • Fixed prettyModelName() to handle model IDs with multiple slashes
  • Changed mainId.split("/")[1] to mainId.split("/").slice(1).join("/") to preserve the full model name after the provider prefix
  • Added comprehensive test suite in prettyModelName.spec.ts

Data Flow
API (/v1/models) → openai.ts fetcher → RouterModels cache → useProviderModels hook → ModelSelector UI ↘ sets displayName ↘ fallback to prettyModelName()

How to Test

How to Test
Configure an OpenAI Compatible provider (e.g., Chutes, OpenRouter, or any OpenAI-compatible API)
Set the API key and base URL in provider settings
Open the model selector dropdown
Verify that:
Available models are fetched and displayed automatically
Model names with slashes display the full name (not truncated)
Models like moonshotai/Kimi-K2-Instruct-0905 show as "Moonshotai / Kimi K2 Instruct 0905"
Run tests:

cd webview-ui && pnpm test src/utils/__tests__/prettyModelName.spec.ts
cd src && pnpm test api/providers/fetchers/__tests__/openai.spec.ts

Get in Touch

b3n.w on Kilo discord.

…ilo-Org#3271)

Reclassify 'openai' from CustomProvider to DynamicProvider to enable
model fetching in the chat panel dropdown. The provider was incorrectly
excluded from the routerModels system which powers model selection.

Changes:
- Move 'openai' from customProviders to dynamicProviders array
- Add 'openai' to dynamicProviderExtras with apiKey, baseUrl, headers
- Add OpenAI candidate to routerModels in webviewMessageHandler
- Create openai.ts model fetcher for /models endpoint
- Update getModelsByProvider to return routerModels.openai
- Add OpenAI params to useRouterModels hook
- Update test fixtures with openai RouterModels entry

Extended model info parsing:
- Parse context_window, context_length, max_context_length from API
- Parse max_output_tokens, max_tokens for output limits
- Parse supports_vision, supports_images, vision flags for image support
- Parse supports_function_calling, supports_tools for tool support
- Parse input_cost_per_token, output_cost_per_token for pricing
- Parse description when provided by the API
- Use .passthrough() to preserve extended fields
@changeset-bot
Copy link

changeset-bot bot commented Jan 4, 2026

⚠️ No Changeset found

Latest commit: b8c553f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/b3nw/kilocode/new/fix/issue-3271-openai-compatible-model-selection?filename=.changeset/stupid-shoes-change.md&value=---%0A%22kilo-code%22%3A%20patch%0A%22%40roo-code%2Fvscode-webview%22%3A%20patch%0A%22%40roo-code%2Ftypes%22%3A%20patch%0A---%0A%0Afix%3A%20enable%20dynamic%20model%20selection%20for%20OpenAI%20Compatible%20provider%20(%23%E2%80%A6%0A)

@b3nw b3nw force-pushed the fix/issue-3271-openai-compatible-model-selection branch from 0957f5a to 4fe64da Compare January 5, 2026 01:25
Add openai provider to test mocks in both webviewMessageHandler.spec.ts and
ClineProvider.spec.ts to match the implementation in webviewMessageHandler.ts
which includes OpenAI Compatible provider in the candidates array for model
fetching.
@b3nw b3nw force-pushed the fix/issue-3271-openai-compatible-model-selection branch from 4fe64da to b8c553f Compare January 5, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] The list of models doesn't load in the panel below on the OpenAI Compatible provider

1 participant