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

byteplus.ts

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