OpenAI list models returns HTTP 401

Hi,
the new OpenAI compatible endpoint https://generativelanguage.googleapis.com/v1beta/openai/models returns an HTTP 401 Unauthorized only instead of the expected list of available models.

GET https://generativelanguage.googleapis.com/v1beta/openai/models
Authorization: Bearer {{apiKey}}

See https://platform.openai.com/docs/api-reference/models/list for reference and expected response.

FYI, I’m using the same REST calls for chat completions and embeddings sucessfully. The information about this new endpoint is based on the $discovery response - revision 20241127

Anyone with further information? Thanks.

2 Likes

Encountered the same problem

1 Like

As does this:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ['GEMINI_API_KEY'],
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
)

response = client.chat.completions.create(
    model="gemini-1.5-flash",
    n=1,
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {
            "role": "user",
            "content": "list planets"
        }
    ]
)

print(response.choices[0].message)

models = client.models.list()
... causes this:
openai.AuthenticationError: Error code: 401 - {'error': {'code': 401, 'message': 'Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.', 'status': 'UNAUTHENTICATED'}}
print(f"\ngoogle_models():\n{models}\n")

C’mon, it’s just a list of models.