OpenAI compatibility REST example fails

The example REST request to the openAI compatibility endpoint from here fails with a 400:

$ curl "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GEMINI_API_KEY" \
-d '{
    "model": "gemini-1.5-flash",
    "messages": [
        {"role": "user", "content": "Explain to me how AI works"}
    ]
    }'
[{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}
]%

Am I doing something wrong?

Hi @tdouglasph, Welcome to the forum!!!

Don’t use $ sign before GEMINI_API_KEY as mentioned in the doc. Use this colab gist.

Got it thanks, it worked when I replaced it with the API key rather than trying to read it from the variable.