Setting up a Relay Server

Connecting directly to tensorstudio through SDK on browser exposes your api-key. If you are running your own relay server, e.g. with the Realtime Console, you can instead connect to the relay server URL.

1. Install Realtime Console

First, install the OpenAI Realtime Console globally:
git clone https://github.com/soketlabs/realtime-console.git
cd realtime-console
npm install

2. Set environment variables for realtime-console

Create a .env file in realtime-console directory
OPENAI_API_KEY=<your-api-key>

3. Start the Relay Server

Run relay server in a new terminal:
cd realtime-console
npm run relay
The relay server will start running on ws://localhost:8081 .

Start using Tensorstudio Speech API through NodeJS SDK

Install NodeJS SDK

npm install https://github.com/soketlabs/openai-realtime-api-beta

Using Node.js SDK

import { RealtimeClient } from '@openai/realtime-api-beta';

const client = new RealtimeClient({
  url: 'your-relay-server-url'
});

Production Deployment

For production:
  1. Use secure WebSocket (WSS) with SSL/TLS
  2. Update the relay server URL to your production domain
  3. Add authentication if needed
  4. Use environment variables for configuration
Example production configuration:
const client = new RealtimeClient({
  baseURL: 'wss://your-domain.com/relay',
  // Other configuration options
});

Security Considerations

  • Never expose your OpenAI API key in client-side code
  • Use HTTPS/WSS in production
  • Implement rate limiting
  • Add authentication to your relay server
  • Monitor server usage and implement proper error handling

Common Issues

  1. Connection Refused: Make sure the relay server is running
  2. SSL/TLS Errors: Check certificate configuration for WSS
  3. Authentication Errors: Verify API key in .env file