### Initialize and Start Project Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Commands to initialize submodules, install dependencies, and start the backend and frontend servers. ```bash # Initialize (clone submodules + install deps) make init # Set up environment test -f .env || cp sample.env .env # then set DEEPGRAM_API_KEY # Start both servers make start # Backend: http://localhost:8081 # Frontend: http://localhost:8080 ``` -------------------------------- ### Install Dependencies Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Commands to install backend and frontend dependencies. ```bash cargo build Frontend: cd frontend && corepack pnpm install ``` -------------------------------- ### Initialize and Start Rust Flux App Source: https://github.com/deepgram-starters/rust-flux/blob/main/README.md Use this Makefile command to initialize the project, set up environment variables by copying the sample, and start the local development server. ```bash make init cp sample.env .env # Add your DEEPGRAM_API_KEY make start ``` -------------------------------- ### Start and Stop Commands Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Commands for managing the lifecycle of the backend and frontend processes. ```bash make start ``` ```bash # Terminal 1 — Backend cargo run # Terminal 2 — Frontend cd frontend && corepack pnpm run dev -- --port 8080 --no-open ``` ```bash lsof -ti:8080,8081 | xargs kill -9 2>/dev/null ``` ```bash rm -rf target frontend/node_modules frontend/.vite make init ``` -------------------------------- ### Project Initialization and Commands (Bash) Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Lists `make` commands for managing the project, including checking prerequisites, initializing, starting servers, updating submodules, running tests, and cleaning build artifacts. ```bash # Check prerequisites (git, cargo) make check-prereqs # Initialize project: clone submodules and install dependencies make init # Set up environment cp sample.env .env # Edit .env and add your DEEPGRAM_API_KEY # Start both backend and frontend servers make start # Backend: http://localhost:8081 # Frontend: http://localhost:8080 # Start servers separately make start-backend # Rust backend on port 8081 make start-frontend # Vite frontend on port 8080 # Update submodules to latest commits make update # Run contract conformance tests (requires running app) make test # Clean build artifacts make clean # Show git and submodule status make status ``` -------------------------------- ### Conventional Commits Examples Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Examples of commit messages following the conventional commits format. ```git feat(rust-flux): add diarization support ``` ```git fix(rust-flux): resolve WebSocket close handling ``` ```git refactor(rust-flux): simplify session endpoint ``` ```git chore(deps): update frontend submodule ``` -------------------------------- ### Environment Configuration (Bash) Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Provides an example `.env` file for configuring the backend server, including Deepgram API key, port, host, and JWT signing secret. ```bash # sample.env - Copy to .env and configure # Required: Your Deepgram API key DEEPGRAM_API_KEY=your_api_key_here # Optional: Backend server port (default: 8081) PORT=8081 # Optional: Server bind address (default: 0.0.0.0) HOST=0.0.0.0 # Optional: JWT signing secret (auto-generated if not set) # Set in production for consistent token validation across restarts SESSION_SECRET=your_secret_key_here ``` -------------------------------- ### Add Keyterms via Query Parameters Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Example of passing keyterms as repeated query parameters to the WebSocket connection. ```text ?keyterm=Deepgram&keyterm=Nova&keyterm=Aura ``` -------------------------------- ### GET /api/metadata Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Returns application metadata including use case, framework, and language. ```APIDOC ## GET /api/metadata ### Description Returns the application metadata, including the use case, framework, and programming language. ### Method GET ### Endpoint /api/metadata ### Response #### Success Response (200) - **useCase** (string) - The application use case - **framework** (string) - The backend framework - **language** (string) - The programming language ``` -------------------------------- ### GET /api/session Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Retrieves a JWT session token for authenticating WebSocket connections. ```APIDOC ## GET /api/session ### Description Issues a JWT session token required for authenticating WebSocket connections to the flux endpoint. ### Method GET ### Endpoint /api/session ### Response #### Success Response (200) - **token** (string) - The JWT session token. ``` -------------------------------- ### Retrieve Project Metadata Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Fetch configuration details and project tags from the backend. ```bash # Get project metadata curl -s http://localhost:8081/api/metadata | jq # Response: { "title": "Rust Flux", "description": "Get started using Deepgram's Flux API for real-time transcription with turn detection using this Rust demo app", "author": "Deepgram DX Team (https://developers.deepgram.com)", "repository": "https://github.com/deepgram-starters/rust-flux", "useCase": "flux", "language": "rust", "framework": "axum", "sdk": "N/A", "tags": ["flux", "turn-detection", "real-time-transcription", "streaming-stt", "end-of-turn", "rust", "axum"] } ``` -------------------------------- ### Run Tests and Manual Endpoint Checks Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Commands to run conformance tests and manually check API endpoints. ```bash # Run conformance tests (requires app to be running) make test ``` ```bash # Manual endpoint check curl -sf http://localhost:8081/api/metadata | python3 -m json.tool ``` ```bash curl -sf http://localhost:8081/api/session | python3 -m json.tool ``` -------------------------------- ### Commit Frontend Changes Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Steps to commit and push changes made to the frontend submodule. ```bash cd frontend && git add . && git commit -m "feat: description" ``` ```bash cd frontend && git push origin main ``` ```bash cd .. && git add frontend && git commit -m "chore(deps): update frontend submodule" ``` -------------------------------- ### Generate and Use Session Tokens Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Request a JWT for WebSocket authentication and establish a connection using the access_token subprotocol. ```bash # Request a session token curl -s http://localhost:8081/api/session | jq # Response: { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2OTk5OTk5OTksImV4cCI6MTcwMDAwMzU5OX0.signature" } # Use the token for WebSocket authentication via subprotocol # In JavaScript: const response = await fetch('/api/session'); const { token } = await response.json(); const ws = new WebSocket('/api/flux', [`access_token.${token}`]); ``` -------------------------------- ### Flux Query Parameters Reference (Bash) Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Illustrates the available URL query parameters for configuring Deepgram Flux's end-of-turn detection and vocabulary. ```bash # WebSocket URL with all available Flux parameters ws://localhost:8081/api/flux?encoding=linear16&sample_rate=16000&eot_threshold=0.7&eager_eot_threshold=0.5&eot_timeout_ms=5000&keyterm=Deepgram&keyterm=Nova # Parameter reference: # - encoding: Audio encoding format (linear16, opus) - default: linear16 # - sample_rate: Audio sample rate in Hz (8000-48000) - default: 16000 # - eot_threshold: End-of-turn confidence threshold (0.0-1.0) - default: 0.7 # Lower values = faster turn endings, may cut off mid-sentence # Higher values = waits longer, better for longer utterances # - eager_eot_threshold: Tentative EOT threshold (0.0-1.0) - optional # Shows tentative completions that can resume if user keeps talking # - eot_timeout_ms: Silence duration before automatic EOT (0-30000) - default: 5000 # - keyterm: Custom vocabulary hints (repeatable parameter) ``` -------------------------------- ### Check Server Health Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Verify the operational status of the backend service. ```bash # Check server health curl -s http://localhost:8081/health | jq # Response: { "status": "ok" } ``` -------------------------------- ### WS /api/flux Source: https://github.com/deepgram-starters/rust-flux/blob/main/AGENTS.md Establishes a WebSocket connection for real-time transcription with turn-based detection. ```APIDOC ## WS /api/flux ### Description Advanced real-time transcription endpoint using WebSockets with support for turn-based detection. Requires a JWT token provided via the `access_token.` subprotocol. ### Method WS ### Endpoint /api/flux ### Parameters #### Query Parameters - **model** (string) - Optional - Flux STT model (default: flux-general-en) - **encoding** (string) - Optional - Audio encoding (linear16, opus) - **sample_rate** (integer) - Optional - Audio sample rate (8000-48000) - **eot_threshold** (float) - Optional - Confidence for end-of-turn detection (0.0-1.0) - **eager_eot_threshold** (float) - Optional - Threshold for tentative end-of-turn (0.0-1.0) - **eot_timeout_ms** (integer) - Optional - Silence duration in ms before automatic EOT (0-30000) - **keyterm** (string) - Optional - Custom vocabulary hints (repeated parameter) ``` -------------------------------- ### Rust Dependencies for Axum WebSocket Server Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Core dependencies for an Axum-based WebSocket proxy server with JWT authentication. Ensure these are added to your Cargo.toml file. ```toml [package] name = "rust-flux" version = "0.1.0" edition = "2021" [dependencies] axum = { version = "0.8", features = ["ws"] } # Web framework with WebSocket support dotenvy = "0.15" # Environment variable loading futures-util = "0.3" # Async stream utilities hex = "0.4" # Hex encoding for session secrets jsonwebtoken = "9" # JWT generation and validation rand = "0.9" # Random number generation serde = { version = "1", features = ["derive"] } # Serialization serde_json = "1" # JSON handling serde_urlencoded = "0.7" # URL query parameter parsing tokio = { version = "1", features = ["full"] } # Async runtime tokio-tungstenite = { version = "0.26", features = ["native-tls"] } # WebSocket client toml = "0.8" # TOML config parsing tower-http = { version = "0.6", features = ["cors"] } # CORS middleware url = "2" # URL manipulation ``` -------------------------------- ### Connect to Deepgram Flux API with Parameters (JavaScript) Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Establishes a WebSocket connection to Deepgram's Flux API, including custom parameters for end-of-turn detection and vocabulary boosting. Requires a session token obtained via a separate API call. ```javascript // Client-side WebSocket connection with Flux parameters async function connectToFlux() { // Get session token first const response = await fetch('/api/session'); const { token } = await response.json(); // Build WebSocket URL with Flux parameters const params = new URLSearchParams({ encoding: 'linear16', sample_rate: '16000', eot_threshold: '0.7', // End-of-turn confidence (0.0-1.0) eager_eot_threshold: '0.5', // Tentative EOT threshold eot_timeout_ms: '5000' // Silence timeout in ms }); // Add multiple keyterms for vocabulary boosting params.append('keyterm', 'Deepgram'); params.append('keyterm', 'Flux'); params.append('keyterm', 'transcription'); // Connect with JWT in subprotocol const ws = new WebSocket( `ws://localhost:8081/api/flux?${params}`, [`access_token.${token}`] ); ws.onopen = () => console.log('Connected to Flux'); ws.onmessage = (event) => { const data = JSON.parse(event.data); // Handle turn-based events switch (data.type) { case 'StartOfTurn': console.log('User started speaking'); break; case 'Update': console.log('Interim:', data.channel.alternatives[0].transcript); break; case 'EagerEndOfTurn': console.log('Tentative end detected'); break; case 'TurnResumed': console.log('User continued speaking'); break; case 'EndOfTurn': console.log('Final:', data.channel.alternatives[0].transcript); break; } }; ws.onerror = (error) => console.error('WebSocket error:', error); ws.onclose = (event) => console.log('Disconnected:', event.reason); return ws; } // Stream audio to the WebSocket async function streamAudio(ws) { const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); const mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/webm' }); mediaRecorder.ondataavailable = (event) => { if (event.data.size > 0 && ws.readyState === WebSocket.OPEN) { ws.send(event.data); } }; mediaRecorder.start(100); // Send chunks every 100ms return mediaRecorder; } ``` -------------------------------- ### Project Metadata API Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Returns project metadata from the `deepgram.toml` configuration file. ```APIDOC ## GET /api/metadata ### Description Retrieves metadata about the project, including its title, description, author, repository, use case, language, framework, and tags. ### Method GET ### Endpoint /api/metadata ### Parameters None ### Request Body None ### Request Example ```bash curl -s http://localhost:8081/api/metadata | jq ``` ### Response #### Success Response (200) - **title** (string) - The title of the project. - **description** (string) - A brief description of the project. - **author** (string) - The author or team responsible for the project. - **repository** (string) - The URL of the project's source code repository. - **useCase** (string) - The primary use case of the project. - **language** (string) - The programming language used for the project. - **framework** (string) - The web framework used for the project. - **sdk** (string) - The SDK used, if any. - **tags** (array of strings) - Tags associated with the project. #### Response Example ```json { "title": "Rust Flux", "description": "Get started using Deepgram's Flux API for real-time transcription with turn detection using this Rust demo app", "author": "Deepgram DX Team (https://developers.deepgram.com)", "repository": "https://github.com/deepgram-starters/rust-flux", "useCase": "flux", "language": "rust", "framework": "axum", "sdk": "N/A", "tags": ["flux", "turn-detection", "real-time-transcription", "streaming-stt", "end-of-turn", "rust", "axum"] } ``` ``` -------------------------------- ### Eject Frontend Submodule Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Command to eject the frontend submodule for standalone development. ```bash make eject-frontend ``` -------------------------------- ### Session Token Generation API Source: https://context7.com/deepgram-starters/rust-flux/llms.txt Issues a signed JWT for client authentication. Tokens expire after 1 hour and are used to authenticate WebSocket connections to the Flux endpoint. ```APIDOC ## POST /api/session ### Description Generates a short-lived JWT token for authenticating WebSocket connections. ### Method POST ### Endpoint /api/session ### Parameters None ### Request Body None ### Request Example ```bash curl -s http://localhost:8081/api/session | jq ``` ### Response #### Success Response (200) - **token** (string) - The generated JWT token. #### Response Example ```json { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2OTk5OTk5OTksImV4cCI6MTcwMDAwMzU5OX0.signature" } ``` ``` -------------------------------- ### Health Check API Source: https://context7.com/deepgram-starters/rust-flux/llms.txt A simple health check endpoint that returns the server status. Useful for load balancers and container orchestration health probes. ```APIDOC ## GET /health ### Description Checks the health status of the server. ### Method GET ### Endpoint /health ### Parameters None ### Request Body None ### Request Example ```bash curl -s http://localhost:8081/health | jq ``` ### Response #### Success Response (200) - **status** (string) - The health status of the server, typically "ok". #### Response Example ```json { "status": "ok" } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.