# Refresh OpenRouter models after setting API key \(\#58551\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/307ea5a0eed1a8437120b61536df199236cb1232)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 307ea5a0eed1a8437120b61536df199236cb1232

Requested commit: 307ea5a0eed1a8437120b61536df199236cb1232

Commit: 307ea5a0eed1a8437120b61536df199236cb1232

Tree: 4509d5982b68305191b9faa2ca9e37b61158db15

Author: Zhiwei Liang

Committer: GitHub

## Message

```
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>
```

## Parents

- [99739ef0477605c112f5e2f57a9364005ff7e5b3](https://git.cafe/gitcafe/zed/commit/99739ef0477605c112f5e2f57a9364005ff7e5b3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/307ea5a0eed1a8437120b61536df199236cb1232?format=markdown)
