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?
Hi @progmars ,
In genai-js
, we have an API ai.models.list
that is used to fetch all the available models you can use with the SDK. The list of models you are getting from api seems correct to me; it will give you all available models. You can use the following code snippet to fetch the list of models.
const ai = new GoogleGenAI({
apiKey: process.env.GEMINI_API_KEY,
});
console.log
const models = await ai.models.list({config: {pageSize: 10}});
for await (const model of models) {
console.log(model.name);
}
Thank You!!
Thank you. After updating the library, ai.models.list started working. It was failing silently in older versions.
However, model names still seem messed up. Please check the models with the following names:
models/gemini-2.0-flash-thinking-exp-01-21
models/gemini-2.0-flash-thinking-exp
models/gemini-2.0-flash-thinking-exp-1219
Why do they all have the following JSON attributes?
“version”: “2.5-preview-04-17”,
“displayName”: “Gemini 2.5 Flash Preview 04-17”
How can 2.0-flash-thinking based models be named as Gemini 2.5 Flash preview-04-17 ?
Hi @progmars
It seems that your interpretation is in the wrong direction. Those models are based on the “version” attribute. Which means that the experimental model names have been upgraded internally to a preview model. While keeping the old name to avoid breakage.
Cheers
Hi @progmars
The API key can also be provided in the HTTP request header instead of a URL parameter: “x-goog-api-key”. An HTTP request would look like this.
# Get a list of available models.
GET https://generativelanguage.googleapis.com/v1beta/models?pageSize=60
x-goog-api-key: {{apiKey}}
Or if you’re interested in the OpenAI compatible endpoint(s)
GET https://generativelanguage.googleapis.com/v1beta/openai/models
Authorization: Bearer {{apiKey}}
Cheers
Ah, I see now, thanks.
I’m using displayName in my app UI, and for users, it’s quite confusing to see four models with “Gemini 2.5 Flash Preview 04-17”. I guess I’ll need to filter the list to remove the duplicates using the version as the key, as you suggested.
2 Likes