Deployed live at: conversational-gujarati-prototype-01.alex-hortfrancis.workers.dev
Prototype for a language learning app that helps users learn to speak Gujarati.
The project uses OpenAI's Agents SDK & Realtime API, with React, Vite, Hono, and Cloudflare Workers.
This project is based on this previous repo: hortfrancis/openai-realtime-agent-deployment-spike-01
git clone https://github.com/hortfrancis/conversational-gujarati-prototype-01.git.. or, using the GitHub CLI:
gh repo clone hortfrancis/conversational-gujarati-prototype-01cd conversational-gujarati-prototype-01npm installGet your OpenAI API key from OpenAI's platform.
Create a .dev.vars file in the root directory and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_keyImportant
You need to set up billing on your OpenAI account, and add some credit, to use the Realtime API.
If you don't do this, the Realtime connection will fail to initialise.
Start the development server:
npm run devOpen your browser and navigate to http://localhost:5173 (or the URL provided in the terminal) to see the React frontend.
You will need a Cloudflare account. If you don't have one, you can sign up at Cloudflare.
The project is set up to use Cloudflare Workers for deployment. The frontend in the client browser calls the backend Worker to fetch an ephemeral (temporary) API key from OpenAI.
This caches your Cloudflare credentials on your local machine.
npx wrangler loginThis creates a dist/ directory and bundles the React app for production here.
npm run buildThis runs wrangler deploy using npm.
npm run deployThis should create a new Workers deployment, available at the default URL of https://conversational-gujarati-prototype-01.<username>.workers.dev.
The URL will be printed in the terminal after deployment.
You will need to add your OpenAI API key to the deployed Cloudflare Worker. You can do this in the Cloudflare dashboard.
- Go to "Workers & Pages" (in the left sidebar)
- Find the deployed Workers instance in the list & click the name
- Go to the "Settings" tab of the Worker instance
- Scroll down to the "Variables and Secrets" section
- Click "Add"
- In the "Variables and Secrets" panel:
- "Type" = "Secret"
- "Variable name" =
OPENAI_API_KEY - "Value" = your API key
- Click "Deploy"
This will redeploy your Workers instance with the OpenAI API key as a environment secret.
Cloudflare's own documentation also covers adding secrets to Workers.