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

byteplus.ts

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