-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathapi.ts
More file actions
331 lines (290 loc) · 6.93 KB
/
Copy pathapi.ts
File metadata and controls
331 lines (290 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
// ---- Text / Chat (Anthropic Messages API) ----
export type ContentBlock =
| { type: 'text'; text: string }
| { type: 'thinking'; thinking: string }
| { type: 'tool_use'; id: string; name: string; input: Record<string, unknown> }
| { type: 'tool_result'; tool_use_id: string; content: string };
export interface ChatMessage {
role: 'user' | 'assistant';
content: string | ContentBlock[];
}
export interface ChatTool {
name: string;
description?: string;
input_schema: Record<string, unknown>;
}
export interface ChatRequest {
model: string;
messages: ChatMessage[];
max_tokens: number;
system?: string;
temperature?: number;
top_p?: number;
stream?: boolean;
tools?: ChatTool[];
tool_choice?: { type: 'auto' | 'any' | 'tool'; name?: string };
}
export interface ChatResponse {
id: string;
type: 'message';
role: 'assistant';
content: ContentBlock[];
model: string;
stop_reason: string;
usage: {
input_tokens: number;
output_tokens: number;
};
}
// ---- Anthropic Streaming Events ----
export interface StreamMessageStart {
type: 'message_start';
message: ChatResponse;
}
export interface StreamContentBlockStart {
type: 'content_block_start';
index: number;
content_block: ContentBlock;
}
export interface StreamContentBlockDelta {
type: 'content_block_delta';
index: number;
delta:
| { type: 'text_delta'; text: string }
| { type: 'thinking_delta'; thinking: string }
| { type: 'input_json_delta'; partial_json: string };
}
export interface StreamContentBlockStop {
type: 'content_block_stop';
index: number;
}
export interface StreamMessageDelta {
type: 'message_delta';
delta: { stop_reason: string };
usage: { output_tokens: number };
}
export interface StreamMessageStop {
type: 'message_stop';
}
export type StreamEvent =
| StreamMessageStart
| StreamContentBlockStart
| StreamContentBlockDelta
| StreamContentBlockStop
| StreamMessageDelta
| StreamMessageStop;
// ---- Speech / TTS ----
export interface SpeechRequest {
model: string;
text: string;
voice_setting?: {
voice_id?: string;
speed?: number;
vol?: number;
pitch?: number;
};
audio_setting?: {
format?: string;
sample_rate?: number;
bitrate?: number;
channel?: number;
};
language_boost?: string;
pronunciation_dict?: Array<{ tone: string; text: string }>;
output_format?: 'url' | 'hex';
stream?: boolean;
subtitle_enable?: boolean; // Correct API parameter name (not 'subtitle')
}
export interface SpeechResponse {
base_resp: BaseResp;
data: {
audio?: string; // hex-encoded audio data
audio_url?: string;
subtitle_file?: string; // URL to download subtitle JSON file (when subtitle_enable=true)
status: number;
};
extra_info?: {
audio_length?: number;
audio_sample_rate?: number;
audio_size?: number;
bitrate?: number;
word_count?: number;
invisible_character_ratio?: number;
};
}
// ---- Voice List ----
export interface SystemVoiceInfo {
voice_id: string;
voice_name: string;
description: string[];
}
export interface VoiceListResponse {
system_voice?: SystemVoiceInfo[];
base_resp: BaseResp;
}
// ---- Image ----
export interface ImageRequest {
model: string;
prompt: string;
aspect_ratio?: string;
n?: number;
seed?: number;
width?: number;
height?: number;
prompt_optimizer?: boolean;
aigc_watermark?: boolean;
response_format?: 'url' | 'base64';
subject_reference?: Array<{
type: string;
image_url?: string;
image_file?: string;
}>;
}
export interface ImageResponse {
base_resp: BaseResp;
data: {
image_urls?: string[];
image_base64?: string[];
task_id: string;
success_count: number;
failed_count: number;
};
}
// ---- Video ----
export interface VideoRequest {
model: string;
prompt: string;
first_frame_image?: string;
last_frame_image?: string;
callback_url?: string;
subject_reference?: Array<{
type: string;
image: string[];
}>;
}
export interface VideoResponse {
base_resp: BaseResp;
task_id: string;
status: string;
}
export interface VideoTaskResponse {
base_resp: BaseResp;
task_id: string;
status: 'Queueing' | 'Processing' | 'Success' | 'Failed' | 'Unknown';
file_id?: string;
video_width?: number;
video_height?: number;
}
// ---- Music ----
export interface MusicRequest {
model: string;
prompt?: string;
lyrics?: string;
is_instrumental?: boolean;
lyrics_optimizer?: boolean;
audio_url?: string;
audio_base64?: string;
seed?: number;
audio_setting?: {
format?: string;
sample_rate?: number;
bitrate?: number;
channel?: number;
};
output_format?: 'url' | 'hex';
stream?: boolean;
aigc_watermark?: boolean;
}
export interface MusicResponse {
base_resp: BaseResp;
data: {
audio?: string;
audio_url?: string;
status: number;
};
extra_info?: {
audio_length?: number;
audio_sample_rate?: number;
audio_size?: number;
bitrate?: number;
};
}
export interface LyricsGenerationRequest {
mode: 'write_full_song' | 'edit';
prompt?: string;
lyrics?: string;
title?: string;
}
export interface LyricsGenerationResponse {
song_title?: string;
style_tags?: string;
lyrics: string;
base_resp: BaseResp;
}
// ---- Quota ----
export interface QuotaResponse {
model_remains: QuotaModelRemain[];
}
export interface QuotaModelRemain {
model_name: string;
start_time: number;
end_time: number;
remains_time: number;
current_interval_total_count: number;
current_interval_usage_count: number;
current_interval_remaining_percent?: number;
current_weekly_total_count: number;
current_weekly_usage_count: number;
current_weekly_remaining_percent?: number;
// Server-side status. 1 = normal (limited), 2 = exhausted, 3 = unlimited.
current_interval_status?: number;
current_weekly_status?: number;
weekly_start_time: number;
weekly_end_time: number;
weekly_remains_time: number;
// Weekly display multiplier in permille (1/1000). The server returns the
// base weekly remaining percent and a separate boost factor; the rendered
// weekly value is base × (boost_permille / 1000). 1500 ⇒ display up to 150%.
weekly_boost_permille?: number;
}
// ---- File ----
export interface FileUploadResponse {
base_resp: BaseResp;
file: {
file_id: string;
bytes: number;
created_at: number;
filename: string;
purpose: string;
};
}
export interface FileListResponse {
base_resp: BaseResp;
files: Array<{
file_id: string;
bytes: number;
created_at: number;
filename: string;
purpose: string;
}>;
}
export interface FileDeleteResponse {
base_resp: BaseResp;
file_id: number;
}
export interface FileRetrieveResponse {
base_resp: BaseResp;
file: {
file_id: string;
bytes: number;
created_at: number;
filename: string;
purpose: string;
download_url?: string;
};
}
// ---- Common ----
export interface BaseResp {
status_code: number;
status_msg: string;
}