Open History to see the last commit
1/**
2 * Runway — public Stainless spec from github.com/runwayml/openapi
3 * (`next`/openapi.json; the README's openapi.yml path 404s). Generation
4 * POSTs only; task GET/cancel, org, uploads, and CRUD classify null.
5 * Runway has no /models list (`/v1/tasks` is per-id status) so listModels
6 * skips without RUNWAY_API_KEY and otherwise returns an empty catalog.
7 */
8import type { Activity } from '#/db/schema.ts'
9import { fetchOpenApi, skippedResult } from '../types.ts'
10import type {
11 ListModelsResult,
12 ProviderConfig,
13 ProviderSecrets,
14 SpecFetchResult,
15} from '../types.ts'
16
17const RUNWAY_OPENAPI_URL =
18 'https://raw.githubusercontent.com/runwayml/openapi/next/openapi.json'
19const RUNWAY_MODELS_URL = 'https://api.dev.runwayml.com/v1/tasks'
20
21const VIDEO_PATHS = new Set([
22 '/v1/image_to_video',
23 '/v1/text_to_video',
24 '/v1/video_to_video',
25 '/v1/video_upscale',
26 '/v1/character_performance',
27 '/v1/generate/video',
28 '/v1/avatar_videos',
29 '/v1/recipes/product_ad',
30 '/v1/recipes/product_swap',
31 '/v1/recipes/multi_shot_video',
32 '/v1/recipes/product_ugc',
33])
34
35const IMAGE_PATHS = new Set([
36 '/v1/text_to_image',
37 '/v1/image_upscale',
38 '/v1/generate/image',
39 '/v1/recipes/ad_localization',
40 '/v1/recipes/marketing_stock_image',
41 '/v1/recipes/product_campaign_image',
42])
43
44const AUDIO_PATHS = new Set([
45 '/v1/sound_effect',
46 '/v1/speech_to_speech',
47 '/v1/text_to_speech',
48 '/v1/voice_dubbing',
49 '/v1/voice_isolation',
50 '/v1/generate/audio',
51])
52
53/**
54 * Path-based: the shared "Start generating" tag mixes video, image, and
55 * audio. Task management, organization, uploads, avatars/voices CRUD,
56 * routers, workflows, and knowledge are platform.
57 */
58function classify(path: string): Activity | null {
59 const bare = path.split('?')[0] ?? path
60 if (VIDEO_PATHS.has(bare)) return 'video'
61 if (IMAGE_PATHS.has(bare)) return 'image'
62 if (AUDIO_PATHS.has(bare)) return 'audio'
63 return null
64}
65
66async function fetchSpec(_env: ProviderSecrets): Promise<SpecFetchResult> {
67 const { spec, hash } = await fetchOpenApi(RUNWAY_OPENAPI_URL)
68 return {
69 specs: [spec],
70 sources: [{ url: RUNWAY_OPENAPI_URL, hash }],
71 outputStrategy: 'post-200',
72 }
73}
74
75async function listModels(env: ProviderSecrets): Promise<ListModelsResult> {
76 if (!env.RUNWAY_API_KEY) {
77 return { models: [], ...skippedResult('runway', 'RUNWAY_API_KEY') }
78 }
79 return { models: [] }
80}
81
82export const provider: ProviderConfig = {
83 id: 'runway',
84 displayName: 'Runway',
85 authEnvVar: 'RUNWAY_API_KEY',
86 specSourceUrl: RUNWAY_OPENAPI_URL,
87 modelsEndpoint: RUNWAY_MODELS_URL,
88 defaultDerivation: 'upstream-spec',
89 fetchSpec,
90 listModels,
91 classify,
92}