7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(media): serve transcription usage at /api/media/usage + show it on the STT tab (#991)
tashdroidb6955f676f4c
diff --git a/client/src/components/media-models.tsx b/client/src/components/media-models.tsxindex ef30b64c..4d992bd6 100644--- a/client/src/components/media-models.tsx+++ b/client/src/components/media-models.tsx@@ -25,7 +25,7 @@ export interface MediaModel {interface MediaData { models: MediaModel[] }interface MediaUsage {- modality: 'image' | 'audio'+ modality: 'image' | 'audio' | 'transcription'models: {id: numberplatform: string@@ -152,6 +152,15 @@ export function MediaModelsView({ modality }: { modality: 'image' | 'audio' }) {refetchInterval: 30_000,})+ // The Audio tab carries both directions of the modality, so the STT section+ // gets its own usage summary (the endpoint accepts modality=transcription).+ const { data: sttUsage } = useQuery<MediaUsage>({+ queryKey: ['media', 'usage', 'transcription'],+ queryFn: () => apiFetch('/api/media/usage?modality=transcription'),+ enabled: modality === 'audio',+ refetchInterval: 30_000,+ })+const toggle = useMutation({mutationFn: ({ id, enabled }: { id: number; enabled: boolean }) =>apiFetch(`/api/media/${id}`, { method: 'PUT', body: JSON.stringify({ enabled }) }),@@ -232,6 +241,21 @@ export function MediaModelsView({ modality }: { modality: 'image' | 'audio' }) {{t('models.sttHint')} <code className="rounded bg-muted px-1 py-0.5 font-mono text-[11px]">/v1/audio/transcriptions</code></p>+ {sttUsage && sttUsage.models.length > 0 && (+ <UsageSummaryCard+ rows={sttUsage.models.map(m => ({+ label: m.displayName,+ platform: m.platform,+ quotaLabel: [m.platform, m.quotaLabel].filter(Boolean).join(' · '),+ amount: m.requestsMonth,+ requestsToday: m.requestsToday,+ }))}+ total={sttUsage.totalRequestsMonth}+ requestsToday={sttUsage.totalRequestsToday}+ unit="requests"+ />+ )}+{isLoading ? (<CardSkeleton />) : sttGroups.length === 0 ? (diff --git a/server/src/__tests__/routes/media-usage.test.ts b/server/src/__tests__/routes/media-usage.test.tsindex 2f7fcefe..769d3693 100644--- a/server/src/__tests__/routes/media-usage.test.ts+++ b/server/src/__tests__/routes/media-usage.test.ts@@ -34,6 +34,10 @@ function seedModels() {insert.run('groq', 'playai-tts', 'PlayAI TTS', 'audio', 1, 1, 'WAV/PCM - 30+ voices');// Disabled rows stay out of the summary entirely.insert.run('cloudflare', 'melotts', 'MeloTTS', 'audio', 2, 0, 'Shared 10k neurons/day');+ // STT models live in the same table with modality='transcription'; the+ // Audio tab lists them under the TTS section, so the usage summary has to+ // accept the modality too (it used to 400).+ insert.run('groq', 'whisper-large-v3', 'Whisper Large v3', 'transcription', 1, 1, 'MP3 output - multilingual');}function seedRequest(platform: string, modelId: string, type: string, when: string) {@@ -102,6 +106,27 @@ describe('GET /api/media/usage', () => {expect(flux.requestsMonth).toBe(0);});+ it('reports transcription usage from the same tagged request log', async () => {+ seedRequest('groq', 'whisper-large-v3', 'transcription', "datetime('now')");+ seedRequest('groq', 'whisper-large-v3', 'transcription', "datetime('now', 'start of month')");+ // Same provider AND model id, but TTS traffic: the join must exclude it by+ // request_type, not just by platform + model_id.+ seedRequest('groq', 'whisper-large-v3', 'audio', "datetime('now')");++ const { status, body } = await get(app, '/api/media/usage?modality=transcription');+ expect(status).toBe(200);+ expect(body.modality).toBe('transcription');+ expect(body.models.map((m: any) => m.modelId)).toEqual(['whisper-large-v3']);++ const whisper = body.models[0];+ // Exactly the two transcription requests — the audio one is filtered out+ // by request_type even though it shares platform and model id.+ expect(whisper.requestsMonth).toBe(2);+ expect(whisper.requestsToday).toBeGreaterThanOrEqual(1);+ expect(whisper.quotaLabel).toBe('MP3 output - multilingual');+ expect(body.totalRequestsMonth).toBe(2);+ });+it('reports no budget field — media quota labels are not token budgets', async () => {const { body } = await get(app, '/api/media/usage?modality=audio');for (const m of body.models) {diff --git a/server/src/routes/media.ts b/server/src/routes/media.tsindex 4101e116..a04a378c 100644--- a/server/src/routes/media.ts+++ b/server/src/routes/media.ts@@ -48,11 +48,14 @@ mediaRouter.get('/', (_req: Request, res: Response) => {// token counts are reported. As with embeddings there is no budget// denominator — `media_models` only carries a free-text `quota_label`// ("Shared 10k neurons/day", "MP3 output - multilingual", which is not even a-// quota) — so the summary shows spend and the label verbatim.+// quota) — so the summary shows spend and the label verbatim. Transcription+// rows are logged the same way (request_type='transcription', see+// logMedia), so the Audio tab's STT section can show the same per-model+// counts instead of dead-ending on a 400.mediaRouter.get('/usage', (req: Request, res: Response) => {- const parsed = z.enum(['image', 'audio']).safeParse(req.query.modality);+ const parsed = z.enum(['image', 'audio', 'transcription']).safeParse(req.query.modality);if (!parsed.success) {- res.status(400).json({ error: { message: 'modality must be image or audio' } });+ res.status(400).json({ error: { message: 'modality must be image, audio or transcription' } });return;}const modality = parsed.data;