1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
"""Central model registry.
 
All backend model metadata is registered in this file, including provider,
model type, concurrency, pricing, and API capability tags.
"""
 
import os
import sys
 
models_dir = os.path.dirname(os.path.abspath(__file__))
backend_dir = os.path.dirname(models_dir)
if backend_dir not in sys.path:
    sys.path.insert(0, backend_dir)
 
from copy import deepcopy
from typing import Any, Optional
 
MODEL_CONFIG: dict[str, Any] = {'models': {'deepseek-chat': {'name': 'DeepSeek Chat',
                              'provider': 'deepseek',
                              'type': ['llm'],
                              'concurrency': 10,
                              'price_per_1k_input_token': 0.002,
                              'price_per_1k_output_token': 0.008},
            'deepseek-reasoner': {'name': 'DeepSeek Reasoner',
                                  'provider': 'deepseek',
                                  'type': ['llm'],
                                  'concurrency': 10,
                                  'price_per_1k_input_token': 0.004,
                                  'price_per_1k_output_token': 0.016},
            'deepseek-v4-flash': {'name': 'DeepSeek V4 Flash',
                                  'provider': 'deepseek',
                                  'type': ['llm'],
                                  'concurrency': 10,
                                  'price_per_1k_input_token': 0.001,
                                  'price_per_1k_output_token': 0.004},
            'deepseek-v4-pro': {'name': 'DeepSeek V4 Pro',
                                'provider': 'deepseek',
                                'type': ['llm'],
                                'concurrency': 10,
                                'price_per_1k_input_token': 0.002,
                                'price_per_1k_output_token': 0.008},
            'gpt-4o': {'name': 'GPT-4o',
                       'provider': 'openai',
                       'type': ['llm'],
                       'concurrency': 10,
                       'price_per_1k_input_token': 0.018,
                       'price_per_1k_output_token': 0.072},
            'gpt-5': {'name': 'GPT-5',
                      'provider': 'openai',
                      'type': ['llm'],
                      'concurrency': 10,
                      'price_per_1k_input_token': 0.02,
                      'price_per_1k_output_token': 0.1},
            'gpt-5.4': {'name': 'GPT-5.4',
                        'provider': 'openai',
                        'type': ['llm', 'vlm'],
                        'concurrency': 10,
                        'price_per_1k_input_token': 0.03,
                        'price_per_1k_output_token': 0.12},
            'qwen3.6-max-preview': {'name': 'Qwen 3.6 Max Preview',
                                    'provider': 'qwen',
                                    'type': ['llm'],
                                    'concurrency': 10,
                                    'price_per_1k_input_token': 0.006,
                                    'price_per_1k_output_token': 0.024},
            'qwen3-max': {'name': 'Qwen 3 Max',
                          'provider': 'qwen',
                          'type': ['llm'],
                          'concurrency': 10,
                          'price_per_1k_input_token': 0.006,
                          'price_per_1k_output_token': 0.024},
            'deepseek-v3.2': {'name': 'DeepSeek V3.2 (DashScope)',
                              'provider': 'qwen',
                              'type': ['llm'],
                              'concurrency': 10,
                              'price_per_1k_input_token': 0.002,
                              'price_per_1k_output_token': 0.008},
            'qwen3.6-plus': {'name': 'Qwen 3.6 Plus',
                             'provider': 'qwen',
                             'type': ['vlm'],
                             'concurrency': 10,
                             'price_per_1k_input_token': 0.0008,
                             'price_per_1k_output_token': 0.002},
            'qwen3.6-flash': {'name': 'Qwen 3.6 Flash',
                              'provider': 'qwen',
                              'type': ['vlm'],
                              'concurrency': 10,
                              'price_per_1k_input_token': 0.0001,
                              'price_per_1k_output_token': 0.0001},
            'kimi-k2.6': {'name': 'Kimi K2.6',
                          'provider': 'qwen',
                          'type': ['llm', 'vlm'],
                          'concurrency': 10,
                          'price_per_1k_input_token': 0.001,
                          'price_per_1k_output_token': 0.003},
            'gemini-2.5-flash': {'name': 'Gemini 2.5 Flash',
                                 'provider': 'gemini',
                                 'type': ['llm'],
                                 'concurrency': 10,
                                 'price_per_1k_input_token': 0.002,
                                 'price_per_1k_output_token': 0.01},
            'gemini-2.0-flash': {'name': 'Gemini 2.0 Flash',
                                 'provider': 'gemini',
                                 'type': ['llm', 'vlm'],
                                 'concurrency': 10,
                                 'price_per_1k_input_token': 0.002,
                                 'price_per_1k_output_token': 0.01},
            'gemini-2.5-flash-image': {'name': 'Gemini 2.5 Flash Image',
                                       'provider': 'gemini',
                                       'type': ['vlm'],
                                       'concurrency': 10,
                                       'price_per_1k_input_token': 0.002,
                                       'price_per_1k_output_token': 0.01},
            'wan2.7-image': {'name': 'Wan 2.7 Image',
                             'provider': 'dashscope',
                             'type': ['t2i', 'i2i'],
                             'concurrency': 5,
                             'price_per_image': 0.2,
                             'capabilities': {'ability_type': 'image_generation',
                                              'ability_types': ['text_to_image', 'image_to_image', 'reference_image'],
                                              'adapter_ability_types': ['text_to_image',
                                                                        'image_to_image',
                                                                        'reference_image'],
                                              'input_modalities': ['text', 'image'],
                                              'adapter_input_modalities': ['text', 'image'],
                                              'api_contract_verified': True,
                                              'resolutions': ['720P', '1080P', '2K', '4K'],
                                              'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4']}},
            'wan2.7-image-pro': {'name': 'Wan 2.7 Image Pro',
                                 'provider': 'dashscope',
                                 'type': ['t2i', 'i2i'],
                                 'concurrency': 5,
                                 'price_per_image': 0.4,
                                 'capabilities': {'ability_type': 'image_generation',
                                                  'ability_types': ['text_to_image',
                                                                    'image_to_image',
                                                                    'reference_image',
                                                                    'high_quality'],
                                                  'adapter_ability_types': ['text_to_image',
                                                                            'image_to_image',
                                                                            'reference_image'],
                                                  'input_modalities': ['text', 'image'],
                                                  'adapter_input_modalities': ['text', 'image'],
                                                  'api_contract_verified': True,
                                                  'resolutions': ['720P', '1080P', '2K', '4K'],
                                                  'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4']}},
            'wan2.6-t2i': {'name': 'Wan 2.6 T2I',
                           'provider': 'dashscope',
                           'type': ['t2i'],
                           'concurrency': 5,
                           'price_per_image': 0.2,
                           'capabilities': {'ability_type': 'image_generation',
                                            'ability_types': ['text_to_image'],
                                            'adapter_ability_types': ['text_to_image'],
                                            'input_modalities': ['text'],
                                            'adapter_input_modalities': ['text'],
                                            'api_contract_verified': True,
                                            'resolutions': ['720P', '1080P', '2K', '4K'],
                                            'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4']}},
            'doubao-seedream-5-0-260128': {'name': 'Seedream 5.0',
                                           'provider': 'seedream',
                                           'type': ['t2i', 'i2i'],
                                           'concurrency': 10,
                                           'price_per_image': 0.22,
                                           'capabilities': {'ability_type': 'image_generation',
                                                            'ability_types': ['text_to_image',
                                                                              'image_to_image',
                                                                              'reference_image',
                                                                              'high_quality'],
                                                            'adapter_ability_types': ['text_to_image',
                                                                                      'image_to_image',
                                                                                      'reference_image'],
                                                            'input_modalities': ['text', 'image'],
                                                            'adapter_input_modalities': ['text', 'image'],
                                                            'api_contract_verified': True,
                                                            'resolutions': ['720P', '1080P', '2K', '4K'],
                                                            'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4']}},
            'doubao-seedream-4-5-251128': {'name': 'Seedream 4.5',
                                           'provider': 'seedream',
                                           'type': ['t2i', 'i2i'],
                                           'concurrency': 10,
                                           'price_per_image': 0.25,
                                           'capabilities': {'ability_type': 'image_generation',
                                                            'ability_types': ['text_to_image',
                                                                              'image_to_image',
                                                                              'reference_image'],
                                                            'adapter_ability_types': ['text_to_image',
                                                                                      'image_to_image',
                                                                                      'reference_image'],
                                                            'input_modalities': ['text', 'image'],
                                                            'adapter_input_modalities': ['text', 'image'],
                                                            'api_contract_verified': True,
                                                            'resolutions': ['720P', '1080P', '2K', '4K'],
                                                            'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4']}},
            'doubao-seedream-4-0-250828': {'name': 'Seedream 4.0',
                                           'provider': 'seedream',
                                           'type': ['t2i', 'i2i'],
                                           'concurrency': 10,
                                           'price_per_image': 0.2,
                                           'capabilities': {'ability_type': 'image_generation',
                                                            'ability_types': ['text_to_image',
                                                                              'image_to_image',
                                                                              'reference_image'],
                                                            'adapter_ability_types': ['text_to_image',
                                                                                      'image_to_image',
                                                                                      'reference_image'],
                                                            'input_modalities': ['text', 'image'],
                                                            'adapter_input_modalities': ['text', 'image'],
                                                            'api_contract_verified': True,
                                                            'resolutions': ['720P', '1080P', '2K', '4K'],
                                                            'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4']}},
            'sora_image': {'name': 'Sora Image',
                           'provider': 'openai',
                           'type': ['t2i'],
                           'concurrency': 3,
                           'price_per_image': 1.45,
                           'capabilities': {'ability_type': 'image_generation',
                                            'ability_types': ['text_to_image'],
                                            'adapter_ability_types': ['text_to_image'],
                                            'input_modalities': ['text'],
                                            'adapter_input_modalities': ['text'],
                                            'api_contract_verified': True}},
            'gpt-image-2': {'name': 'GPT Image 2',
                            'provider': 'openai',
                            'type': ['t2i', 'i2i'],
                            'concurrency': 3,
                            'price_per_image': 1.09,
                            'capabilities': {'ability_type': 'image_generation',
                                             'ability_types': ['text_to_image', 'image_to_image', 'reference_image'],
                                             'adapter_ability_types': ['text_to_image',
                                                                       'image_to_image',
                                                                       'reference_image'],
                                             'input_modalities': ['text', 'image'],
                                             'adapter_input_modalities': ['text', 'image'],
                                             'api_contract_verified': True}},
            'wan2.6-i2v-flash': {'name': 'Wan 2.6 I2V Flash',
                                 'provider': 'dashscope',
                                 'type': ['video'],
                                 'concurrency': 5,
                                 'price_per_second': 0.6,
                                 'capabilities': {'ability_type': 'image_to_video',
                                                  'ability_types': ['first_frame_i2v',
                                                                    'audio_driven_i2v',
                                                                    'multi_shot',
                                                                    'fast_generation'],
                                                  'adapter_ability_types': ['first_frame_i2v'],
                                                  'input_modalities': ['text', 'image', 'audio'],
                                                  'adapter_input_modalities': ['text', 'image'],
                                                  'duration': {'min': 2, 'max': 15, 'integer': True, 'verified': True},
                                                  'resolutions': ['720P', '1080P'],
                                                  'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4'],
                                                  'api_contract_verified': True}},
            'wan2.7-i2v': {'name': 'Wan 2.7 I2V',
                           'provider': 'dashscope',
                           'type': ['video'],
                           'concurrency': 5,
                           'price_per_second': 0.8,
                           'capabilities': {'ability_type': 'image_to_video',
                                            'ability_types': ['first_frame_i2v',
                                                              'start_end_frame_i2v',
                                                              'video_continuation',
                                                              'audio_driven_i2v',
                                                              'multi_shot'],
                                            'adapter_ability_types': ['first_frame_i2v', 'audio_driven_i2v'],
                                            'input_modalities': ['text', 'image', 'audio', 'video'],
                                            'adapter_input_modalities': ['text', 'image'],
                                            'duration': {'min': 2, 'max': 15, 'integer': True, 'verified': True},
                                            'resolutions': ['720P', '1080P'],
                                            'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4'],
                                            'api_contract_verified': True}},
            'happyhorse-1.0-i2v': {'name': 'Happy Horse 1.0 I2V',
                                   'provider': 'dashscope',
                                   'type': ['video'],
                                   'concurrency': 5,
                                   'price_per_second': 1.0,
                                   'capabilities': {'ability_type': 'image_to_video',
                                                    'ability_types': ['first_frame_i2v', 'native_audio'],
                                                    'adapter_ability_types': ['first_frame_i2v', 'native_audio'],
                                                    'input_modalities': ['text', 'image'],
                                                    'adapter_input_modalities': ['text', 'image'],
                                                    'duration': {'min': 3,
                                                                 'max': 15,
                                                                 'integer': True,
                                                                 'verified': True},
                                                    'resolutions': ['720P', '1080P'],
                                                    'api_contract_verified': True}},
            'kling-v3': {'name': 'Kling V3',
                         'provider': 'kling',
                         'type': ['video'],
                         'concurrency': 10,
                         'price_per_second': 1.0,
                         'capabilities': {'ability_type': 'image_to_video',
                                          'ability_types': ['text_to_video',
                                                            'image_to_video',
                                                            'start_end_frame_i2v',
                                                            'native_audio',
                                                            'multi_shot',
                                                            'element_reference'],
                                          'adapter_ability_types': ['first_frame_i2v', 'native_audio'],
                                          'input_modalities': ['text', 'image'],
                                          'adapter_input_modalities': ['text', 'image'],
                                          'duration': {'min': 3, 'max': 15, 'integer': True, 'verified': True},
                                          'resolutions': ['720P', '1080P'],
                                          'api_contract_verified': False}},
            'kling-v2-6': {'name': 'Kling V2.6',
                           'provider': 'kling',
                           'type': ['video'],
                           'concurrency': 10,
                           'price_per_second': 0.5,
                           'capabilities': {'ability_type': 'image_to_video',
                                            'ability_types': ['text_to_video',
                                                              'image_to_video',
                                                              'start_end_frame_i2v',
                                                              'native_audio'],
                                            'adapter_ability_types': ['first_frame_i2v', 'native_audio'],
                                            'input_modalities': ['text', 'image'],
                                            'adapter_input_modalities': ['text', 'image'],
                                            'api_contract_verified': False}},
            'kling-v2-5-turbo': {'name': 'Kling V2.5 Turbo',
                                 'provider': 'kling',
                                 'type': ['video'],
                                 'concurrency': 10,
                                 'price_per_second': 0.3,
                                 'capabilities': {'ability_type': 'image_to_video',
                                                  'ability_types': ['image_to_video'],
                                                  'adapter_ability_types': ['first_frame_i2v', 'native_audio'],
                                                  'input_modalities': ['text', 'image'],
                                                  'adapter_input_modalities': ['text', 'image'],
                                                  'api_contract_verified': False}},
            'doubao-seedance-2-0-260128': {'name': 'Seedance 2.0',
                                           'provider': 'seedance',
                                           'type': ['video'],
                                           'concurrency': 10,
                                           'price_per_second': 0.5,
                                           'capabilities': {'ability_type': 'image_to_video',
                                                            'ability_types': ['text_to_video', 'image_to_video'],
                                                            'adapter_ability_types': ['first_frame_i2v',
                                                                                      'native_audio'],
                                                            'input_modalities': ['text', 'image'],
                                                            'adapter_input_modalities': ['text', 'image'],
                                                            'duration': {'min': 2,
                                                                         'max': 12,
                                                                         'integer': True,
                                                                         'verified': True},
                                                            'resolutions': ['720p', '1080p'],
                                                            'ratios': ['16:9',
                                                                       '4:3',
                                                                       '1:1',
                                                                       '3:4',
                                                                       '9:16',
                                                                       '21:9',
                                                                       'adaptive'],
                                                            'api_contract_verified': True}},
            'doubao-seedance-2-0-fast-260128': {'name': 'Seedance 2.0 Fast',
                                                'provider': 'seedance',
                                                'type': ['video'],
                                                'concurrency': 10,
                                                'price_per_second': 0.3,
                                                'capabilities': {'ability_type': 'image_to_video',
                                                                 'ability_types': ['text_to_video',
                                                                                   'image_to_video',
                                                                                   'fast_generation'],
                                                                 'adapter_ability_types': ['first_frame_i2v',
                                                                                           'native_audio'],
                                                                 'input_modalities': ['text', 'image'],
                                                                 'adapter_input_modalities': ['text', 'image'],
                                                                 'duration': {'min': 2,
                                                                              'max': 12,
                                                                              'integer': True,
                                                                              'verified': True},
                                                                 'resolutions': ['720p', '1080p'],
                                                                 'ratios': ['16:9',
                                                                            '4:3',
                                                                            '1:1',
                                                                            '3:4',
                                                                            '9:16',
                                                                            '21:9',
                                                                            'adaptive'],
                                                                 'api_contract_verified': True}},
            'wan2.7-r2v': {'name': 'Wan 2.7 R2V',
                           'provider': 'dashscope',
                           'type': ['video'],
                           'concurrency': 5,
                           'price_per_second': 0.8,
                           'capabilities': {'ability_type': 'reference_to_video',
                                            'ability_types': ['reference_to_video',
                                                              'digital_human',
                                                              'multi_character',
                                                              'native_audio',
                                                              'voice_reference',
                                                              'multi_shot'],
                                            'adapter_ability_types': ['reference_to_video',
                                                                      'digital_human',
                                                                      'voice_reference'],
                                            'input_modalities': ['text', 'image', 'audio', 'video'],
                                            'adapter_input_modalities': ['text', 'image', 'audio'],
                                            'duration': {'min': 2, 'max': 10, 'integer': True, 'verified': True},
                                            'resolutions': ['720P', '1080P'],
                                            'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4'],
                                            'api_contract_verified': True}},
            'wan2.7-videoedit': {'name': 'Wan 2.7 Video Edit',
                                 'provider': 'dashscope',
                                 'type': ['video'],
                                 'concurrency': 5,
                                 'price_per_second': 0.8,
                                 'capabilities': {'ability_type': 'video_editing',
                                                  'ability_types': ['video_editing',
                                                                    'action_transfer',
                                                                    'instruction_editing',
                                                                    'video_transfer'],
                                                  'adapter_ability_types': ['action_transfer', 'video_editing'],
                                                  'input_modalities': ['text', 'image', 'video'],
                                                  'adapter_input_modalities': ['text', 'image', 'video'],
                                                  'duration': {'min': 2, 'max': 10, 'integer': True, 'verified': True},
                                                  'resolutions': ['720P', '1080P'],
                                                  'ratios': ['16:9', '9:16', '1:1', '4:3', '3:4'],
                                                  'api_contract_verified': True}},
            'happyhorse-1.0-r2v': {'name': 'Happy Horse 1.0 R2V',
                                   'provider': 'dashscope',
                                   'type': ['video'],
                                   'concurrency': 5,
                                   'price_per_second': 1.0,
                                   'capabilities': {'ability_type': 'reference_to_video',
                                                    'ability_types': ['reference_to_video',
                                                                      'digital_human',
                                                                      'multi_character',
                                                                      'native_audio',
                                                                      'multi_shot'],
                                                    'adapter_ability_types': ['reference_to_video', 'digital_human'],
                                                    'input_modalities': ['text', 'image'],
                                                    'adapter_input_modalities': ['text', 'image'],
                                                    'duration': {'min': 3,
                                                                 'max': 15,
                                                                 'integer': True,
                                                                 'verified': True},
                                                    'resolutions': ['720P', '1080P'],
                                                    'ratios': ['16:9', '9:16', '3:4', '4:3', '1:1'],
                                                    'api_contract_verified': True}},
            'happyhorse-1.0-video-edit': {'name': 'Happy Horse 1.0 Video Edit',
                                          'provider': 'dashscope',
                                          'type': ['video'],
                                          'concurrency': 5,
                                          'price_per_second': 1.0,
                                          'capabilities': {'ability_type': 'video_editing',
                                                           'ability_types': ['video_editing',
                                                                             'action_transfer',
                                                                             'instruction_editing',
                                                                             'native_audio'],
                                                           'adapter_ability_types': ['action_transfer',
                                                                                     'video_editing'],
                                                           'input_modalities': ['text', 'image', 'video'],
                                                           'adapter_input_modalities': ['text', 'image', 'video'],
                                                           'duration': {'min': 3,
                                                                        'max': 15,
                                                                        'integer': True,
                                                                        'verified': True},
                                                           'resolutions': ['720P', '1080P'],
                                                           'api_contract_verified': True}},
            'seedance-1-0-pro': {'name': 'Seedance 1.0 Pro',
                                 'provider': 'seedance',
                                 'type': ['video'],
                                 'concurrency': 10,
                                 'price_per_second': 0.5,
                                 'capabilities': {'ability_type': 'image_to_video',
                                                  'ability_types': [],
                                                  'adapter_ability_types': ['first_frame_i2v'],
                                                  'api_contract_verified': False}},
            'seedance-1-0-lite': {'name': 'Seedance 1.0 Lite',
                                  'provider': 'seedance',
                                  'type': ['video'],
                                  'concurrency': 10,
                                  'price_per_second': 0.3,
                                  'capabilities': {'ability_type': 'image_to_video',
                                                   'ability_types': [],
                                                   'adapter_ability_types': ['first_frame_i2v'],
                                                   'api_contract_verified': False}}}}
 
 
def load_model_config() -> dict[str, Any]:
    return MODEL_CONFIG
 
 
def get_model_config(model: str) -> dict[str, Any]:
    """Get metadata for one model, with a loose fallback for provider aliases."""
    models = MODEL_CONFIG.get("models", {})
    if model in models:
        return models[model]
 
    model_lower = model.lower()
    for key, value in models.items():
        if key in model_lower or model_lower in key:
            return value
 
    return {
        "name": model,
        "provider": "unknown",
        "type": [],
        "concurrency": 3,
    }
 
 
def get_max_concurrency(model: str, enable_concurrency: bool = False) -> int:
    if not enable_concurrency:
        return 1
    return int(get_model_config(model).get("concurrency", 3))
 
 
def get_models_by_type(model_type: str) -> list[dict[str, Any]]:
    result = []
    for model_id, metadata in MODEL_CONFIG.get("models", {}).items():
        if model_type in (metadata.get("type") or []):
            result.append({"id": model_id, **metadata})
    return result
 
 
def model_records(media_type: Optional[str] = None) -> list[dict[str, Any]]:
    records = []
    for model_id, metadata in MODEL_CONFIG.get("models", {}).items():
        resolved_media_type = _resolve_media_type(metadata.get("type") or [])
        if media_type and resolved_media_type != media_type:
            continue
        if resolved_media_type not in {"image", "video"}:
            continue
        records.append(_workflow_info(model_id, metadata, resolved_media_type))
    return records
 
 
def list_api_models(
    media_type: Optional[str] = None,
    required_adapter_abilities: Optional[list[str]] = None,
    verified_only: bool = False,
) -> list[dict[str, Any]]:
    records = model_records(media_type=media_type)
    required = set(required_adapter_abilities or [])
    if verified_only:
        records = [record for record in records if record.get("api_contract_verified", True)]
    if required:
        records = [record for record in records if required.intersection(model_ability_tags(record))]
    return records
 
 
def parse_api_model(model: str, media_type: str) -> tuple[str, str]:
    if model and model.startswith("api/"):
        _, provider, model_id = model.split("/", 2)
        return provider, model_id
 
    metadata = MODEL_CONFIG.get("models", {}).get(model)
    if metadata and _resolve_media_type(metadata.get("type") or []) == media_type:
        return metadata.get("provider", ""), model
    return "", model
 
 
def media_capabilities(provider: str, model: str, media_type: str) -> dict[str, Any]:
    metadata = MODEL_CONFIG.get("models", {}).get(model, {})
    capabilities = metadata.get("capabilities")
    if capabilities:
        return deepcopy(capabilities)
    if media_type == "image":
        return {
            "ability_type": "image_generation",
            "ability_types": ["text_to_image"],
            "adapter_ability_types": ["text_to_image"],
            "input_modalities": ["text"],
            "adapter_input_modalities": ["text"],
            "api_contract_verified": False,
        }
    return {
        "ability_type": "image_to_video",
        "ability_types": [],
        "adapter_ability_types": ["first_frame_i2v"],
        "input_modalities": ["text", "image"],
        "adapter_input_modalities": ["text", "image"],
        "api_contract_verified": False,
        "duration": {"min": 3, "max": 15, "integer": True, "verified": False},
    }
 
 
def video_capabilities(provider: str, model: str) -> dict[str, Any]:
    return media_capabilities(provider, model, "video")
 
 
def image_capabilities(provider: str, model: str) -> dict[str, Any]:
    return media_capabilities(provider, model, "image")
 
 
def model_ability_tags(record: dict[str, Any]) -> set[str]:
    tags = set(record.get("adapter_ability_types") or [])
    tags.update(record.get("ability_types") or [])
    if record.get("ability_type"):
        tags.add(record["ability_type"])
    tags.update(record.get("type") or [])
    return tags
 
 
def _workflow_info(model_id: str, metadata: dict[str, Any], media_type: str) -> dict[str, Any]:
    provider = metadata.get("provider", "")
    capabilities = media_capabilities(provider, model_id, media_type)
    return {
        "key": f"api/{provider}/{model_id}",
        "name": model_id,
        "display_name": f"{metadata.get('name') or model_id} - API {provider.title()}",
        "source": "api",
        "provider": provider,
        "model": model_id,
        "media_type": media_type,
        "type": metadata.get("type", []),
        "capabilities": capabilities,
        "ability_type": capabilities.get("ability_type"),
        "ability_types": capabilities.get("ability_types", []),
        "adapter_ability_types": capabilities.get("adapter_ability_types", []),
        "input_modalities": capabilities.get("input_modalities", []),
        "adapter_input_modalities": capabilities.get("adapter_input_modalities", []),
        "api_contract_verified": capabilities.get("api_contract_verified", False),
        "concurrency": metadata.get("concurrency"),
    }
 
 
def _resolve_media_type(types: list[str]) -> str:
    if "video" in types:
        return "video"
    if any(item in types for item in ("t2i", "i2i", "image")):
        return "image"
    return ""