Frontend Guide

Frontend Developer Guide

Integration guide for frontend builders. The intended product experience is a paid voice API with browser-friendly preview workflows, account usage controls, and server-safe API key handling.

Recommended Frontend Model
1

Customer signs in to your product

2

Your backend maps the customer to an API account, balance, and token quota

3

Browser calls your backend or a signed proxy endpoint

4

Your backend calls the public Voice API

5

Usage is metered and reflected back in your product UI

Key Endpoints to Integrate First

POST /voices/previewPOST /voices/preview/streamPOST /voices/analyzePOST /voices/validateGET /voices/{voice_id}
Browser vs Server Responsibility

Browser Should Handle

  • Upload selection and mic recording UX
  • Preview player UI
  • Progress and loading states
  • Usage display and remaining balance
  • Retry and validation messaging

Backend Should Handle

  • Raw API key storage
  • Customer billing state
  • Token deduction and reconciliation
  • Rate limiting per customer or workspace
  • Proxying signed requests to the voice API
Recommended Browser UX

Core Screens

ScreenPurpose
Voice listShow available voice IDs and labels
Text preview composerEnter text for preview or stream
Live playerPlay streamed preview audio
Usage panelShow token estimate, cost, and remaining balance
History panelShow prior previews and validation results
Billing stateShow insufficient-balance and upgrade state

Recommended Flow

1

User selects voice

2

User enters preview text

3

Frontend asks backend for a token estimate

4

Frontend shows estimated token cost before generation

5

User confirms preview request

6

Backend forwards to Voice API

7

Frontend plays stream or receives preview payload

8

Frontend updates usage UI from backend-confirmed balance state

Browser Integration Patterns
Pattern A

JSON Preview

Use when you need waveform analysis, metadata display, easier persistence, or simpler debugging.

async function requestPreview( baseUrl: string, apiKey: string, voiceId: string, text: string ) { const response = await fetch(`${baseUrl}/voices/preview`, { method: "POST", headers: { "Content-Type": "application/json", "X-API-Key": apiKey, }, body: JSON.stringify({ voice_id: voiceId, text, include_audio_base64: true, persist_preview: true, }), }); if (!response.ok) { throw new Error(await response.text()); } return response.json(); }
Pattern B

Realtime Stream

Use when you need immediate playback, lower-latency preview UX, or simpler audio-only delivery.

async function streamPreview( baseUrl: string, apiKey: string, voiceId: string, text: string ) { const response = await fetch(`${baseUrl}/voices/preview/stream`, { method: "POST", headers: { "Content-Type": "application/json", "X-API-Key": apiKey, }, body: JSON.stringify({ voice_id: voiceId, text, }), }); if (!response.ok || !response.body) { throw new Error(await response.text()); } return response.body; }
Product States

Your frontend should explicitly handle these states:

StateMeaning
idleNo request in flight
estimatingWaiting for token estimate
streamingReceiving realtime audio
completedRequest finished successfully
insufficient-balanceAccount cannot generate
invalid-inputRequest text or voice config invalid
rate-limitedAccount exceeded allowed burst or throughput
service-unavailableBackend or voice runtime unavailable
Best Practices

Do

  • Show estimated token usage before confirming generation
  • Show actual consumed usage after completion
  • Surface rate-limit and insufficient-balance states clearly
  • Separate preview usage from production usage
  • Keep replay and history actions visible

Avoid

  • Embedding permanent API keys in browser bundles
  • Charging based only on client-side estimates
  • Assuming all preview routes return JSON
  • Treating internal admin routes as public APIs
  • Storing balance truth only in frontend state