What is the correct way to list the available models using the API?

I’m using the latest GenAI SDK:

import { GoogleGenAI, HarmCategory, HarmBlockThreshold } from "@google/genai";

In general, everything works fine, as long as I know the name of the model.

However, I need the list of model names to select the one I want in my UI. I searched the Google documentation and asked Gemini 2.5 Pro. It was quite confused, spitting out a code example with the old SDK and mixing up both SDKs and classes, until it finally gave up and reported that actually you cannot do it using genai and have to use a direct REST API call instead. So, based on the REST API docs, (which has a Python example for genai client.models.list(), but no JavaScript example), I came up with the following GET request:

https://generativelanguage.googleapis.com/v1beta/models?key=<api_key_here>

It works, but passing the API key in a URL does not seem like a good practice. Also, it seems weird that I have to use a raw HTTP request for listing, and there is no proper API function in the “google/genai”.

And some results in the list look mixed up. I understand that some models are just pointers to the others. But check out the displayName “Gemini 2.5 Flash Preview 04-17” - it appears 4 times in that list for the following models:

“models/gemini-2.5-flash-preview-04-17”- correct, it’s “Gemini 2.5 Flash Preview 04-17”
“models/gemini-2.0-flash-thinking-exp-01-21” - why?
“models/gemini-2.0-flash-thinking-exp” - why?
“models/gemini-2.0-flash-thinking-exp-1219” - why?

I have checked it a few times, and the duplicated name has been there for weeks now. What’s going on?