Skip to content

Commit c49f6d0

Browse files
YedPoolclaude
andcommitted
Fix critical communication issues in 3-app deployment architecture
- Fixed frontend to use token server instead of voice agent for token requests - Standardized deployment name environment variables (LIVEKIT_DEPLOYMENT_NAME) - Removed hardcoded credentials from configs, moved to Cerebrium dashboard secrets - Fixed authentication mismatch by removing unnecessary auth from token server - Added comprehensive CORS origins for development and production - Updated service discovery to use consistent project ID pattern - Added deployment fixes documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0ba8df0 commit c49f6d0

14 files changed

Lines changed: 983 additions & 278 deletions

File tree

.env.example

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,25 @@ VITE_LIVEKIT_API_SECRET=your_livekit_api_secret
2020
VITE_DEEPGRAM_API_KEY=your_deepgram_api_key
2121
VITE_OPENAI_API_KEY=your_openai_api_key
2222

23-
# Voice Agent Configuration
24-
VITE_VOICE_AGENT_URL=https://your-cerebrium-voice-agent.com/api
23+
# Service Discovery Configuration (NEW - Automatic URL Generation)
24+
VITE_CEREBRIUM_PROJECT_ID=your-project-id
25+
26+
# Cerebrium Secrets Configuration (set these in Cerebrium dashboard)
27+
# ===================================================================
28+
# REQUIRED: Set these in ALL service dashboards:
29+
# CEREBRIUM_PROJECT_ID=your-project-id
30+
# LIVEKIT_API_KEY=devkey
31+
# LIVEKIT_API_SECRET=secret
32+
33+
# REQUIRED: Set these in Agent dashboard only:
34+
# DEEPGRAM_API_KEY=your_deepgram_api_key
35+
36+
# OPTIONAL: Override service names if needed:
37+
# LIVEKIT_DEPLOYMENT_NAME=gmail-livekit-server
38+
# TOKEN_SERVER_DEPLOYMENT_NAME=gmail-token-server
39+
# AGENT_DEPLOYMENT_NAME=gmail-voice-assistant-allinone
40+
41+
# Manual URL Override (only if service discovery fails)
42+
# VITE_TOKEN_SERVER_URL=https://api.aws.us-east-1.cerebrium.ai/v4/p-xxx/gmail-token-server
43+
# VITE_VOICE_AGENT_URL=https://api.aws.us-east-1.cerebrium.ai/v4/p-xxx/gmail-voice-assistant-allinone
44+
# LIVEKIT_URL=wss://api.aws.us-east-1.cerebrium.ai/v4/p-xxx/gmail-livekit-server:7880

DEPLOYMENT_FIXES.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# 🚀 Critical Deployment Fixes Applied
2+
3+
## Fixed Issues
4+
5+
### ✅ 1. Frontend Token Request Flow
6+
**Problem**: Frontend was calling voice agent URL for tokens instead of token server
7+
**Fix**: Updated `useVoiceAgent.js` to use `cerebriumApi.getLiveKitToken()`
8+
- Now correctly routes to `gmail-token-server` service
9+
- Simplified token request flow
10+
11+
### ✅ 2. Service Discovery Variables
12+
**Problem**: Inconsistent deployment name environment variables
13+
**Fix**: Standardized to `LIVEKIT_DEPLOYMENT_NAME` across all services
14+
- Updated `livekit-server/main.py` to use consistent variable name
15+
16+
### ✅ 3. Security Credentials
17+
**Problem**: Hardcoded `devkey`/`secret` in production config
18+
**Fix**: Moved to Cerebrium dashboard secrets
19+
- Removed hardcoded values from `livekit-server/cerebrium.toml`
20+
- Added validation in `livekit-server/main.py`
21+
22+
### ✅ 4. Authentication Mismatch
23+
**Problem**: Token server expected auth header, frontend couldn't provide it
24+
**Fix**: Removed unnecessary authentication from token server
25+
- Updated `cerebriumApi.js` to remove Authorization header
26+
- Token server now accepts requests without auth
27+
28+
### ✅ 5. CORS Configuration
29+
**Problem**: Missing localhost origins for development
30+
**Fix**: Added comprehensive CORS origins
31+
- Added localhost ports 3000, 5173, 5174
32+
- Added deployment platforms (Vercel, Netlify)
33+
34+
## Required Environment Variables
35+
36+
### Set in Cerebrium Dashboard Secrets (ALL services):
37+
```bash
38+
CEREBRIUM_PROJECT_ID=your-project-id
39+
LIVEKIT_API_KEY=your-secure-api-key
40+
LIVEKIT_API_SECRET=your-secure-api-secret
41+
LIVEKIT_DEPLOYMENT_NAME=gmail-livekit-server
42+
```
43+
44+
### Set in Voice Agent Dashboard Only:
45+
```bash
46+
DEEPGRAM_API_KEY=your-deepgram-api-key
47+
```
48+
49+
### Set in Frontend (.env):
50+
```bash
51+
VITE_CEREBRIUM_PROJECT_ID=your-project-id
52+
VITE_CEREBRIUM_API_KEY=your-inference-token
53+
```
54+
55+
## Communication Flow (Fixed)
56+
57+
1. **Frontend****Token Server**: `cerebriumApi.getLiveKitToken()`
58+
2. **Token Server****LiveKit Server**: Service discovery via project ID
59+
3. **Frontend****LiveKit Server**: WebRTC connection with token
60+
4. **LiveKit Server****Voice Agent**: Agent connects for processing
61+
62+
## Testing Next Steps
63+
64+
1. Deploy all 3 services to Cerebrium
65+
2. Set environment variables in dashboards
66+
3. Test token generation: `POST /token` to token server
67+
4. Test WebRTC connection from frontend
68+
5. Verify agent can connect to LiveKit server
69+
70+
## Notes
71+
72+
- All services now use consistent service discovery
73+
- Security credentials properly isolated
74+
- CORS configured for development and production
75+
- Authentication simplified to prevent 401 errors

cerebrium/cerebrium.toml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,27 @@ cooldown = 120
1818
dockerfile = false
1919
python_packages = "./requirements.txt"
2020
include = [".", "*.py"]
21-
22-
[cerebrium.predict]
23-
python_version = "3.11"
24-
gpu_count = 1
25-
setup_commands = [
26-
"apt-get update && apt-get install -y curl wget",
27-
"curl -fsSL https://ollama.ai/install.sh | sh"
21+
# Install system dependencies then download models
22+
shell_commands = [
23+
"apt-get update && apt-get install -y curl",
24+
"curl -fsSL https://ollama.com/install.sh | sh",
25+
"python main.py download-files"
2826
]
2927

30-
# Main entry point
31-
[cerebrium.app]
32-
main = "main.py"
28+
# Custom Runtime Configuration - LiveKit Agent Worker
29+
[cerebrium.runtime.custom]
30+
port = 8600
31+
entrypoint = ["python", "main.py", "dev"]
3332

3433
[cerebrium.env]
35-
# Required API Keys (All-in-One Deployment)
34+
# Required API Keys (All-in-One Deployment) - Set these via Cerebrium dashboard
3635
# DEEPGRAM_API_KEY = "your-deepgram-key" # For Nova-2 STT + Rime TTS
3736
# OPENAI_API_KEY = "your-openai-key" # For GPT-4o-mini LLM
3837

39-
# Internal service configuration (auto-configured)
40-
LIVEKIT_URL = "ws://localhost:7880"
41-
LIVEKIT_API_KEY = "devkey"
42-
LIVEKIT_API_SECRET = "secret"
38+
# LiveKit Configuration - Set these via Cerebrium dashboard secrets
39+
# LIVEKIT_URL = "wss://your-livekit-server"
40+
# LIVEKIT_API_KEY = "your-livekit-api-key"
41+
# LIVEKIT_API_SECRET = "your-livekit-api-secret"
4342

4443
# External access ports
4544
LIVEKIT_EXTERNAL_PORT = "7880"

0 commit comments

Comments
 (0)