Skip to content

please provide more detailed code. #21184

@taojoe

Description

@taojoe

Existing documentation URL(s)

What changes are you suggesting?

hi cloudflare team,

I'm trying to use the realtime api of google. All the code you provided are working, but i need to send an user content to google, but there is no response. so please give more code, so that I can figure out what to do.

here is my code.

import WebSocket from "ws";
import delay from "delay";


async function main(){
  const ws = new WebSocket("wss://gateway.ai.cloudflare.com/....", ['cf-aig-authorization.<token>']);
  
  let opened=false;
  
  ws.on("open", () => {
    console.log("Connected to server.");
    opened=true;
  });
  ws.on("message", (message:any) => {
    const {type, data}=message;
    console.log('message:', message.toString());
  });
  await delay(1000*1);
  while(true){
    console.log('check opened');
    if(opened){
      break;
    }
    await delay(1000*1);
  }
  ws.send(
    JSON.stringify({
      setup: {
        model: "models/gemini-2.0-flash-exp",
        generationConfig: { responseModalities: ["TEXT"] },
      },
    }),
  );
  await delay(1000*5);
  console.log('sending msg');
  ws.send(JSON.stringify({
    clientContent:{
      turns:[
        {
          role:'user',
          parts:['hello'],
        }
      ],
      turn_complete:true,
    }
  }));
  console.log('sent msg');
  await delay(1000*10);
}


main()

Additional information

No response

Metadata

Metadata

Labels

content:editRequest for content editsdocumentationDocumentation editsproduct:ai-gatewayAI Gateway: https://developers.cloudflare.com/ai-gateway/

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions