Gemini’s WebSocket Won’t Talk to Me :)

Hello,

I’m using Delphi (Object Pascal), so I’m unable to use the official Google GenAI libraries.

I’m trying to connect to the Gemini Multimodal Live API via the following WebSocket URLs:

wss://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent?key={my_key}
wss://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:streamGenerateContent?key={my_key}
wss://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-001:streamGenerateContent?key={my_key}

However, the WebSocket handshake fails in both:

  • My Delphi application, and
  • Browser-based WebSocket testing tools (e.g., Chrome extensions).

The server rejects the connection during the handshake phase, and no session is established.


:red_question_mark: My Questions

  1. What is my mistake? (Could you please point out what I’m doing wrong?)
  2. Are these streamGenerateContent WebSocket endpoints intended to be used directly via raw WebSocket clients?
  3. If so, are any additional headers or protocols required beyond the api_key query parameter?
  4. Or is this functionality only available via the official Python SDK (google-genai) or other client libraries?

:magnifying_glass_tilted_left: WebSocket Connection Details

URL:  wss://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-001:streamGenerateContent?key={my_key}
Host: generativelanguage.googleapis.com
Path: /v1beta/models/gemini-2.0-flash-001:streamGenerateContent
SSL:  Enabled
Port: 443

Log:

Attempting to connect to WebSocket...
Disconnected from Gemini API WebSocket

I would appreciate clarification on whether these endpoints are publicly available for custom WebSocket clients, or only accessible through official SDKs.
Thanks in advance!

1 Like

Hi @Gil,

Welcome to the forum! While I’m not deeply familiar with WebSocket technology myself, the documentation linked below might provide some useful information, particularly if you need to configure any specific parameters for WebSocket functionality:

Hi Siva,
Thank you very much. Of course I am familiar with the documentation.
The problems seems to be incorrect url. I should have used:
‘wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1alpha.GenerativeService.BidiGenerateContent?key=’ + FAPIKey;

Have a great day,
Gil.

1 Like