Refresh OpenRouter models after setting API key (#58551)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Summary

Adding an OpenRouter API key did not populate the model list until the
app was
restarted. `set_api_key` stored the credential but never triggered a
model
fetch, so until re-authentication happened (on restart or a settings
change)
the picker showed only the user-configured `settings.available_models`,
not the
models returned by the OpenRouter API.

This makes `set_api_key` refresh the models right after the key is
stored,
mirroring how `authenticate` already does it.

## Changes

- `set_api_key` awaits the credential store and then calls
`restart_fetch_models_task`, so the API model list loads immediately
after a
  key is entered (and is cleared when the key is removed).
- `fetch_models` now maps `list_models` errors via
`LanguageModelCompletionError::from`, preserving the real OpenRouter
error
  message instead of wrapping it in a generic `Other(...)`.

Release Notes:

- Fixed OpenRouter models not appearing until restart after adding an
API key

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
307ea5a0eeZhiwei Liang committed on 6/4/2026, 4:03:35 PM· committed by GitHubparent99739ef
1 file changedLine totals unavailable