parseModelsResponse function
Parses body (the raw /models JSON) into ModelsEndpointInfo.
Dialects accepted: OpenAI/OpenRouter {"data": [{"id": ...}]} and the
{"models": [{"alias": ...}]} shape some gateways use (id falls back to
alias, then name).
Implementation
ModelsEndpointInfo parseModelsResponse(String body) {
final decoded = jsonDecode(body);
final data = decoded is Map ? (decoded['data'] ?? decoded['models']) : null;
final ids = <String>[];
final windows = <String, int>{};
final maxTokens = <String, int>{};
if (data is List) {
for (final entry in data) {
_collectModelEntry(entry, ids, windows, maxTokens);
}
}
ids.sort();
return (ids, windows, maxTokens);
}