Skip to content

Conversation

@demonarch
Copy link

Summary

This PR enhances the OpenRouter integration to dynamically fetch available models from the OpenRouter API, similar to how Ollama fetches models locally.

Changes

  • New: src/utils/openrouter.ts - OpenRouter API utility to fetch 345+ available models
  • Updated: Model selection flow to display browsable list instead of requiring manual text input
  • Enhanced: Error handling with helpful messages when API is unreachable
  • Added: FEATURES.md to document changes and improvements

User Experience

Before:

  • Users had to manually type model names (error-prone)
  • Required visiting openrouter.ai/models to find identifiers

After:

  • Browse and select from complete list of OpenRouter models
  • Arrow key navigation through sorted model list
  • Real-time fetching from OpenRouter API
  • Graceful fallback with helpful error messages

Testing

  • ✅ Successfully fetches 345+ models from OpenRouter API
  • ✅ Models are properly sorted alphabetically
  • ✅ TypeScript compilation passes
  • ✅ Error handling works correctly

Backward Compatibility

All existing OpenRouter configurations and stored preferences continue to work without any changes required.

- Add OpenRouter API utility to fetch available models
- Update model selection to show browsable list instead of free-text input
- Add graceful error handling for API failures
- Update documentation in FEATURES.md
@virattt
Copy link
Owner

virattt commented Feb 6, 2026

Thanks for the contribution — I spotted a couple of issues that need fixing before we can merge:

src/hooks/useModelSelection.ts

1. Type mismatch: string[] passed where Model[] expected

// Current (broken)
const openRouterModels = await getOpenRouterModels();
setPendingModels(openRouterModels);

// Suggested
const openRouterModelIds = await getOpenRouterModels();
const openRouterModels: Model[] = openRouterModelIds.map((id) => ({ id, displayName: id }));
setPendingModels(openRouterModels);

getOpenRouterModels() returns string[] but pendingModels is Model[]. The ModelSelector component accesses .id and .displayName on each item, both of which resolve to undefined on a plain string. The model list renders as blank rows. The Ollama branch right below does this correctly with the .map() conversion.

2. Wrong state setter in the API key flow

// Current (broken)
} else {
  setPendingModels([fullModelId]);
  setAppState('api_key_confirm');
}

// Suggested
} else {
  setPendingSelectedModelId(fullModelId);
  setAppState('api_key_confirm');
}

handleApiKeyConfirm and handleApiKeySubmit both read pendingSelectedModelId to complete the switch. Since it is never set here, users without an existing API key will always hit the "No model selected." error after entering a valid key. Compare with handleModelInputSubmit which correctly calls setPendingSelectedModelId.

src/components/ModelSelector.tsx

3. openrouter: prefix not normalized (nit)

// Current
const normalizedCurrentModel = providerId === 'ollama' && currentModel?.startsWith('ollama:')
  ? currentModel.replace(/^ollama:/, '')
  : currentModel;

// Suggested
const prefix = `${providerId}:`;
const normalizedCurrentModel = currentModel?.startsWith(prefix)
  ? currentModel.slice(prefix.length)
  : currentModel;

Now that OpenRouter uses the list-based ModelSelector, the stored model (e.g. openrouter:anthropic/claude-3.5-sonnet) won't match any bare ID in the list, so the current-model checkmark never appears. A generic prefix strip covers both Ollama and OpenRouter.

UX concern

OpenRouter exposes 345+ models. The ModelSelector renders every item at once with only arrow-key navigation, which is effectively unusable at that volume. The previous free-text input was arguably better for this case, or the list needs a text-filter/search to be viable.

# Severity Issue
1 bug string[]Model[] mismatch, list renders blank
2 bug setPendingModels instead of setPendingSelectedModelId, API key flow always fails
3 nit openrouter: prefix not stripped, no checkmark on current model
4 optional 345+ models with no search/filter

@virattt virattt added the bug Something isn't working label Feb 6, 2026
Repository owner deleted a comment from haydenbeamish Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants