Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

byteplus.ts

719 lines23.6 KB

1/**
2 * BytePlus (ModelArk + Seed Speech) — SDK-generated specs, live models.
3 *
4 * BytePlus publishes no OpenAPI document: `/openapi.json`, `/swagger.json`
5 * and `/docs` on the Ark data plane all answer 200 with an EMPTY body (a
6 * catch-all, not a document — re-probed with a real key 2026-08-12), and the
7 * genuine per-action documents live behind the console's API Explorer, which
8 * needs an interactive login.
9 *
10 * It does, however, publish an official Go SDK whose model package declares
11 * the entire Ark data plane as `json:"…"`-tagged structs. Those are plain
12 * text, so `fetchSpec` pulls them from GitHub on the ordinary spec-sync cron
13 * and `byteplus-ark-build.ts` turns them into the Ark document — the spec
14 * tracks upstream SDK releases with no codegen step and no committed
15 * artifact. `byteplus-spec.ts` keeps the hand-ported document as the fallback
16 * for when GitHub is unreachable or the SDK is refactored past what the
17 * parser handles.
18 *
19 * Seed Speech appears in no BytePlus SDK in any language, so the voice
20 * document stays hand-written.
21 *
22 * The MODEL CATALOG is different: Ark's data-plane `GET /models` is a real,
23 * richly-typed source (created / task_type / token_limits / modalities /
24 * features / status), so `listModels` prefers it whenever `ARK_API_KEY` is
25 * set. Two things keep the curated catalog alive underneath it:
26 *
27 * 1. The listing is NOT exhaustive — `seedream-5-0-lite-260128` answers
28 * requests but is absent from it (confirmed live 2026-08-12).
29 * 2. Seed Speech (TTS/ASR) lives on a different host entirely and appears in
30 * no Ark listing.
31 *
32 * So the live rows win where they state a fact, and the curated entries
33 * fill the gaps, including activity and modalities on a live id whose
34 * listing names neither. With no key the provider still serves the curated
35 * catalog and reports that fallback on `docsFailures`, so a dropped secret
36 * is not a healthy poll. A live response with no `data` array, or an empty
37 * one, throws: the poll keeps the stored rows instead of writing the catalog.
38 */
39import type { Activity } from '#/db/schema.ts'
40import { errorMessage } from '#/server/errors.ts'
41import {
42 ingestFailedEvent,
43 noteIngest,
44} from '#/server/ingest/ingest-signals.ts'
45import { contentHash } from '#/server/kv.ts'
46import {
47 ARK_GO_FILES,
48 ARK_GO_SOURCE_URL,
49 arkGoFileUrl,
50 buildArkSpecFromGo,
51} from './byteplus-ark-build.ts'
52import { byteplusModelPricing } from './byteplus-pricing.ts'
53import { byteplusSpeechPricing } from './byteplus-speech-pricing.ts'
54import { byteplusServerTools } from './byteplus-tools.ts'
55import { docsReport, docsRun } from './model-facts.ts'
56import {
57 byteplusModelReasoning,
58 listsReasoning,
59 overlayModelFacts,
60} from './reasoning-config.ts'
61import { bearerConnect, headerApiKeyConnect } from './connect.ts'
62import {
63 BYTEPLUS_ARK_BASE_URL,
64 BYTEPLUS_ARK_DOCS_URL,
65 BYTEPLUS_VOICE_BASE_URL,
66 BYTEPLUS_VOICE_DOCS_URL,
67 bytePlusArkSpec,
68 bytePlusVoiceSpec,
69} from './byteplus-spec.ts'
70import { githubRequestInit } from './github.ts'
71import { byteplusGenerationEndpointId } from './model-meta.ts'
72import {
73 SEEDANCE_DURATION_DOCS,
74 SEEDANCE_DURATIONS,
75 seedanceActivityRequests,
76 uncoveredSeedanceIds,
77} from './byteplus-video-duration.ts'
78import { byteplusIdSuffixDate } from './release-dates.ts'
79import { fetchJson, fetchText, sha256Text } from './types.ts'
80import type {
81 ListModelsResult,
82 ModelInfo,
83 OpenApiDocument,
84 ProviderConfig,
85 ProviderSecrets,
86 SpecFetchResult,
87 SpecSource,
88} from './types.ts'
89​
90const ARK_MODELS_URL = 'https://ark.ap-southeast.bytepluses.com/api/v3/models'
91​
92/**
93 * Both hosts' generation surfaces classify by exact path (the Ark and voice
94 * documents have no overlapping paths).
95 */
96function classify(path: string): Activity | null {
97 if (path === '/chat/completions') return 'chat'
98 if (path === '/images/generations') return 'image'
99 if (
100 path === '/contents/generations/tasks' ||
101 path === '/contents/generations/tasks/{id}'
102 ) {
103 return 'video'
104 }
105 if (path === '/tts/create' || path === '/auc/bigmodel/recognize/flash') {
106 return 'audio'
107 }
108 return null
110​
111/**
112 * Ark half: generated from BytePlus's Go SDK so it tracks upstream releases.
113 * Falls back to the embedded document — never to nothing — if GitHub is
114 * unreachable or the SDK is refactored beyond what the parser handles, so a
115 * bad upstream day degrades the spec's freshness rather than the service.
116 */
117async function fetchArkSpec(env: ProviderSecrets): Promise<{
118 spec: OpenApiDocument
119 source: SpecSource
120 warnings: Array<string>
121}> {
122 try {
123 const files = await Promise.all(
124 ARK_GO_FILES.map(async (name) => {
125 const url = arkGoFileUrl(name)
126 return {
127 name,
128 // Raw host: githubRequestInit leaves these unauthenticated.
129 text: await fetchText(url, githubRequestInit(url, env)),
130 }
131 }),
132 )
133 const { spec, warnings } = buildArkSpecFromGo(files)
134 return {
135 spec,
136 source: {
137 url: ARK_GO_SOURCE_URL,
138 // One document from many files: hash their concatenation in the
139 // fixed ARK_GO_FILES order so the digest is reproducible.
140 hash: await sha256Text(files.map((f) => f.text).join('')),
141 },
142 warnings,
143 }
144 } catch (error) {
145 const spec = bytePlusArkSpec()
146 return {
147 spec,
148 source: { url: BYTEPLUS_ARK_DOCS_URL, hash: await contentHash(spec) },
149 warnings: [
150 `byteplus: Go SDK spec generation failed (${errorMessage(error)}) — served the embedded Ark document instead`,
151 ],
152 }
153 }
155​
156async function fetchSpec(env: ProviderSecrets): Promise<SpecFetchResult> {
157 const ark = await fetchArkSpec(env)
158 // Seed Speech appears in no BytePlus SDK in any language, so the voice
159 // document stays hand-written; provenance hashes the document itself (the
160 // FAL embedded-spec precedent).
161 const voice = bytePlusVoiceSpec()
162 return {
163 specs: [ark.spec, voice],
164 sources: [
165 ark.source,
166 { url: BYTEPLUS_VOICE_DOCS_URL, hash: await contentHash(voice) },
167 ],
168 outputStrategy: 'post-200',
169 warnings: ark.warnings,
170 }
172​
173interface CuratedModel {
174 rawId: string
175 activity: Activity
176 contextWindow?: number
177 maxOutput?: number
178 input: Array<string>
179 output: Array<string>
180 capabilities?: unknown
182​
183const chat = (
184 rawId: string,
185 maxOutput: number,
186 capabilities: Array<string>,
187 input: Array<string> = ['text'],
188 contextWindow = 256_000,
189): CuratedModel => ({
190 rawId,
191 activity: 'chat',
192 contextWindow,
193 maxOutput,
194 input,
195 output: ['text'],
196 capabilities,
197})
198​
199const TIV = ['text', 'image', 'video']
200const TIVA = ['text', 'image', 'video', 'audio']
201const REASON_TOOLS = ['reasoning', 'tools', 'tool_choice']
202const REASON_TOOLS_SO = [
203 ...REASON_TOOLS,
204 'response_format',
205 'structured_outputs',
207​
208const video = (
209 rawId: keyof typeof SEEDANCE_DURATIONS,
210 input: Array<string>,
211 output: Array<string>,
212 resolutions: Array<string>,
213): CuratedModel => ({
214 rawId,
215 activity: 'video',
216 input,
217 output,
218 capabilities: { resolutions, duration: SEEDANCE_DURATIONS[rawId] },
219})
220​
221const image = (rawId: string, maxReferenceImages: number): CuratedModel => ({
222 rawId,
223 activity: 'image',
224 input: ['text', 'image'],
225 output: ['image'],
226 capabilities: { maxReferenceImages, sizeTokens: ['1K', '2K', '4K'] },
227})
228​
229/**
230 * Ported from `@tanstack/ai-byteplus` `model-meta.ts` (context windows,
231 * max-output, modalities, and the probed structured-output verdicts — the
232 * BytePlus capability tables are wrong in both directions, so the probe
233 * results are authoritative).
234 */
235const BYTEPLUS_MODELS: Array<CuratedModel> = [
236 // Chat (Seed / GLM / DeepSeek / gpt-oss on Ark)
237 chat('dola-seed-2-1-turbo-260628', 256_000, REASON_TOOLS_SO, TIV),
238 chat('seed-2-0-lite-260428', 128_000, REASON_TOOLS, TIVA),
239 chat('seed-2-0-mini-260428', 128_000, REASON_TOOLS, TIVA),
240 chat('seed-2-0-pro-260328', 128_000, REASON_TOOLS_SO, TIV),
241 chat('seed-2-0-lite-260228', 128_000, REASON_TOOLS_SO, TIV),
242 chat('seed-2-0-mini-260215', 128_000, REASON_TOOLS_SO, TIV),
243 chat('seed-2-0-code-preview-260328', 128_000, REASON_TOOLS, TIV),
244 chat('seed-1-8-251228', 64_000, REASON_TOOLS_SO, TIV),
245 chat('seed-1-6-250915', 32_000, REASON_TOOLS_SO, TIV),
246 chat('seed-1-6-250615', 32_000, REASON_TOOLS_SO, TIV),
247 chat('seed-1-6-flash-250715', 32_000, REASON_TOOLS_SO, TIV),
248 chat('seed-1-6-flash-250615', 32_000, REASON_TOOLS_SO, TIV),
249 chat('glm-5-2-260617', 128_000, REASON_TOOLS_SO, ['text'], 1_024_000),
250 chat('glm-4-7-251222', 128_000, REASON_TOOLS),
251 chat('deepseek-v4-pro-260425', 384_000, REASON_TOOLS, ['text'], 1_024_000),
252 chat('deepseek-v4-flash-260425', 384_000, REASON_TOOLS, ['text'], 1_024_000),
253 chat('deepseek-v3-2-251201', 32_000, REASON_TOOLS, ['text'], 128_000),
254 chat('gpt-oss-120b-250805', 64_000, ['reasoning'], ['text'], 128_000),
255 // Video (Seedance, async task API)
256 video(
257 'dreamina-seedance-2-5-260628',
258 TIVA,
259 ['video', 'audio'],
260 ['480p', '720p'],
261 ),
262 video(
263 'dreamina-seedance-2-0-260128',
264 TIVA,
265 ['video', 'audio'],
266 ['480p', '720p', '1080p', '4k'],
267 ),
268 video(
269 'dreamina-seedance-2-0-fast-260128',
270 TIVA,
271 ['video', 'audio'],
272 ['480p', '720p'],
273 ),
274 video(
275 'dreamina-seedance-2-0-mini-260615',
276 TIVA,
277 ['video', 'audio'],
278 ['480p', '720p'],
279 ),
280 video(
281 'seedance-1-5-pro-251215',
282 ['text', 'image'],
283 ['video', 'audio'],
284 ['480p', '720p', '1080p'],
285 ),
286 video(
287 'seedance-1-0-pro-250528',
288 ['text', 'image'],
289 ['video'],
290 ['480p', '720p', '1080p'],
291 ),
292 video(
293 'seedance-1-0-pro-fast-251015',
294 ['text', 'image'],
295 ['video'],
296 ['480p', '720p', '1080p'],
297 ),
298 // Image (Seedream)
299 image('dola-seedream-5-0-pro-260628', 10),
300 image('seedream-5-0-260128', 14),
301 image('seedream-5-0-lite-260128', 14),
302 image('seedream-4-5-251128', 14),
303 image('seedream-4-0-250828', 14),
304 // Seed Speech (voice host — separate product and API key)
305 {
306 rawId: 'seed-audio-1.0',
307 activity: 'audio',
308 input: ['text', 'audio'],
309 output: ['audio'],
310 },
311 {
312 rawId: 'seed-asr',
313 activity: 'audio',
314 input: ['audio'],
315 output: ['text'],
316 },
318​
319/**
320 * The live listing, or null when it cannot be trusted. A 200 with no
321 * `data` array, or an empty one, is how a bad key and a shape change both
322 * presented: `listModels` then served every curated row and the poll
323 * succeeded. Null makes the caller throw.
324 */
325function arkModelList(body: unknown): Array<ArkModel> | null {
326 if (typeof body !== 'object' || body === null || !('data' in body)) {
327 return null
328 }
329 const data = body.data
330 if (!Array.isArray(data) || data.length === 0) return null
331 return data as Array<ArkModel>
333​
334function curatedModels(): Array<ModelInfo> {
335 return BYTEPLUS_MODELS.map((m) => ({
336 rawId: m.rawId,
337 activity: m.activity,
338 contextWindow: m.contextWindow ?? null,
339 maxOutput: m.maxOutput ?? null,
340 modalities: { input: m.input, output: m.output },
341 // A chat row's list is flags; an image or video row's object is the
342 // provider's own description of the model.
343 ...(Array.isArray(m.capabilities)
344 ? { capabilities: m.capabilities }
345 : m.capabilities
346 ? { providerMetadata: m.capabilities as Record<string, unknown> }
347 : {}),
348 // Dated ids embed their release as a -YYMMDD suffix; the undated Seed
349 // Speech ids keep their poll-time firstSeenAt.
350 releasedAt: byteplusIdSuffixDate(m.rawId),
351 }))
353​
354const CURATED_BY_ID = new Map(BYTEPLUS_MODELS.map((m) => [m.rawId, m]))
355​
356/**
357 * Ark reports one or more `task_type`s per model. Highest-precedence match
358 * wins: a chat model that also accepts audio input carries `SpeechToText`
359 * alongside `TextGeneration` (e.g. seed-2-0-lite-260428) and must classify as
360 * `chat`, not `audio`, so the generation task types are checked first.
361 * 3D-generation models carry no task_type at all and fall through to null —
362 * the same treatment FAL's `text-to-3d` gets until the taxonomy grows.
363 *
364 * The listing used PascalCase (`TextToVideo`) through 2026-08 and now sends
365 * snake_case (`text_to_video`). Comparison ignores case and separators.
366 */
367const ARK_TASK_ACTIVITIES: Array<[Activity, Array<string>]> = [
368 [
369 'video',
370 [
371 'TextToVideo',
372 'ImageToVideo',
373 'MultimodalToVideo',
374 'VideoEditing',
375 'VideoExtension',
376 ],
377 ],
378 ['image', ['TextToImage', 'ImageToImage']],
379 ['embeddings', ['TextEmbedding', 'ImageEmbedding', 'MultimodalEmbedding']],
380 ['chat', ['TextGeneration', 'VisualQuestionAnswering']],
381 ['audio', ['SpeechToText', 'TextToSpeech']],
383​
384function arkTaskKey(task: string): string {
385 return task.replace(/[_\s-]/g, '').toLowerCase()
387​
388export function arkTaskActivity(
389 taskTypes: Array<string> | undefined,
390): Activity | null {
391 if (!taskTypes?.length) return null
392 const wanted = new Set(taskTypes.map(arkTaskKey))
393 for (const [activity, types] of ARK_TASK_ACTIVITIES) {
394 if (types.some((t) => wanted.has(arkTaskKey(t)))) return activity
395 }
396 return null
398​
399/**
400 * `domain` when `task_type` is absent. LLM and VLM are not mapped: a chat
401 * row states a generation task type, and a domain alone does not.
402 */
403function arkDomainActivity(domain: string | undefined): Activity | null {
404 switch (domain) {
405 case 'ImageGeneration':
406 return 'image'
407 case 'VideoGeneration':
408 return 'video'
409 case 'Embedding':
410 return 'embeddings'
411 default:
412 return null
413 }
415​
416/**
417 * Last resort for an id the listing does not classify. Seedream and
418 * Seedance are the product names on `images/generations` and
419 * `contents/generations/tasks`; the docs name models by that token.
420 */
421function arkFamilyActivity(rawId: string): Activity | null {
422 const id = rawId.toLowerCase()
423 if (id.includes('seedream')) return 'image'
424 if (id.includes('seedance')) return 'video'
425 return null
427​
428function statedModalities(
429 value: Array<string> | undefined,
430): Array<string> | null {
431 return value && value.length > 0 ? value : null
433​
434/** Output the activity itself states when the listing and catalog omit it. */
435function defaultOutput(activity: Activity | null): Array<string> | null {
436 if (activity === 'image') return ['image']
437 if (activity === 'video') return ['video']
438 return null
440​
441interface ArkModel {
442 id: string
443 name?: string
444 created?: number
445 /** Absent for live models; 'Shutdown' / 'Retiring' once wound down. */
446 status?: string
447 domain?: string
448 task_type?: Array<string>
449 modalities?: {
450 input_modalities?: Array<string>
451 output_modalities?: Array<string>
452 }
453 token_limits?: {
454 context_window?: number
455 max_input_token_length?: number
456 max_output_token_length?: number
457 max_reasoning_token_length?: number
458 }
459 features?: Record<string, unknown>
460 version?: string
462​
463/**
464 * Ark's `features.structured_outputs.json_schema` is NOT reliable: probed
465 * 2026-08-12, `seed-2-0-lite-260428` advertises `json_schema: true` and then
466 * answers a schema-bearing request with
467 * `400 InvalidParameter … json_schema is not supported by this model`, while
468 * `seed-2-0-lite-260228` (same family) accepts one. Both outcomes match
469 * TanStack AI's 2026-07-31 sweep of all 18 chat models, so their probe
470 * verdicts are carried here as a separate, clearly-labelled capability rather
471 * than letting the upstream flag stand alone. Ids outside this set get no
472 * verdict (absence ≠ unsupported).
473 */
474const PROBED_STRUCTURED_OUTPUT: Record<string, boolean> = {
475 'dola-seed-2-1-turbo-260628': true,
476 'seed-2-0-pro-260328': true,
477 'seed-2-0-lite-260228': true,
478 'seed-2-0-mini-260215': true,
479 'seed-1-8-251228': true,
480 'seed-1-6-250915': true,
481 'seed-1-6-250615': true,
482 'seed-1-6-flash-250715': true,
483 'seed-1-6-flash-250615': true,
484 'glm-5-2-260617': true,
485 'seed-2-0-lite-260428': false,
486 'seed-2-0-mini-260428': false,
487 'seed-2-0-code-preview-260328': false,
488 'deepseek-v4-pro-260425': false,
489 'deepseek-v4-flash-260425': false,
490 'deepseek-v3-2-251201': false,
491 'gpt-oss-120b-250805': false,
492 // Accepts the request with 200 but ignores the schema and answers in prose
493 // — a status-code-only probe reads this as support.
494 'glm-4-7-251222': false,
496​
497interface ArkFeatures {
498 structured_outputs?: { json_object?: boolean; json_schema?: boolean }
499 tools?: { function_calling?: boolean }
501​
502/**
503 * Chat rows speak the shared OpenRouter parameter vocabulary (#53, #76).
504 * The probe verdict beats Ark's `json_schema` flag whenever one exists.
505 */
506export function arkChatCapabilities(m: ArkModel): Array<string> {
507 const features = (m.features ?? {}) as ArkFeatures
508 const caps: Array<string> = []
509 if (features.tools?.function_calling) caps.push('tools', 'tool_choice')
510 if ((m.token_limits?.max_reasoning_token_length ?? 0) > 0) {
511 caps.push('reasoning')
512 }
513 const structured =
514 PROBED_STRUCTURED_OUTPUT[m.id] ??
515 features.structured_outputs?.json_schema === true
516 if (structured || features.structured_outputs?.json_object) {
517 caps.push('response_format')
518 }
519 if (structured) caps.push('structured_outputs')
520 return caps
522​
523/** Clip length and resolution tiers the listing does not state. */
524function curatedVideoFacts(rawId: string): Record<string, unknown> {
525 const caps = CURATED_BY_ID.get(rawId)?.capabilities
526 if (!caps || Array.isArray(caps)) return {}
527 const facts = caps as { duration?: unknown; resolutions?: unknown }
528 return {
529 ...(facts.resolutions !== undefined
530 ? { resolutions: facts.resolutions }
531 : {}),
532 ...(facts.duration !== undefined ? { duration: facts.duration } : {}),
533 }
535​
536function toModelInfo(m: ArkModel): ModelInfo {
537 const probed = PROBED_STRUCTURED_OUTPUT[m.id]
538 const curated = CURATED_BY_ID.get(m.id)
539 // Listing task type, then the listing's domain, then the curated row for
540 // this exact id, then the Seedream/Seedance product token. A stated
541 // modality side wins; a blank side takes the curated list, and an image
542 // or video row still missing an output takes that activity's output.
543 const activity =
544 arkTaskActivity(m.task_type) ??
545 arkDomainActivity(m.domain) ??
546 curated?.activity ??
547 arkFamilyActivity(m.id)
548 const input =
549 statedModalities(m.modalities?.input_modalities) ?? curated?.input ?? null
550 const output =
551 statedModalities(m.modalities?.output_modalities) ??
552 curated?.output ??
553 defaultOutput(activity)
554 return {
555 rawId: m.id,
556 displayName: m.name ?? null,
557 activity,
558 contextWindow: m.token_limits?.context_window ?? null,
559 maxOutput: m.token_limits?.max_output_token_length ?? null,
560 modalities: {
561 ...(input ? { input } : {}),
562 ...(output ? { output } : {}),
563 },
564 ...(activity === 'chat'
565 ? { capabilities: arkChatCapabilities(m) }
566 : {
567 providerMetadata: {
568 ...m.features,
569 taskType: m.task_type,
570 domain: m.domain || undefined,
571 maxReasoningTokens: m.token_limits?.max_reasoning_token_length,
572 // Distinct key from the upstream `structured_outputs` block
573 // above so the disagreement stays visible.
574 ...(probed === undefined ? {} : { structuredOutputProbed: probed }),
575 // The listing does not state clip length. The curated table does.
576 ...curatedVideoFacts(m.id),
577 },
578 }),
579 // 'Retiring' models still serve but are on the way out; both states are
580 // deprecation signals for consumers picking a model today.
581 deprecated: m.status === 'Shutdown' || m.status === 'Retiring',
582 releasedAt: m.created ?? byteplusIdSuffixDate(m.id),
583 }
585​
586/**
587 * A listed video id with no duration row still ships. The poll says which
588 * id, every time, until a row exists. Guessing the range would be worse.
589 */
590function noteMissingSeedanceDurations(models: Array<ModelInfo>): void {
591 const missing = uncoveredSeedanceIds(
592 models
593 .filter((model) => model.activity === 'video')
594 .map((model) => model.rawId),
595 )
596 if (missing.length === 0) return
597 noteIngest(
598 ingestFailedEvent(
599 'models-poll',
600 'byteplus',
601 `no Seedance duration for ${missing.join(', ')} (${SEEDANCE_DURATION_DOCS})`,
602 ),
603 )
605​
606async function listModels(
607 env: ProviderSecrets,
608 kv?: KVNamespace,
609): Promise<ListModelsResult> {
610 const docs = docsRun()
611 const key = env.ARK_API_KEY
612 // No key: the embedded catalog is still a real answer (a fresh install
613 // has nothing else), but the poll must say so. A dropped secret otherwise
614 // rewrites the live rows and counts as success.
615 if (!key) {
616 docs.failed++
617 docs.first.unshift({
618 source: ARK_MODELS_URL,
619 error: 'ARK_API_KEY is unset; serving the embedded catalog',
620 elapsedMs: 0,
621 })
622 }
623 const [pricing, speech, reasoning, tools] = await Promise.all([
624 byteplusModelPricing(docs, kv),
625 byteplusSpeechPricing(docs, kv),
626 byteplusModelReasoning(kv),
627 byteplusServerTools(docs, kv),
628 ])
629 const withPricing = (models: Array<ModelInfo>): Array<ModelInfo> =>
630 models.map((model) => {
631 // Seed Speech is priced on the voice billing pages, not the Ark one.
632 const priced = speech(model.rawId) ?? pricing(model.rawId)
633 const hosted = tools(model.rawId)
634 // Both pages may name tools for one row; keep every one of them.
635 const merged = [
636 ...new Set([
637 ...(priced.serverTools ?? []),
638 ...(hosted.serverTools ?? []),
639 ]),
640 ].sort()
641 return overlayModelFacts(
642 model,
643 priced,
644 hosted,
645 merged.length > 0
646 ? {
647 serverTools: merged,
648 factSources: {
649 serverTools: {
650 ...priced.factSources?.serverTools,
651 ...hosted.factSources?.serverTools,
652 },
653 },
654 }
655 : {},
656 reasoning(model.rawId, listsReasoning(model.capabilities)),
657 )
658 })
659 if (!key) {
660 const models = withPricing(curatedModels())
661 noteMissingSeedanceDurations(models)
662 return {
663 models,
664 docsFailures: docsReport(docs),
665 }
666 }
667​
668 const body = await fetchJson(ARK_MODELS_URL, {
669 headers: { Authorization: `Bearer ${key}` },
670 })
671 const data = arkModelList(body)
672 if (!data) {
673 throw new Error(
674 `Ark GET ${ARK_MODELS_URL} returned no models; refusing the embedded catalog`,
675 )
676 }
677 const live = data.map(toModelInfo)
678​
679 // Curated entries the listing omits: Seed Speech (different host) and ids
680 // Ark serves but does not enumerate.
681 const liveIds = new Set(live.map((m) => m.rawId))
682 const gapFillers = curatedModels().filter((m) => !liveIds.has(m.rawId))
683 const models = withPricing([...live, ...gapFillers])
684 noteMissingSeedanceDurations(models)
685 return {
686 models,
687 docsFailures: docsReport(docs),
688 }
690​
691export const byteplusProvider: ProviderConfig = {
692 id: 'byteplus',
693 displayName: 'BytePlus',
694 // Optional, not required: it upgrades the model catalog from embedded to
695 // live. fetchSpec never needs it. Without it listModels still serves the
696 // curated catalog and reports that on docsFailures.
697 authEnvVar: 'ARK_API_KEY',
698 // Overridden per operation: the generated Ark document stamps
699 // 'generated', and the Seed Speech document stamps its own verified
700 // status. This default only applies if a marker is ever missing.
701 defaultDerivation: 'probe-verified',
702 specGrain: 'provider',
703 // Default document is Ark. Seed Speech uses the voice host and
704 // X-Api-Key. A mixed document keeps those paths and overrides `servers`
705 // and `security` on each, so the Ark bearer profile is not sent there.
706 // `?activity=audio` is still the voice document on its own.
707 connect: bearerConnect(BYTEPLUS_ARK_BASE_URL, 'Ark'),
708 connectByActivity: {
709 audio: headerApiKeyConnect(BYTEPLUS_VOICE_BASE_URL, 'X-Api-Key'),
710 },
711 fetchSpec,
712 listModels,
713 classify,
714 classifyGets: true,
715 classifyDeletes: true,
716 activityModelRequests: seedanceActivityRequests,
717 generationEndpointId: ({ rawId, activity }) =>
718 byteplusGenerationEndpointId(rawId, activity),