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

byteplus-advanced.md

421 lines16.8 KB

1---
2title: "BytePlus: Advanced"
3id: byteplus-advanced
4order: 8
5description: "Advanced BytePlus setup in TanStack AI: regions, reasoning and encrypted_content, structured output, Seedance options per model, Seedream reference images, Seed Speech details, and the API reference."
6keywords:
7 - tanstack ai
8 - byteplus
9 - modelark
10 - seedance
11 - seedream
12 - seed speech
13 - encrypted_content
14 - adapter
15---
16​
17This page has the details of the BytePlus adapter. To get a first chat working, start at [BytePlus](./byteplus).
18​
19## Regions
20​
21Each Ark key works in one region only. A key from one region does not authenticate in another region. The default base URL is the Asia-Pacific south-east endpoint, `https://ark.ap-southeast.bytepluses.com/api/v3`. To use another region, set `baseURL`:
22​
23```typescript
24import { createBytePlusText } from "@tanstack/ai-byteplus";
25​
26const adapter = createBytePlusText("dola-seed-2-1-turbo-260628", process.env.ARK_API_KEY!, {
27 baseURL: "https://ark.eu-west.bytepluses.com/api/v3",
28});
29```
30​
31The BytePlus docs say that the EU endpoint has chat and images only. Seedance video is in Asia-Pacific only.
32​
33### BYOK
34​
35The two products use two keys, so [BYOK](../advanced/byok) has two providers. Import both from `@tanstack/ai-byteplus/byok`:
36​
37- `byteplusByok`: the Ark key, for chat, video, and images.
38- `byteplusVoiceByok`: the Seed Speech key, for text-to-speech and transcription.
39​
40## Reasoning and `encrypted_content`
41​
42Seed models think by default. The thinking text streams as `reasoning_content` deltas. The adapter sends it as reasoning, so `useChat` shows it apart from the answer.
43​
44What `reasoning` sends to Ark:
45​
46- `off` sends `thinking: { type: "disabled" }` and no effort.
47- The other levels send `thinking: { type: "enabled" }` and `reasoning_effort`.
48- `deepseek-v3-2-251201` is the one model that does not think by default.
49​
50Four models also send an `encrypted_content` value with their reasoning: `dola-seed-2-1-turbo-260628`, `seed-2-0-lite-260428`, `seed-2-0-mini-260428`, and `seed-2-0-pro-260328`. This value is a signature of the reasoning. BytePlus asks you to send it back, with no change, on the assistant message of the next turn.
51​
52The adapter does this for you. It reads the value from the stream and stores it as the `signature` of the thinking part. On the next request, it sends the value back. Anthropic thinking signatures work the same way.
53​
54- If you store and replay the history yourself, keep the `signature` of the thinking parts. Without it, you lose the reasoning cache hit. The request still works.
55- A structured-output turn does not keep the value. Again, you lose the cache hit, and the request still works.
56​
57## Structured output
58​
59Ten of the 18 chat models accept `response_format: { type: "json_schema" }`:
60​
61- `dola-seed-2-1-turbo-260628`
62- `seed-2-0-pro-260328`, `seed-2-0-lite-260228`, `seed-2-0-mini-260215`
63- `seed-1-8-251228`, `seed-1-6-250915`, `seed-1-6-250615`
64- `seed-1-6-flash-250715`, `seed-1-6-flash-250615`
65- `glm-5-2-260617`
66​
67```typescript
68import { chat } from "@tanstack/ai";
69import { byteplusText } from "@tanstack/ai-byteplus";
70import { z } from "zod";
71​
72const RecipeSchema = z.object({
73 name: z.string().meta({ description: "Name of the dish" }),
74 minutes: z.number().meta({ description: "Total cooking time in minutes" }),
75 ingredients: z.array(z.string()),
76});
77​
78const recipe = await chat({
79 adapter: byteplusText("dola-seed-2-1-turbo-260628"),
80 messages: [{ role: "user", content: "Give me a recipe for carbonara" }],
81 threadId: "thread-1",
82 outputSchema: RecipeSchema,
83});
84​
85console.log(recipe.name, recipe.minutes);
86```
87​
88On the other eight models, the adapter stops with an error:
89​
90- `chat({ outputSchema })` throws.
91- The streaming form sends a `RUN_ERROR` that names the models that work.
92​
93There is no JSON-mode fallback. Ark also rejects `response_format: { type: "json_object" }` on these eight models.
94​
95Two results of live tests that the BytePlus tables do not show:
96​
97- `seed-2-0-lite-260428` rejects a JSON schema. For typed output, use `seed-2-0-lite-260228` or `dola-seed-2-1-turbo-260628`.
98- `glm-4-7-251222` accepts a schema and then ignores it. It answers in prose with a `200`. The adapter does not allow a schema on this model, so you do not get output that you cannot parse.
99​
100To build a model picker, use the exported `BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS`.
101​
102## Seedance video
103​
104### Run a Seedance job from the client
105​
106Let the server poll the job. Set `stream: true` and send the events to the browser:
107​
108```typescript
109import {
110 generateVideo,
111 generationParamsFromRequest,
112 toServerSentEventsResponse,
113} from "@tanstack/ai";
114import { byteplusVideo } from "@tanstack/ai-byteplus";
115​
116export async function POST(request: Request) {
117 const { input, threadId } = await generationParamsFromRequest("video", request);
118 if (typeof input.prompt !== "string") {
119 return new Response("Send a text prompt.", { status: 400 });
120 }
121​
122 const stream = generateVideo({
123 adapter: byteplusVideo("dreamina-seedance-2-5-260628"),
124 prompt: input.prompt,
125 threadId,
126 size: "16:9_720p",
127 duration: 5,
128 stream: true,
129 pollingInterval: 5000,
130 });
131​
132 return toServerSentEventsResponse(stream);
134```
135​
136On the client, `useGenerateVideo` tracks the job:
137​
138```tsx
139import { fetchServerSentEvents, useGenerateVideo } from "@tanstack/ai-react";
140​
141export function SeedanceGenerator() {
142 const { generate, result, videoStatus, isLoading, error } = useGenerateVideo({
143 connection: fetchServerSentEvents("/api/generate/video"),
144 threadId: "video-studio",
145 });
146​
147 return (
148 <div>
149 <button
150 onClick={() => generate({ prompt: "a guitar being played in a store" })}
151 disabled={isLoading}
152 >
153 {isLoading ? "Generating..." : "Generate video"}
154 </button>
155​
156 {isLoading && <p>Status: {videoStatus?.status ?? "starting"}</p>}
157 {error && <p>Error: {error.message}</p>}
158 {result && <video src={result.url} controls width={640} />}
159 </div>
160 );
162```
163​
164The job record stays for seven days. The video URL expires 24 hours after the job completes.
165​
166### Seedance options per model
167​
168Seedance options are different for each model. Ark rejects an option that does not apply with a `400`, for example: "the specified parameter `draft` is not supported for model seedance-1-0-pro in t2v, must be empty".
169​
170| Option | Models that accept it |
171| --- | --- |
172| `service_tier` (`"default"` or `"flex"`) | Seedance 1.x only |
173| `camera_fixed` | Seedance 1.x only |
174| `frames` (`25 + 4n`, from `29` to `289`) | `seedance-1-0-pro-250528`, `seedance-1-0-pro-fast-251015` |
175| `draft` (a cheap preview) | `seedance-1-5-pro-251215` only |
176| `priority` (`0` to `9`) | Seedance 2.5 and the `dreamina-seedance-2-0-*` models |
177| `duration: -1` (the model picks the length) | Seedance 2.5, Seedance 2.0, `seedance-1-5-pro-251215` |
178| `output_format` (`"mp4"` or `"mov"`) | Seedance 2.5 (default `mp4`) |
179| `seed`, `watermark`, `generate_audio`, `return_last_frame`, `callback_url` | All models |
180​
181- `watermark` is `false` by default for video. For Seedream images, it is `true`.
182- All models accept `generate_audio`. Only Seedance 2.5, Seedance 2.0, and `seedance-1-5-pro-251215` add an audio track.
183​
184Resolutions also change by model:
185​
186- No Seedance model has a 2K tier.
187- Only `dreamina-seedance-2-0-260128` has `4k`.
188- Seedance 2.5 accepts `480p`, `720p`, and `1080p`.
189- `seedance-1-0-pro-fast-251015` accepts `1080p`.
190​
191The adapter finds a combination that a model does not support before it sends the request, and throws a clear error.
192​
193Reference media uses the shared [role hints](../media/video-generation#role-hints): `start_frame`, `end_frame`, and `reference`.
194​
195- Seedance 2.5 and Seedance 2.0 take reference images, video, and audio.
196- Seedance 2.5 also accepts audio-only reference input. It takes up to 30 images, 10 videos, and 10 audio clips. Seedance 2.0 takes 9, 3, and 3.
197- The 1.x models take start and end frames only. `seedance-1-0-pro-fast-251015` takes a start frame only.
198​
199### Seedance 2.5
200​
201`dreamina-seedance-2-5-260628` is the newest Seedance model. Use it for long clips (up to 30 seconds), audio-only reference input, and `output_format: "mov"`.
202​
203```typescript
204import { generateVideo } from "@tanstack/ai";
205import { byteplusVideo } from "@tanstack/ai-byteplus";
206​
207const { jobId } = await generateVideo({
208 adapter: byteplusVideo("dreamina-seedance-2-5-260628"),
209 prompt: "a guitar being played in a store",
210 threadId: "thread-1",
211 size: "16:9_1080p",
212 duration: 10,
213 modelOptions: {
214 generate_audio: true,
215 priority: 5,
216 output_format: "mp4",
217 },
218});
219​
220console.log(jobId);
221```
222​
223| Capability | Seedance 2.5 |
224| --- | --- |
225| Duration | 4 to 30 seconds, or `-1` (the model picks; required for video edit tasks) |
226| Resolution | `480p`, `720p`, `1080p` (default `720p`). No 4k. |
227| Reference media | 1 to 30 images, 0 to 10 videos, 0 to 10 audio clips. Audio only is allowed. |
228| First and last frame | Yes |
229| `priority`, `generate_audio` | Yes |
230| `service_tier`, `camera_fixed`, `frames`, `draft` | No |
231​
232The account can need to activate the model, or buy a resource pack, in the Ark Console. Until then, a call fails with `404 ModelNotOpen`.
233​
234`byteplusVideo()` accepts any string, so you can use an id that BytePlus releases before this package lists it. For an unknown id, the adapter skips its local checks and lets Ark validate the request. Known ids keep their checks.
235​
236### Seedance through BytePlus or fal
237​
238You can also reach Seedance through [`@tanstack/ai-fal`](./fal). This adapter talks to BytePlus directly, so you get:
239​
240- BytePlus billing and rate limits.
241- The model ids of BytePlus.
242- All the Seedance fields above (`camera_fixed`, `draft`, `priority`, reference media roles). fal has a smaller, shared set.
243​
244Use the account that you already have. You do not need both packages for Seedance.
245​
246## Seedream reference images
247​
248To edit an image, or to guide the result with images, put image parts in the `prompt` array. Seedream takes up to 14 reference images, and `dola-seedream-5-0-pro-260628` takes up to 10:
249​
250```typescript
251import { generateImage } from "@tanstack/ai";
252import { byteplusImage } from "@tanstack/ai-byteplus";
253​
254const result = await generateImage({
255 adapter: byteplusImage("seedream-5-0-260128"),
256 prompt: [
257 { type: "text", content: "Put this guitar on a concert stage" },
258 {
259 type: "image",
260 source: { type: "url", value: "https://example.com/guitar.png" },
261 },
262 ],
263 threadId: "thread-1",
264});
265​
266console.log(result.images.length);
267```
268​
269Two Seedream behaviors to know:
270​
271- The adapter never sets `watermark` for you, so the BytePlus default (`true`) applies.
272- Seedream has no `n` option. When you ask for more than one image, the adapter uses the group-image mode (`sequential_image_generation: "auto"` with `max_images`). The model then decides how many images the prompt needs. A request for four can return two. The adapter logs a warning when this occurs.
273​
274## Seed Speech
275​
276### Voice ids
277​
278Seed Speech has no top-level `speaker` field. The voice goes inside a `references` entry. The adapter turns `voice` into `references: [{ speaker: "en_female_stokie_uranus_bigtts" }]` for you.
279​
280`modelOptions.references` replaces that entry. It does not merge with it. So if you send `references` for voice cloning, the adapter drops `voice`. To keep a stock voice with your clips, add a `speaker` entry yourself.
281​
282The end of a voice id tells you its generation:
283​
284- `_uranus_bigtts`: TTS 2.0 voices, the newest generation.
285- `_mars_bigtts` and `_moon_bigtts`: TTS 1.0 voices.
286- `*_emo_v2_*`: TTS 1.0 voices that also accept emotion tags.
287​
288The full list is in the [BytePlus voice list](https://docs.byteplus.com/en/docs/byteplusvoice/voicelist). It changes more often than this package, so the adapter accepts any string. `speaker` also takes a voice that you cloned with Voice Replication.
289​
290### Speech options
291​
292Use `modelOptions` for these:
293​
294- `ogg_opus` output and an exact `sample_rate`.
295- `references`: voice cloning, with up to three 30-second audio clips. Refer to them from the text as `@Audio1` to `@Audio3`.
296- `watermark`, `speech_rate`, and the raw `enable_subtitle` timings.
297​
298```typescript
299import { generateSpeech } from "@tanstack/ai";
300import { byteplusSpeech, type BytePlusTTSResult } from "@tanstack/ai-byteplus";
301​
302const result: BytePlusTTSResult = await generateSpeech({
303 adapter: byteplusSpeech("seed-audio-1.0"),
304 text: "welcome to the guitar store",
305 threadId: "thread-1",
306 modelOptions: {
307 format: "ogg_opus",
308 sample_rate: 48000,
309 speech_rate: 20,
310 enable_subtitle: true,
311 },
312});
313​
314for (const sentence of result.subtitle?.sentences ?? []) {
315 console.log(sentence.text, sentence.start_time);
317```
318​
319### Timings
320​
321The shared `timestamps: true` option is easier than `modelOptions.enable_subtitle`. It sets the same flag. Then it maps the timings to `result.alignment` (per word) and `result.segments` (per sentence), in seconds:
322​
323```typescript
324import { generateSpeech } from "@tanstack/ai";
325import { byteplusSpeech } from "@tanstack/ai-byteplus";
326​
327const result = await generateSpeech({
328 adapter: byteplusSpeech("seed-audio-1.0"),
329 text: "welcome to the guitar store",
330 threadId: "thread-1",
331 timestamps: true,
332});
333​
334console.log(result.alignment?.unit); // "word"
335console.log(result.alignment?.endSeconds.at(-1)); // where speech stops
336```
337​
338### Dialogue
339​
340Seed Audio 1.0 makes a dialogue with several voices in one request. Pass `turns`, and the adapter builds the `references` array and the role prompt for you. A request can have up to three different voices:
341​
342```typescript
343import { generateSpeech } from "@tanstack/ai";
344import { byteplusSpeech } from "@tanstack/ai-byteplus";
345​
346// Replace SECOND_VOICE with another voice id from the BytePlus voice list.
347const SECOND_VOICE = "your-second-voice-id";
348​
349const result = await generateSpeech({
350 adapter: byteplusSpeech("seed-audio-1.0"),
351 turns: [
352 { text: "Do you sell picks?", voice: "en_female_stokie_uranus_bigtts" },
353 { text: "By the till.", voice: SECOND_VOICE },
354 ],
355 timestamps: true,
356 threadId: "thread-1",
357});
358​
359for (const segment of result.segments ?? []) {
360 console.log(segment.startSeconds, segment.text);
362```
363​
364### Watermarks
365​
366For speech, `watermark` is an object. It has two markers, and both are off by default:
367​
368- `aigc_watermark`: adds a sound marker at the end of the clip.
369- `aigc_metadata`: writes the source of the audio into the audio header. It writes nothing unless `enable` is `true`.
370​
371```typescript
372import { generateSpeech } from "@tanstack/ai";
373import { byteplusSpeech } from "@tanstack/ai-byteplus";
374​
375const result = await generateSpeech({
376 adapter: byteplusSpeech("seed-audio-1.0"),
377 text: "welcome to the guitar store",
378 threadId: "thread-1",
379 modelOptions: {
380 watermark: {
381 aigc_watermark: true,
382 aigc_metadata: { enable: true, content_producer: "guitar-store" },
383 },
384 },
385});
386​
387console.log(result.format);
388```
389​
390`watermark: true` is short for `{ aigc_watermark: true }`. Images and video use a boolean `watermark`. Only speech takes the object.
391​
392### Limits
393​
394- One request makes 120 seconds of audio at most. The limit applies to `originalDuration`, the length before `speech_rate`. BytePlus also bills on this length.
395- The raw `subtitle` timings are in milliseconds. `duration` and `originalDuration` are in seconds. `alignment` and `segments` are always in seconds.
396- The `url` on the result expires about two hours after generation. Keep the base64 `audio`, not the link.
397​
398## Transcription options
399​
400Set these in `modelOptions` of `byteplusTranscription`:
401​
402- `enable_itn`: writes spoken numbers and dates as digits.
403- `enable_punc`: adds punctuation.
404- `enable_ddc`: removes filler words.
405- `enable_speaker_info`: adds speaker labels, which come back as `segment.speaker`.
406​
407## API reference
408​
409Each factory pair has the same shape. The short factory reads the key from the environment. The `create*` factory takes an explicit API key. Both take `model` as the first argument.
410​
411| Factories | Creates | Key |
412| --- | --- | --- |
413| `byteplusText(model, config?)` / `createBytePlusText(model, apiKey, config?)` | Chat adapter | `ARK_API_KEY` or `BYTEPLUS_API_KEY` |
414| `byteplusVideo(model, config?)` / `createBytePlusVideo(model, apiKey, config?)` | Seedance video adapter (experimental) | `ARK_API_KEY` |
415| `byteplusImage(model, config?)` / `createBytePlusImage(model, apiKey, config?)` | Seedream image adapter | `ARK_API_KEY` |
416| `byteplusSpeech(model, config?)` / `createBytePlusSpeech(model, apiKey, config?)` | Seed Speech text-to-speech adapter | `BYTEPLUS_VOICE_API_KEY` |
417| `byteplusTranscription(model, config?)` / `createBytePlusTranscription(model, apiKey, config?)` | Seed Speech transcription adapter | `BYTEPLUS_VOICE_API_KEY` |
418​
419- `config.baseURL` sets the region endpoint of the Ark adapters.
420- `adapter.inputModalities` lists the input kinds of the selected chat model. It is `undefined` for a model that this package does not know.
421- BytePlus has no provider tools. Define your tools with `toolDefinition()`. Ark uses the OpenAI tool-call format, so the usual [tools flow](../tools/tools.md) works.