Open History to see the last commit
1/**
2 * AssemblyAI — public OpenAPI 3.1 titled "AssemblyAI API" at
3 * www.assemblyai.com/docs/openapi.json (the hinted /openapi.json 308s
4 * here). Do not fetch /docs/api-reference/openapi.json — that is Mintlify's
5 * plant-store placeholder. No classic /models list; listModels returns a
6 * small curated speech-model catalog when ASSEMBLYAI_API_KEY is set.
7 */
8import type { Activity } from '#/db/schema.ts'
9import { normalizeMediaModalities } from '../media-modalities.ts'
10import { fetchOpenApi, skippedResult } from '../types.ts'
11import type {
12 ListModelsResult,
13 ProviderConfig,
14 ProviderSecrets,
15 SpecFetchResult,
16} from '../types.ts'
17
18const ASSEMBLYAI_OPENAPI_URL = 'https://www.assemblyai.com/docs/openapi.json'
19/** Stand-in: AssemblyAI has no GET /models. */
20const ASSEMBLYAI_MODELS_URL = 'https://api.assemblyai.com/v2/transcript'
21
22/**
23 * Speech model ids from the published spec's `SpeechModel` enum. Used as
24 * the catalog because there is no list-models endpoint.
25 */
26const CURATED_SPEECH_MODELS: ReadonlyArray<{
27 rawId: string
28 displayName: string
29}> = [
30 { rawId: 'universal-3-5-pro', displayName: 'Universal 3.5 Pro' },
31 { rawId: 'universal-2', displayName: 'Universal-2' },
32]
33
34/**
35 * Generation surface only. POST /v2/transcript submits STT; websocket
36 * streaming paths classify audio if a later spec revision includes them.
37 * Upload, transcript GET/DELETE, subtitle/sentence helpers, and Lemur
38 * classify to null.
39 */
40function classify(path: string): Activity | null {
41 const bare = path.includes('#') ? path.slice(0, path.indexOf('#')) : path
42 if (bare === '/v2/transcript') return 'audio'
43 if (bare === '/v2/realtime/ws' || bare === '/v3/ws') return 'audio'
44 return null
45}
46
47async function fetchSpec(_env: ProviderSecrets): Promise<SpecFetchResult> {
48 const { spec, hash } = await fetchOpenApi(ASSEMBLYAI_OPENAPI_URL)
49 return {
50 specs: [spec],
51 sources: [{ url: ASSEMBLYAI_OPENAPI_URL, hash }],
52 outputStrategy: 'post-200',
53 }
54}
55
56async function listModels(env: ProviderSecrets): Promise<ListModelsResult> {
57 if (!env.ASSEMBLYAI_API_KEY) {
58 return { models: [], ...skippedResult('assemblyai', 'ASSEMBLYAI_API_KEY') }
59 }
60 return {
61 models: CURATED_SPEECH_MODELS.map((m) => ({
62 rawId: m.rawId,
63 displayName: m.displayName,
64 activity: 'audio' as const,
65 modalities: normalizeMediaModalities({
66 activity: 'audio',
67 listingInput: ['audio'],
68 listingOutput: ['text'],
69 }),
70 schemaEndpointId: 'v2/transcript',
71 releasedAt: null,
72 })),
73 }
74}
75
76export const provider: ProviderConfig = {
77 id: 'assemblyai',
78 displayName: 'AssemblyAI',
79 authEnvVar: 'ASSEMBLYAI_API_KEY',
80 specSourceUrl: ASSEMBLYAI_OPENAPI_URL,
81 modelsEndpoint: ASSEMBLYAI_MODELS_URL,
82 defaultDerivation: 'upstream-spec',
83 fetchSpec,
84 listModels,
85 classify,
86}