API 參考 BazaarLink API 總覽
BazaarLink 在不同模型與供應商之間提供統一且相容 OpenAI 的請求與回應格式。你只需整合一次,就能切換模型,不必重寫應用程式。
客戶端路由欄位的處理方式
若請求包含 transforms、route、頂層 service_tier 或 preset,這些欄位會在送往上游前移除,無法選擇上游或價格層級。provider 物件同樣不會轉送給上游;BazaarLink 自己的路由只會採用其中的 order、only、ignore、allow_fallbacks(指定或排除可服務請求的主機,僅適用於支援選擇主機的模型)與 sticky(見 :floor),其他欄位(例如 sort)會被忽略。Chat Completions 與 Responses 端點支援 models 陣列作為本地備援清單:BazaarLink 會自行路由每個模型並依該模型的 BazaarLink 客戶價格計費,清單不會轉發給上游。客戶提供的 :nitro 與 :exacto 後綴會被忽略;:floor 後綴會讓 BazaarLink 為該模型選擇最低價的主機,預設會持續黏著同一主機,可用 provider.sticky=false 取消,改為每次請求重新挑選;:eco 仍是 BazaarLink 的經濟方案,並在內部對應至 BazaarLink 的 :floor。:free 仍是獨立的目錄模型變體。
網路搜尋附加費用
使用 plugins、:online 或 web_search_options 要求網路搜尋時,現有行為維持不變,且可能產生上游附加費用;費用會計入該請求所用的金鑰,也就是 BazaarLink 平台金鑰或您的 BYOK 金鑰。
OpenAPI 規格 完整的 BazaarLink API 使用 OpenAPI 規格記錄,並提供 YAML 與 JSON 格式:
你可以將這些規格匯入 Swagger UI、Postman 或其他相容 OpenAPI 的程式碼產生器,用來探索 API 或產生用戶端函式庫。
請求 對話完成的請求本文會傳送至以下端點:
POST /v1/chat/completions
如需完整的支援欄位清單,請參閱 參數 。
請求結構
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
type Request = {
model : string ;
messages : Message [];
stream ?: boolean ;
temperature ?: number ;
max_tokens ?: number ;
max_completion_tokens ?: number ;
n ?: number ;
seed ?: number ;
stop ?: string | string [];
top_p ?: number ;
top_k ?: number ;
frequency_penalty ?: number ;
presence_penalty ?: number ;
repetition_penalty ?: number ;
min_p ?: number ;
top_a ?: number ;
logit_bias ?: Record <number , number >;
logprobs ?: boolean ;
top_logprobs ?: number ;
user ?: string ;
tools ?: Tool [];
tool_choice ?: ToolChoice ;
parallel_tool_calls ?: boolean ;
response_format ?: ResponseFormat ;
structured_outputs ?: boolean ;
plugins ?: Plugin [];
modalities ?: Array <"text" | "image" >;
image_config ?: Record <string , unknown >;
input_audio ?: InputAudio ;
reasoning_effort ?: "low" | "medium" | "high" ;
include_reasoning ?: boolean ;
reasoning ?: ReasoningConfig ;
thinking ?: ThinkingConfig ;
enable_thinking ?: boolean ;
};
type Message =
| SystemMessage
| UserMessage
| AssistantMessage
| ToolMessage ;
type SystemMessage = {
role : "system" ;
content : string | ContentPart [];
name ?: string ;
};
type UserMessage = {
role : "user" ;
content : string | ContentPart [];
name ?: string ;
};
type AssistantMessage = {
role : "assistant" ;
content ?: string | ContentPart [] | null ;
name ?: string ;
tool_calls ?: ToolCall [];
};
type ToolMessage = {
role : "tool" ;
content : string ;
tool_call_id : string ;
name ?: string ;
};
type ContentPart =
| TextContentPart
| ImageContentPart
| FileContentPart
| AudioContentPart
| VideoContentPart ;
type TextContentPart = {
type : "text" ;
text : string ;
};
type ImageContentPart = {
type : "image_url" ;
image_url : {
url : string ;
detail ?: string ;
};
};
type FileContentPart = {
type : "file" ;
file : {
filename ?: string ;
file_data : string ;
};
};
type AudioContentPart = {
type : "input_audio" ;
input_audio : InputAudio ;
};
type InputAudio = {
data : string ;
format : string ;
};
type VideoContentPart = {
type : "video_url" ;
video_url : {
url : string ;
};
};
type FunctionDescription = {
name : string ;
description ?: string ;
parameters : object ;
};
type Tool = {
type : "function" ;
function : FunctionDescription ;
};
type ToolChoice =
| "none"
| "auto"
| "required"
| {
type : "function" ;
function : {
name : string ;
};
};
type ToolCall = {
id : string ;
type : "function" ;
function : {
name : string ;
arguments : string ;
};
};
type ResponseFormat =
| {
type : "json_object" ;
}
| {
type : "json_schema" ;
json_schema : {
name : string ;
strict ?: boolean ;
schema : object ;
};
};
type Plugin = {
id : string ;
enabled ?: boolean ;
[key : string ]: unknown ;
};
type ReasoningConfig = {
effort ?: "low" | "medium" | "high" ;
max_tokens ?: number ;
exclude ?: boolean ;
};
type ThinkingConfig = {
type ?: "enabled" | "disabled" ;
budget_tokens ?: number ;
};
⌄ 顯示全部 203 行結構化輸出 強制模型返回符合 Schema 的有效 JSON。這對於建立需要程式化解析模型輸出的可靠應用程式至關重要。
json_object — 基本 JSON 模式;模型會回傳有效的 JSON。json_schema — 嚴格 Schema 模式;模型輸出必須符合提供的 JSON Schema。外掛 BazaarLink 會將 plugins 陣列轉送至選定的上游路由。外掛可用性取決於模型與供應商;使用 :online 模型變體時也會啟用 web 外掛。
JSON
{
"model" : "openai/gpt-4o" ,
"messages" : [
{ "role" : "user" , "content" : "What happened today?" }
] ,
"plugins" : [
{ "id" : "web" }
]
}
⌄ 顯示全部 9 行透過請求標頭識別您的應用程式,讓系統追蹤使用量、顯示在儀表板上,並在未來提供更細緻的分析。
TypeScript
await fetch ("https://api.bazaarlink.ai/v1/chat/completions" , {
method : "POST" ,
headers : {
"Authorization" : "Bearer <BAZAARLINK_API_KEY>" ,
"Content-Type" : "application/json" ,
"HTTP-Referer" : "https://your-app.example" ,
"X-Title" : "Your App"
},
body : JSON .stringify ({
model : "openai/gpt-4o" ,
messages : [{ role : "user" , content : "Hello!" }]
})
});
⌄ 顯示全部 13 行助手預填 在訊息陣列最後加入一則未完成的 assistant 訊息,向相容的模型路由要求接續生成。
運作方式
BazaarLink 會保留並轉送最後一則 assistant 訊息。接續行為由所選的上游模型與供應商實作,因此並非每條路由都保證支援。
TypeScript
const response = await client.chat .completions .create ({
model : "anthropic/claude-sonnet-4.6" ,
messages : [
{ role : "user" , content : "What is the meaning of life?" },
{ role : "assistant" , content : "My best answer is" }
]
});
⌄ 顯示全部 8 行回應 BazaarLink 將不同模型與供應商的完成回應正規化為統一、相容 OpenAI 的格式。
choices 永遠是陣列。串流回應使用 delta,非串流回應使用 message;可取得時亦會回傳用量與成本明細。
回應結構
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
type Response = {
id : string ;
object : "chat.completion" | "chat.completion.chunk" ;
created : number ;
model : string ;
choices : Array <NonStreamingChoice | StreamingChoice >;
usage ?: {
prompt_tokens : number ;
completion_tokens : number ;
total_tokens : number ;
cost ?: number ;
prompt_tokens_details ?: {
cached_tokens : number ;
cache_write_tokens ?: number ;
audio_tokens ?: number ;
};
completion_tokens_details ?: {
reasoning_tokens ?: number ;
image_tokens ?: number ;
};
};
};
type NonStreamingChoice = {
index : number ;
finish_reason : string | null ;
message : {
role : "assistant" ;
content : string | null ;
tool_calls ?: ToolCall [];
reasoning ?: string ;
reasoning_details ?: Array <{ type : string ; text ?: string }>;
};
};
type StreamingChoice = {
index : number ;
finish_reason : string | null ;
delta : {
role ?: string ;
content ?: string | null ;
tool_calls ?: ToolCall [];
reasoning ?: string ;
reasoning_details ?: Array <{ type : string ; text ?: string }>;
};
};
⌄ 顯示全部 46 行結束原因 finish_reason 使用 BazaarLink 正規化後的 stop、length、tool_calls、content_filter、error 等值。
JSON
{
"finish_reason" : "stop"
} 查詢成本與統計資料 使用回應 id 或 x-request-id 標頭中的不透明 BazaarLink 請求 ID 呼叫 GET /v1/generation;非串流回應也會在 x-generation-id 提供此 ID。統計資料可能延遲數秒;若收到 404,請短暫重試。
TypeScript
const generation = await fetch (
"https://api.bazaarlink.ai/v1/generation?id=<GENERATION_ID>" ,
{
headers : {
Authorization : "Bearer <BAZAARLINK_API_KEY>"
}
}
).then ((response ) => response.json ());
⌄ 顯示全部 8 行Agent 註冊 功能開啟後,Agent 可使用未付費或 x402 付費註冊入口建立帳戶。
註冊需要一個小型工作量證明。先呼叫 GET https://bazaarlink.ai/api/v1/agents/register/challenge,找出一個 solution 字串,使 challenge:solution 的 SHA-256 至少有指定數量的前導零位元(約數秒),再把 pow_challenge 與 pow_solution 隨請求送出。每個挑戰只能用一次、須來自取得它的 IP,120 秒內有效。從未使用的 Agent 金鑰會在七天後停用。 註冊還需要在請求內容帶上四個必填答案:agent_type(這是什麼 Agent,最多 80 字)、discovery_source(search、skill_md、referral、openrouter_alternatives 或 other)、intended_use(打算用來做什麼,最多 300 字)與 x402_interest(true 或 false)。缺漏或無效時回 HTTP 400、code 為 agent_survey_incomplete,並列出缺少與無效的欄位和範例請求;補上後用同一個挑戰重送即可。
GET https://bazaarlink.ai/api/v1/agents/register/challenge
POST https://api.bazaarlink.ai/api/v1/agents/register
未付費註冊接受 name、可選的 description 與 referral_code。201 回應包含 API 金鑰、額度、7 天 claim token 與到期時間、升級網址、推薦碼、free_model auto:free、base URL 和文件連結。它使用既有的免費模型機制;免費網頁搜尋需要已驗證的電子郵件,因此未付費 Agent 無法使用。
POST https://api.bazaarlink.ai/api/v1/agents/register/x402
付費註冊先回傳 HTTP 402 需求:scheme exact、network eip155:196、asset USD-T0 和 payTo。Agent 帶著 X-PAYMENT 重送後,會收到相同註冊欄位以及 payment { txHash, network, amountUsd }。付費 Agent 遵循一般付費帳戶規則;既有帳戶可使用 /api/x402/topup 加值。
人類可在 7 天 token 有效期間透過 /claim 接管未付費 Agent。註冊限制為每個 IP 每 24 小時一次,並受雲端供應商上限約束;拒絕的請求會回傳含 Retry-After 的 429。
POST https://api.bazaarlink.ai/api/x402/topup
對話完成 主要端點。與 OpenAI Chat Completions API 相容。
POST /v1/chat/completions
請求內文 model必填
string
使用 GET /v1/models 列出的 id 或 alias,例如「claude-sonnet-4.6」或「anthropic/claude-sonnet-4.6」。
messages必填
Message[]
包含 role 和 content 的訊息物件陣列
stream
boolean
若為 true,返回 Server-Sent Events 串流。預設:false
temperature
number
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
max_tokens
integer
要生成的最大 token 數量
max_completion_tokens
integer
max_tokens 的別名(OpenAI o 系列相容)。兩者皆支援,以提供的為準
top_k
integer
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
frequency_penalty
number
懲罰重複的 token。範圍:[-2, 2]。預設:0
presence_penalty
number
基於存在情況懲罰 token。範圍:[-2, 2]。預設:0
repetition_penalty
number
降低輸入中 token 重複的機率。範圍:(0, 2]。預設:1
min_p
number
相對最高機率 token 的最低入選機率。範圍:[0, 1]。預設:0
top_a
number
基於最高機率 token 的動態 Top-P。範圍:[0, 1]。預設:0
seed
integer
整數隨機種子,用於確定性取樣。部分模型不保證
user
string
終端使用者識別碼,用於監控與濫用偵測。對計費無影響。僅限 OpenAI 系列模型 —— 見下方說明。
stop
string | string[]
停止序列 — 遇到時停止生成
logit_bias
object
將 token ID 映射到偏差値 [-100, 100],在取樣前加到機率。僅限 OpenAI 系列模型 —— 見下方說明。
logprobs
boolean
回傳每個輸出 token 的對數機率。僅限 OpenAI 系列模型 —— 見下方說明。
top_logprobs
integer
每個位置回傳概率最高的 N 個候選 token(需配合 logprobs: true)。範圍:0–20。僅限 OpenAI 系列模型 —— 見下方說明。
tools
Tool[]
模型可以呼叫的工具(函式)列表
tool_choice
string | object
控制工具使用:"auto"、"none" 或指定工具
parallel_tool_calls
boolean
啟用並行工具呼叫功能。預設:true。僅限 OpenAI 系列模型 —— 見下方說明。
response_format
object
強制結構化 JSON 輸出。請參閱結構化輸出章節
structured_outputs
boolean
在支援的 provider 上要求嚴格符合 JSON schema 的輸出。原樣轉發
reasoning
object
Provider 專屬的 reasoning/thinking 設定。原樣轉發
reasoning_effort
string
OpenAI o 系列風格的 reasoning 強度:"low"、"medium" 或 "high"。原樣轉發
include_reasoning
boolean
true 時在 message.reasoning(串流為 delta.reasoning)回傳思考內容;false 則為預設會思考的模型關閉思考(見推理章節),因此不會計思考費用。沒有帶 reasoning_effort、reasoning 或 thinking 時,只有那些模型會預設思考並回傳;其他模型要帶參數才會回傳
user、logprobs、top_logprobs、logit_bias、parallel_tool_calls 只會傳到 OpenAI 系列模型
只要解析出來的模型不是 OpenAI 自家的,這五個參數就會從上游請求中被拿掉 —— 送到 anthropic/claude-*、google/gemini-* 或其他非 OpenAI 目標時,會回 200,參數被悄悄忽略,不會報錯。如果你設了其中任何一個卻沒看到效果,先檢查目標模型是不是 OpenAI 的。
請求結構 (TypeScript) 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
type Request = {
model : string ;
messages : Message [];
stream ?: boolean ;
temperature ?: number ;
max_tokens ?: number ;
max_completion_tokens ?: number ;
n ?: number ;
seed ?: number ;
stop ?: string | string [];
top_p ?: number ;
top_k ?: number ;
frequency_penalty ?: number ;
presence_penalty ?: number ;
repetition_penalty ?: number ;
min_p ?: number ;
top_a ?: number ;
logit_bias ?: Record <number , number >;
logprobs ?: boolean ;
top_logprobs ?: number ;
user ?: string ;
tools ?: Tool [];
tool_choice ?: ToolChoice ;
parallel_tool_calls ?: boolean ;
response_format ?: ResponseFormat ;
structured_outputs ?: boolean ;
plugins ?: Plugin [];
modalities ?: Array <"text" | "image" >;
image_config ?: Record <string , unknown >;
input_audio ?: InputAudio ;
reasoning_effort ?: "low" | "medium" | "high" ;
include_reasoning ?: boolean ;
reasoning ?: ReasoningConfig ;
thinking ?: ThinkingConfig ;
enable_thinking ?: boolean ;
};
type Message =
| SystemMessage
| UserMessage
| AssistantMessage
| ToolMessage ;
type SystemMessage = {
role : "system" ;
content : string | ContentPart [];
name ?: string ;
};
type UserMessage = {
role : "user" ;
content : string | ContentPart [];
name ?: string ;
};
type AssistantMessage = {
role : "assistant" ;
content ?: string | ContentPart [] | null ;
name ?: string ;
tool_calls ?: ToolCall [];
};
type ToolMessage = {
role : "tool" ;
content : string ;
tool_call_id : string ;
name ?: string ;
};
type ContentPart =
| TextContentPart
| ImageContentPart
| FileContentPart
| AudioContentPart
| VideoContentPart ;
type TextContentPart = {
type : "text" ;
text : string ;
};
type ImageContentPart = {
type : "image_url" ;
image_url : {
url : string ;
detail ?: string ;
};
};
type FileContentPart = {
type : "file" ;
file : {
filename ?: string ;
file_data : string ;
};
};
type AudioContentPart = {
type : "input_audio" ;
input_audio : InputAudio ;
};
type InputAudio = {
data : string ;
format : string ;
};
type VideoContentPart = {
type : "video_url" ;
video_url : {
url : string ;
};
};
type FunctionDescription = {
name : string ;
description ?: string ;
parameters : object ;
};
type Tool = {
type : "function" ;
function : FunctionDescription ;
};
type ToolChoice =
| "none"
| "auto"
| "required"
| {
type : "function" ;
function : {
name : string ;
};
};
type ToolCall = {
id : string ;
type : "function" ;
function : {
name : string ;
arguments : string ;
};
};
type ResponseFormat =
| {
type : "json_object" ;
}
| {
type : "json_schema" ;
json_schema : {
name : string ;
strict ?: boolean ;
schema : object ;
};
};
type Plugin = {
id : string ;
enabled ?: boolean ;
[key : string ]: unknown ;
};
type ReasoningConfig = {
effort ?: "low" | "medium" | "high" ;
max_tokens ?: number ;
exclude ?: boolean ;
};
type ThinkingConfig = {
type ?: "enabled" | "disabled" ;
budget_tokens ?: number ;
};
⌄ 顯示全部 203 行範例請求 cURL Python TypeScript
curl https://api.bazaarlink.ai/v1/chat/completions \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in one paragraph."}
],
"temperature": 0.7,
"max_tokens": 512
}'
⌄ 顯示全部 12 行回應 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
{
"id" : "85e6f35c71a31f19-SJC" ,
"object" : "chat.completion" ,
"created" : 1740000000 ,
"model" : "openai/gpt-4o" ,
"choices" : [
{
"index" : 0 ,
"message" : {
"role" : "assistant" ,
"content" : "Quantum computing leverages quantum mechanics..."
} ,
"finish_reason" : "stop"
}
] ,
"usage" : {
"prompt_tokens" : 28 ,
"completion_tokens" : 74 ,
"total_tokens" : 102 ,
"cost" : 0.0006480 ,
"prompt_tokens_details" : {
"cached_tokens" : 0
} ,
"completion_tokens_details" : {
"reasoning_tokens" : 0
}
}
}
⌄ 顯示全部 28 行回應結構 (TypeScript) BazaarLink 回傳標準化回應並移除上游專屬欄位。usage.cost 是此請求向客戶收取的美元金額。
超過 100 秒的長請求建議使用 stream:true。非串流請求約 12 秒後(預設值,可由部署設定調整)會先回應 200 並開始傳送 keepalive 空白;之後若出錯,會以 200 + error JSON 回傳。keepalive 是 JSON 本文前的空白,標準 JSON 解析器會忽略。
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
type Response = {
id : string ;
object : "chat.completion" | "chat.completion.chunk" ;
created : number ;
model : string ;
choices : (NonStreamingChoice | StreamingChoice )[];
usage ?: ResponseUsage ;
};
type NonStreamingChoice = {
index : number ;
finish_reason : "stop" | "length" | "tool_calls" | "content_filter" | null ;
message : {
role : "assistant" ;
content : string | null ;
tool_calls ?: ToolCall [];
reasoning ?: string ;
reasoning_details ?: Array <{ type : string ; text ?: string }>;
};
};
type StreamingChoice = {
index : number ;
finish_reason : string | null ;
delta : {
role ?: string ;
content ?: string | null ;
tool_calls ?: ToolCall [];
reasoning ?: string ;
reasoning_details ?: Array <{ type : string ; text ?: string }>;
};
};
type ResponseUsage = {
prompt_tokens : number ;
completion_tokens : number ;
total_tokens : number ;
cost : number ;
prompt_tokens_details ?: {
cached_tokens : number ;
cache_write_tokens ?: number ;
audio_tokens ?: number ;
};
completion_tokens_details ?: {
reasoning_tokens ?: number ;
image_tokens ?: number ;
};
};
type ToolCall = {
id : string ;
type : "function" ;
function : { name : string ; arguments : string };
};
⌄ 顯示全部 54 行圖片生成 BazaarLink 提供兩條圖片生成路徑:(A) /v1/chat/completions 並帶 modalities: ["image"] — 原生路徑,支援 SSE stream 與混合 text+image 輸出,推薦新整合使用。(B) /v1/images/generations — OpenAI DALL·E 相容請求格式,回應為 SSE event stream(避免慢速模型撞 100s 上游超時)。兩條路徑的 SSE 事件協定一致,端點選擇純粹是請求形狀偏好。圖片編輯(修改既有圖片)走 POST /v1/images/edits — 與 OpenAI images.edit 相容,用 multipart/form-data 上傳來源圖。可編輯的模型 modality 是 text+image->image(例如 qwen/qwen-image-3);純生成模型是 text->image —— 各模型的 modality 可在 GET /v1/models 查。
Response format /v1/images/generations 預設回傳 OpenAI 相容的同步 JSON(2026-07-25 起)——client.images.generate() 不需任何包裝即可使用。傳 stream: true 可改用 SSE 事件串流,適合生成時間較長的模型取得進度。
超過 20 秒的非串流請求會先回 HTTP 200(隨後以空白字元保持連線),因此較晚才發生的失敗會以「200 加錯誤內容」回傳:請檢查最上層的 `error` 物件(我們另外加上 `"object": "error"` 與 `"http_status"`)。若你的 client 讀取逾時夠長(OpenAI SDK 預設 10 分鐘),可帶 `X-BazaarLink-Sync-Wait: 90`(整數秒,1–90,預設 20),讓該時間內的失敗取得真實狀態碼;Python SDK 用 `default_headers={"X-BazaarLink-Sync-Wait": "90"}`,Node SDK 用 `defaultHeaders: { "X-BazaarLink-Sync-Wait": "90" }`。Windows 請把 JSON 存成 UTF-8 檔後用 `curl --data-binary @body.json` 送出:直接在主控台 `-d` 後輸入中文不是 UTF-8,會立刻被回 400 `invalid_utf8`。
A. /v1/chat/completions (原生,推薦) POST /v1/chat/completions
The canonical streaming path. Recommended for any new integration.
curl -N https://api.bazaarlink.ai/v1/chat/completions \
-H "Authorization: Bearer $BL_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4-image-2",
"messages": [{"role":"user","content":"a red cat on a sofa"}],
"modalities": ["image","text"],
"stream": true
}'
⌄ 顯示全部 9 行圖生圖(image-to-image):在 content 陣列帶 image_url 部件即可,支援 data URI 或 https 圖片網址(不接受 http://),最多 8 張、單張 data URI 約 10MB 內;帶圖的那則訊息必須同時含 text 部件(編輯指令)。部分模型另支援 image_config(例如 {"strength": 0.7},0–1,值越低越貼近原圖),原樣透傳給上游。
curl -N https://api.bazaarlink.ai/v1/chat/completions \
-H "Authorization: Bearer $BL_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4-image-2",
"messages": [{"role":"user","content":[
{"type":"image_url","image_url":{"url":"data:image/png;base64,..."}},
{"type":"text","text":"change the background to a night city"}
]}],
"modalities": ["image"],
"stream": true
}'
⌄ 顯示全部 12 行圖片編輯(OpenAI 相容) POST /v1/images/edits
OpenAI SDK 的 client.images.edit() 可直接使用(multipart 上傳、同步 JSON 回應,回傳 data: [{ url }])。限制同圖生圖:最多 8 張、單張 10MB;mask 與 response_format=b64_json 暫不支援。
curl https://api.bazaarlink.ai/v1/images/edits \
-H "Authorization: Bearer $BL_API_KEY " \
-F model="openai/gpt-5.4-image-2" \
-F image=@cat.png \
-F prompt="change the background to a night city" B. /v1/images/generations (DALL·E 相容) POST /v1/images/generations
OpenAI DALL-E request shape. Sync JSON ({ created, data: [{ url }] }) is the default and works with client.images.generate() out of the box; pass stream: true to get the SSE event stream documented below instead.
curl https://api.bazaarlink.ai/v1/images/generations \
-H "Authorization: Bearer $BL_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-image-1",
"prompt": "a red cat on a sofa",
"size": "1024x1024"
}'
⌄ 顯示全部 8 行model必填
string
模型 ID,例如 google/gemini-2.5-flash-image
curl -N https://api.bazaarlink.ai/v1/images/generations \
-H "Authorization: Bearer $BL_API_KEY " \
-H "Accept: text/event-stream" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-5.4-image-2","prompt":"a red cat on a sofa","stream":true}' SSE event protocol 忽略 SSE 註解列及未知或 ping 事件;處理文件列出的 image、usage 與 done 事件。
: keep-alive
event: image
data: {"index": 0, "url": "https://api.bazaarlink.ai/v1/images/proxy/<token>"}
event: image-cached # bazaarlink Redis-backed proxy URL (1 hr TTL)
data: {"index": 0, "url": "https://api.bazaarlink.ai/v1/images/proxy/<token>"}
event: usage # final cost / token count
data: {"promptTokens": 12, "completionTokens": 7080, "cost": 0.226, "durationMs": 163400, "imageCount": 1}
event: done
data: {}
⌄ 顯示全部 13 行支援的圖片模型 Model ID Modality i2i (edits)
影片生成 非同步三步驟流程(submit → poll → content)。影片生成需要 30 秒到 5 分鐘,無法套用 chat-completions 的同步請求/回應語意 — 因此 BazaarLink 把影片獨立到 /v1/videos 路徑,採用 job-id 模式:submit 拿到 vjob_* ID → poll 狀態 → 完成後 fetch bytes。將 video model 透過 /chat/completions 或 /images/generations 呼叫會回 400(code: wrong_endpoint_for_video)。費用於 completed 時依實際 usage.cost 結算。
影片任務類型 同一個端點涵蓋多種任務,實際執行哪一種由你傳入的欄位決定 —— 同一個模型可以做圖生影、首尾幀、影片接續。並非每個模型都支援每種任務,不支援時回傳 400。
文生影片
prompt
只給文字提示,從零生成,不需輸入素材。
圖生影片
frame_images: [ 首幀 ]
圖片就是畫面本身:當作第一幀讓它動起來,內容忠於原圖。例:一張貓的照片 → 那隻貓在同一個場景裡轉頭。
首尾幀生影片
frame_images: [ 首幀, 尾幀 ]
給起點與終點兩張圖,模型補出中間的運動過渡。
影片接續
input_video
延續一段既有影片。要求的 duration 必須大於來源影片的長度。
參考生影片
input_references: [ 參考圖 ]
圖片是「參考」不是畫面:模型保留主體/風格,生成全新場景。例:一張貓的照片 +「在森林裡跳舞」→ 全新影片,貓的長相保留但場景與動作都是新的(可放 1–9 張參考圖)。與圖生影片的差別:圖生影片忠於原圖;參考生影片是「照著這個角色演新戲」。
影片編輯
input_video + prompt
編輯一段既有影片 —— 換場景、風格或動作。計費 = 輸入影片秒數 + 輸出秒數。
1. 提交任務(立即回 vjob_xxx) POST /v1/videos
model必填
string
模型 ID,例如 bytedance/seedance-2.0
resolution
string
解析度:480p / 720p / 1080p 等
generate_audio
boolean
是否產生音軌(true/false)
frame_images
array
首/尾幀圖片(圖生影、首尾幀)。物件 { type: "image_url", image_url: { url }, frame_type: "first_frame" | "last_frame" } 或純 URL 字串。
input_references
array
參考生影片用的參考圖 —— 引導主體/風格,非精確幀。
input_video
string|object
影片接續與影片編輯的來源影片 URL,必須是上游可公開存取的網址。
aspect_ratio
string
寬高比,例如 16:9 或 9:16。當輸入圖已決定比例時會被忽略。
watermark
boolean
加上浮水印,預設 false。
callback_url
string
任務進入終態時呼叫的 webhook 網址——僅限 HTTPS,會做 SSRF 檢查。v1 無簽章;請視為提示,並用 GET /videos/{id} 回查確認。
curl https://api.bazaarlink.ai/v1/videos \
-H "Authorization: Bearer $BL_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "bytedance/seedance-2.0",
"prompt": "a bird flying over mountains",
"duration": 3,
"resolution": "720p",
"generate_audio": false
}'
⌄ 顯示全部 11 行Note
提交時會依最壞情況估算預留額度。工作完成後,usage.cost 是此請求向客戶收取的美元金額。
2. 輪詢狀態 GET /v1/videos/{id}
curl -H "Authorization: Bearer $BL_API_KEY " \
https://api.bazaarlink.ai/v1/videos/vjob_xxxNote
每次 GET 間隔需 ≥ 8 秒才會實際打上游(避免 rate limit)
Note
若 status=failed,reserve 金額全額退回用戶。
3. 取得影片內容 (MP4) GET /v1/videos/{id}/content
curl -H "Authorization: Bearer $BL_API_KEY " \
-o output.mp4 \
https://api.bazaarlink.ai/v1/videos/vjob_xxx/content使用須知 各模型支援的畫質不同 —— 送不支援的值會回 400 並列出可用畫質。 輸入的圖片/影片必須是公開可存取的 URL。防盜鏈的網站(例如部分 wiki)會失敗。 輸入素材會經過上游內容審核,偶爾可能被誤擋。 影片接續時,要求的 duration 必須大於來源影片長度。 輸出寬高比會跟隨輸入圖 —— 方形圖會產生方形影片。 影片編輯的計費為:輸入影片秒數 + 生成輸出秒數。 影片編輯/接續的 input_video 必須是公開網址。你在這裡生成的影片是憑 API 金鑰才能存取的,上游抓不到,所以來源影片請放到公開可讀的網址。 Webhook 沒有簽章——採取行動前請用 GET /videos/{id} 回查狀態與金額,且其中的 unsigned_urls 是絕對網址(跟輪詢回應的相對路徑不同)。 支援的影片模型 Model ID Modality Tasks bytedance/seedance-2.5 text+image->video t2v bytedance/seedance-2.0 text+image->video t2v bytedance/seedance-2.0-mini text+image->video t2v x-ai/grok-imagine-video text+image->video t2v, i2v minimax/minimax-h3 text+image->video t2v, i2v google/veo-3.1 text+image->video t2v alibaba/wan3.0 text+image->video t2v, i2v x-ai/grok-imagine-video-1.5 text+image->video i2v klingai/kling-v3.0-t2v-std text->video t2v klingai/kling-v3.0-i2v-std text+image->video i2v klingai/kling-v2.5-turbo-t2v-std text->video t2v klingai/kling-v3.0-t2v text->video t2v klingai/kling-v2.6-i2v text+image->video i2v alibaba/wan3.0-prime text+image->video t2v, i2v klingai/kling-v2.5-turbo-i2v-std text+image->video i2v klingai/kling-v2.6-t2v text->video t2v klingai/kling-v2.6-t2v-std text->video t2v bytedance/seedance-2.5-flash text+image->video t2v, i2v minimax/hailuo-3-max text+image->video t2v, i2v bytedance/seedance-2.0-fast text+image+audio+video->video t2v, i2v x-ai/grok-imagine-video-1.5-lite text+image->video t2v, i2v google/gemini-omni-1.2-flash text+image+video->text+video t2v, i2v
語音合成 將文字轉成音訊;使用 /v1/models?output_modalities=speech 的模型識別碼。按模型頁所列每百萬字元價格計費;完整緩衝音訊後才回傳二進位資料,尚不支援逐段串流。provider、transforms、route、service_tier、preset 等路由控制欄位會被忽略。
POST /v1/audio/speech
curl https://api.bazaarlink.ai/v1/audio/speech \
-H "$BAZAARLINK_AUTH_HEADER " \
-H "Content-Type: application/json" \
-d '{"model":"<speech-model-id>","input":"Hello","voice":"alloy","response_format":"mp3"}' \
--output speech.mp3
curl -D - https://api.bazaarlink.ai/v1/audio/speech \
-H "$BAZAARLINK_AUTH_HEADER " \
-H "Content-Type: application/json" \
-d '{"model":"elevenlabs/eleven-v4","input":"Hello","voice":"george","stability":0.4,"similarity_boost":0.8,"style":0.2,"use_speaker_boost":true,"language_code":"en","audio_effects":{"distance":0.3}}' \
--output speech.mp3
⌄ 顯示全部 12 行語音轉寫 使用 multipart/form-data 的 model、file,或 JSON 的 model、input_audio:{data,format}(原始 base64)。支援 wav、mp3、mp4、m4a、ogg、flac、webm、aac。解碼音訊最多 25 MiB;含 base64 的請求本文上限 50 MiB。audio.transcription_max_seconds_by_model 設定各模型上限,未設定時依序使用 audio.transcription_max_seconds 與預設 60 秒。超過會在處理前回傳 413 audio_too_long,且不收費。response_format 僅支援 json、verbose_json;timestamp_granularities 的 word、segment 只可搭配 verbose_json。不支援 stream,回傳 400 unsupported_parameter;音訊過大回傳 413 audio_too_large。provider 路由欄位被忽略。依資料庫模型價格按 usage.seconds 或輸入/輸出 token 計費;每分鐘為每秒價格乘以 60。usage.cost 是客戶支付的 USD 金額。
POST /v1/audio/transcriptions
curl https://api.bazaarlink.ai/v1/audio/transcriptions \
-H "$BAZAARLINK_AUTH_HEADER " \
-F model="<transcription-model-id>" \
-F file=@audio.wav \
-F response_format=json
curl https://api.bazaarlink.ai/v1/audio/transcriptions \
-H "$BAZAARLINK_AUTH_HEADER " \
-H "Content-Type: application/json" \
-d '{"model":"<transcription-model-id>","input_audio":{"data":"<raw-base64-audio>","format":"wav"},"response_format":"verbose_json","timestamp_granularities":["word","segment"]}'
⌄ 顯示全部 10 行文件重排 傳入 query 和 documents,取得依相關性排序的 index 與 relevance_score。計費單位為 search,依模型頁價格乘以 usage.search_units 計費,不按文件數計費。不支援串流(stream)。
POST /v1/rerank
curl https://api.bazaarlink.ai/v1/rerank \
-H "$BAZAARLINK_AUTH_HEADER " \
-H "Content-Type: application/json" \
-d '{"model":"your-rerank-model-id","query":"capital of France","documents":["Paris is the capital of France.","Berlin is in Germany."],"top_n":1}' POST /v1/chat/completions
在 /v1/chat/completions 傳入 audio 或 input_audio,並選擇支援 audio 的模型。依設定的輸入與輸出 token 單價計費;回報的文字與音訊 token 合併套用相同單價。
curl https://api.bazaarlink.ai/v1/chat/completions \
-H "$BAZAARLINK_AUTH_HEADER " \
-H "Content-Type: application/json" \
-d '{"model":"<audio-chat-model-id>","messages":[{"role":"user","content":"Say hi."}],"stream":true,"modalities":["text","audio"],"audio":{"voice":"alloy","format":"pcm16"},"max_tokens":32}' 語音合成(TTS)指南 POST /v1/audio/speech 與 OpenAI 相容:送出 JSON,回傳二進位音訊檔。語音模型包含 ElevenLabs 系列(elevenlabs/eleven-v4、eleven-v4-turbo、eleven-v3、eleven-v3-conversational、eleven-multilingual-v2、eleven-flash-v2.5、eleven-flash-v2、eleven-turbo-v2.5、eleven-turbo-v2)。最新清單請查 GET /v1/models?output_modalities=speech。 GET /v1/models 預設只回文字模型,請加 ?output_modalities=speech(或 all)才會列出語音模型。
POST /v1/audio/speech
參數 參數 型別 必填 說明 model string 是 語音模型識別碼,例如 elevenlabs/eleven-flash-v2.5。 input string 是 要合成的文字,每次最多 4,096 個字元(elevenlabs/eleven-v4 與 eleven-v4-turbo 為 10,000)。更長的文字請拆成多次請求。 voice string 是 要使用的聲音,格式依模型而定,見下方「voice 規則」。 response_format string 否 mp3(預設)或 pcm。opus、aac、flac、wav 雖被 API 接受,但目前 ElevenLabs 模型會以 400 拒絕。 speed number 否 語速,範圍 0.25–4.0;不是每個模型都會套用。 instructions string 否 聲音風格指示;不是每個模型都會套用。 stability number 否 聲音穩定度,0–1(預設 0.5)。越低越有情緒起伏,越高越平穩。僅在由我們的直連語音路線處理的 elevenlabs/* 模型生效;回應標頭 X-Voice-Settings 會標示 applied(已套用)或 ignored(未套用)。 similarity_boost number 否 與原聲的相似度,0–1(預設 0.75)。Eleven v3 不使用。 style number 否 風格誇張度,0–1(預設 0)。大於 0 會增加延遲。Eleven v4 不使用。 use_speaker_boost boolean 否 是否增強與原說話者的相似度(預設 true),會略微增加延遲。 clone_strength number 否 克隆度,0–1(多數情況建議 0)。僅適用於您自己、針對 Eleven v4 訓練的專業克隆聲音(voice_…)。 language_code string 否 兩碼小寫語言代碼(ISO 639-1),例如 ar、ja、en,用來指定朗讀語言。multilingual-v2 模型不使用。 audio_effects object 否 選填的音訊效果物件:filter_preset_id(濾鏡,如 phone、old_radio)、environment_id(空間殘響,如 small_room、hall)、background_noise_id(背景音,如 cafe)、distance(距離 0–1)、send_level(殘響量 0–1)、pan(左右位置 −1…1)。ID 只能是小寫英文、數字與底線;不另外收費。開啟殘響或 pan 不為 0 會輸出立體聲,不能搭配 pcm 輸出。
上方七個聲音設定都是選填,沒帶就完全不變;數值超出範圍會直接回 400,不會送出也不會收費。回應標頭 X-Voice-Settings 說明這次有沒有用到您的設定:applied=已套用;ignored=這次由備援路線回答,您的設定沒有被使用(聲音仍會正常產生);沒有這個標頭=您沒有帶任何聲音設定。例如 stability 設 0 會讀得更有起伏,設 1 則更平穩。
voice 規則 ElevenLabs 模型(elevenlabs/…)的 voice 可填下列聲音名稱(不分大小寫):george, sarah, adam, alice, bella, bill, brian, callum, charlie, chris, daniel, eric, harry, jessica, laura, liam, lily, matilda, river, roger, will。ElevenLabs 模型可省略 voice(預設 george)。其他值回 400 invalid_voice。您自己的自訂聲音(voice_…)請見下方「自訂聲音」章節。
alloy、echo、nova 這類 OpenAI 風格的聲音名稱,只適用於有列出這些聲音的模型。各模型支援的聲音請看模型頁。
自訂聲音(克隆)正分階段開放:請見下方「自訂聲音」章節(POST /v1/voices)。在您的帳號開通之前,請使用上列 21 個預設名稱或公開的聲音 ID。
對 ElevenLabs 模型填 alloy 會失敗
ElevenLabs 模型收到既不是 voice ID、也不在支援名稱內的聲音(例如 alloy 或 Rachel)時,會回 400 invalid_voice,訊息會列出可用的名稱。失敗的請求不收費。
內建聲音一覽 voice 欄位可填下表的聲音名稱(英文小寫)。每個聲音都附一段我們自己的試聽,也可以用 GET /api/v1/audio/voices 取得完整清單(性別、年齡層、口音、風格與試聽網址)。
?lang=(en、zh-TW、zh-CN,預設依 Accept-Language)只決定 description 的語言;試聽網址不隨參數改變:preview_urls.en(同 preview_url)是英文試聽、preview_urls.zh(同 preview_url_zh)是中文試聽。
聲音 說明 試聽 george 男聲、中年、英式口音。成熟沉穩,適合旁白與說故事。 sarah 女聲、年輕、美式口音。專業清晰,適合影視與節目式朗讀。 adam 男聲、中年、美式口音。親切自然,適合社群短影音。 alice 女聲、中年、英式口音。專業,適合教學與資訊解說。 bella 女聲、中年、美式口音。專業,適合教學與資訊解說。 bill 男聲、年長、美式口音。清晰俐落,適合廣告配音。 brian 男聲、中年、美式口音。沉穩有質感,適合社群與品牌內容。 callum 男聲、中年、美式口音。表現力強,適合角色與動畫配音。 charlie 男聲、年輕、澳洲口音。活力十足,適合對話。 chris 男聲、中年、美式口音。輕鬆隨性,適合對話。 daniel 男聲、中年、英式口音。正式穩重,適合新聞式與教學朗讀。 eric 男聲、中年、美式口音。沉穩有質感,適合對話。 harry 男聲、年輕、美式口音。粗獷有個性,適合角色配音。 jessica 女聲、年輕、美式口音。明亮可愛,適合對話。 laura 女聲、年輕、美式口音。俏皮有個性,適合社群內容。 liam 男聲、年輕、美式口音。自信有精神,適合社群內容。 lily 女聲、中年、英式口音。自信清楚,適合教學與資訊解說。 matilda 女聲、中年、美式口音。開朗親切,適合教學與資訊解說。 river 中性聲音、中年、美式口音。平靜穩定,適合對話。 roger 男聲、中年、美式口音。沉穩有質感,適合對話。 will 男聲、年輕、美式口音。放鬆隨和,適合對話。
情緒與動作標籤(audio tags) 直接把標籤用方括號寫在 input 裡,例如 [laughs]、[whispers]、[excited]、[sighs]、[crying]、[curious]、[softly]。標籤會原樣送給模型,用來決定後面那段話的語氣與演出。就算文字是中文,標籤也請維持英文。
curl https://api.bazaarlink.ai/v1/audio/speech \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{"model":"elevenlabs/eleven-v3","input":"[laughs] That was actually funny. [whispers] Do not tell anyone.","voice":"george","response_format":"mp3"}' \
--output audio-tags.mp3elevenlabs/eleven-v3 與 elevenlabs/eleven-v4 系列支援。其他語音模型不會解讀標籤,可能把括號內文字直接念出來,建議先用一小句測試。
標籤也算入 input 字元數,與其餘文字一樣計費。
輸出格式 不帶 response_format 時預設為 mp3(Content-Type 為 audio/mpeg);pcm(audio/pcm,原始 16-bit PCM)也可用。API 雖接受 opus、aac、flac、wav,但 ElevenLabs 模型目前會以 400 拒絕。請依回應標頭 Content-Type 儲存檔案。
計價方式 語音合成依 input 的字元數計費。每字元價格列在 /models 的模型頁,以及 GET /v1/models 的 pricing.character(每字元美元)。模型頁以每 100 萬字元顯示。
範例 cURL Python JavaScript
curl https://api.bazaarlink.ai/v1/audio/speech \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{"model":"elevenlabs/eleven-flash-v2.5","input":"Hello from BazaarLink.","voice":"george","response_format":"mp3"}' \
--output speech.mp3常見錯誤 狀態碼 原因與處理 400 請求有誤:缺少 model、input 或 voice;input 超過 4,096 字元;speed 不在 0.25–4.0;不支援的 response_format;Unknown voice(voice 與模型不符);unknown_model(請到 /models 確認識別碼)。 401 缺少或無效的 API Key。請以 Authorization: Bearer 帶上 BazaarLink 金鑰。 402 點數不足,請儲值後再試。 403 管理金鑰不能呼叫模型,或帳號已停用。請改用一般 API Key。 429 達到速率上限。請依 Retry-After 標頭等待後重試。 502 模型服務暫時無法使用,或音訊傳輸中斷。請重試;失敗的請求不收費。
完整參數參考: 語音合成
語音轉文字(轉錄)指南 POST /v1/audio/transcriptions 與 OpenAI 相容:以 multipart/form-data 上傳音訊(或用 JSON 傳 base64 的 input_audio),回傳文字。轉錄模型包含 elevenlabs/scribe-v2 與 elevenlabs/scribe-v2-medical。最新清單請查 GET /v1/models?output_modalities=transcription。 GET /v1/models 預設只回文字模型,請加 ?output_modalities=transcription(或 all)才會列出轉錄模型。
POST /v1/audio/transcriptions
參數 參數 型別 必填 說明 model string 是 轉錄模型識別碼,例如 elevenlabs/scribe-v2。 file file 是 音訊檔(multipart)。支援 wav、mp3、mp4、m4a、ogg、flac、webm、aac,最大 25 MiB。JSON 用戶端可改傳 input_audio: {data: base64, format}。 response_format string 否 json(預設)回傳 {text};verbose_json 另含語言、時長與 segments/words。 language string 否 選填的語言提示,例如 en 或 zh。留空則自動偵測。 prompt string 否 選填的上下文文字,幫助辨識人名與專有名詞;不是每個模型都會套用。 timestamp_granularities[] string[] 否 word 和/或 segment,只在 response_format=verbose_json 時套用,其他格式會忽略。 目前尚未回傳逐字(word)時間戳,會回傳 segments。
輸出格式 response_format 只接受 json 或 verbose_json(不支援 text、srt、vtt),也不支援 stream。音訊依模型設定長度上限,預設 60 秒;超過會在處理前回傳 413 audio_too_long,且不收費。較長的錄音請切段。
計價方式 轉錄依音訊秒數計費。每秒價格列在 /models 的模型頁,以及 GET /v1/models 的 pricing.second(每秒美元);每分鐘價格=60 × 該值。回應的 usage 會列出計費秒數,usage.cost 為實際扣款(美元)。
範例 cURL Python JavaScript
curl https://api.bazaarlink.ai/v1/audio/transcriptions \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-F model="elevenlabs/scribe-v2" \
-F file=@audio.mp3 \
-F response_format=verbose_json \
-F "timestamp_granularities[]=word" 常見錯誤 狀態碼 原因與處理 400 請求有誤:缺少 model 或 file、音訊為空、response_format 不是 json/verbose_json、帶了 stream=true(unsupported_parameter),或 timestamp_granularities 不是 word/segment。 401 缺少或無效的 API Key。 402 點數不足,請儲值後再試。 413 audio_too_large:解碼後音訊超過 25 MiB。audio_too_long:音訊超過依模型設定的長度上限(預設 60 秒),處理前即拒絕且不收費。請壓縮或切段。 429 達到速率上限。請依 Retry-After 標頭等待後重試。 502 模型服務暫時無法使用,或音訊傳輸中斷。請重試;失敗的請求不收費。
完整參數參考: 語音轉寫
自訂聲音(聲音克隆) 自訂聲音(聲音克隆)
需申請開放。自訂聲音逐一帳號開通:請聯絡客服申請。在您的帳號開通之前,所有 /v1/voices 請求都會回 403 voice_cloning_not_enabled(功能對所有人關閉時回 404 not_found)。本頁的限制與價格是預設值,可能調整。
上傳一小段您有權使用的聲音錄音,會得到一個我們自己的聲音 id(voice_…)。把這個 id 當成 POST /v1/audio/speech 的 voice 即可。聲音只有建立者本人能使用。
端點 POST /v1/voices
建立聲音(multipart/form-data)
GET /v1/voices
列出您的聲音(limit 1–100,after 帶聲音 id 取下一頁)
GET /v1/voices/{id}
取得您的其中一個聲音
DELETE /v1/voices/{id}
刪除聲音(立即生效)
POST /v1/voices/report
檢舉聲音(不需要 API 金鑰)
建立聲音:欄位 欄位 型別 必填 說明 name string 是 聲音名稱,1–60 個字元。 files file[] 是 1 到 5 個該聲音的錄音檔(mp3, wav, m4a, ogg, flac, webm)。 consent boolean 是 必須為 true:您確認有權複製並使用這個聲音(見「同意聲明」)。 consent_statement_version string 是 您確認的同意聲明版本,目前為 "v1"。 description string 否 選填,最多 200 個字元。 remove_background_noise boolean 否 選填布林值,預設 false。克隆前先清除樣本中的背景噪音。
請求是同步的:回 201 就代表聲音已可使用。請帶 Idempotency-Key 標頭(任一不重複字串),重試時沿用同一個,這樣重試不會建立或收取第二個聲音的費用。
回應 201,內容含 id(voice_…)、object("voice")、name、description、status("ready")、created_at(Unix 秒)與 usage.cost_usd(本次收取的建立費)。聲音如何製作的其他資訊不會對外提供。
GET /v1/voices 只回傳您自己的聲音:{ "object": "list", "data": [ … ], "has_more": false }。別人的聲音 id 會回 404 voice_not_found,與不存在的 id 完全一樣。
GET /v1/voices/{id} 回傳其中一個聲音(欄位同上,但沒有 usage)。
DELETE /v1/voices/{id} 回傳 { "id": "voice_…", "object": "voice", "deleted": true },立即生效:使用該聲音的語音請求會馬上失敗。刪除免費,建立費不退。
限制(預設值) 每人最多 3 個聲音。 每個聲音 1 到 5 個音檔,單檔最大 10 MB、總計 25 MB;格式:mp3, wav, m4a, ogg, flac, webm。總長約 30 秒到 5 分鐘的乾淨人聲效果最好。 每天最多建立 3 次(以 UTC 日計)。 帳號需已驗證 Email,且餘額至少 US$5。 模仿公眾人物、或聽起來像官方/員工的名稱與描述會被拒絕(invalid_voice_name)。 錄音只用來建立聲音,我們不保存錄音。我們保留聲音名稱、擁有者、同意紀錄與時間戳記。 價格 建立聲音收取一次性費用(預設 US$1.00);實際收取的金額會在 usage.cost_usd 回傳,且只有聲音建立成功才會收費。在語音合成中使用自訂聲音,每字元價格與該模型其他聲音相同。刪除免費。
同意聲明 每次建立都必須帶 consent=true 與 consent_statement_version="v1"。聲明更新時,建立會回 400 consent_version_mismatch,請以新版本重新確認。
您所確認的聲明草稿(正式文字審閱中,可能調整):
I confirm that I own the voice in these recordings or have the written permission of the person whose voice it is, that this person is an adult and has agreed to have their voice cloned and synthesized, and that I will not use the voice to impersonate a real person, to deceive, to harass, or for political persuasion, fraud or any unlawful purpose. I understand the voice can be removed and my account suspended if I break these rules. 使用自訂聲音 把聲音 id 當成 POST /v1/audio/speech (voice=voice_…) 的 voice,並搭配 elevenlabs/* 系列的語音模型。輸入上限、格式與每字元價格都依該模型。不存在、已刪除或被停用、或屬於別人的聲音 id 會回 400 invalid_voice;自訂聲音不能搭配其他模型。
範例 cURL Python JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
curl https://api.bazaarlink.ai/v1/voices \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Idempotency-Key: $(uuidgen) " \
-F name="My narrator" \
-F description="Warm and calm" \
-F consent=true \
-F consent_statement_version=v1 \
-F files=@sample-1.mp3 \
-F files=@sample-2.wav
curl "https://api.bazaarlink.ai/v1/voices?limit=20" \
-H "Authorization: Bearer $BAZAARLINK_API_KEY "
curl -X DELETE https://api.bazaarlink.ai/v1/voices/voice_0123456789abcdef01234567 \
-H "Authorization: Bearer $BAZAARLINK_API_KEY "
curl https://api.bazaarlink.ai/v1/audio/speech \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{"model":"elevenlabs/eleven-flash-v2.5","input":"Hello, this is my own voice.","voice":"voice_0123456789abcdef01234567","response_format":"mp3"}' \
--output my-voice.mp3
⌄ 顯示全部 21 行檢舉聲音 若有聲音未經同意模仿您或他人,請檢舉:POST /v1/voices/report(不需要 API 金鑰),JSON 內容為 voice_id(voice_…)或 sample_url、reason(impersonation、fraud、harassment、minor、political 或 other),以及選填的 details 與 contact(Email)。一律回 202。我們會審查檢舉並移除違規聲音,帳號可能被停權。
curl https://api.bazaarlink.ai/v1/voices/report \
-H "Content-Type: application/json" \
-d '{"voice_id":"voice_0123456789abcdef01234567","reason":"impersonation","details":"...","contact":"me@example.com"}' 負責任的使用 請勿複製公眾人物、名人、政治人物或任何未同意者的聲音。請勿用克隆聲音讓人誤以為在與本人對話,也不得用於欺騙、騷擾、政治說服或詐欺。
錯誤 狀態 代碼 意義 400 bad_request 請求格式不正確:不是 multipart/form-data、沒有音檔、description 過長,或 limit 不在 1–100。 400 consent_required 缺少 consent=true。 400 consent_version_mismatch 同意聲明版本已過期;請以目前版本重新確認。 400 invalid_voice_name 名稱為空、超過 60 個字元,或不被允許。 400 too_many_files 音檔超過 5 個。 401 invalid_api_key 缺少或無效的 API 金鑰。 402 insufficient_balance 餘額不足(建立費或最低餘額門檻)。 403 email_unverified 請先驗證 Email。 403 voice_cloning_not_enabled 您的帳號尚未開通自訂聲音,請聯絡客服申請。 403 voice_cloning_disabled 目前此服務尚未開放自訂聲音。 404 voice_not_found 沒有這個聲音(或不屬於您)。 404 not_found 找不到,包含功能尚未對您的帳號開通時的所有 /v1/voices 請求。 405 method_not_allowed 此路徑不提供該方法。 409 duplicate_request 相同的 Idempotency-Key 仍在處理中,請稍候再試。 413 file_too_large 單檔超過 10 MB,或全部檔案合計超過 25 MB。 415 unsupported_file_type 不支援的音訊格式;請使用 mp3, wav, m4a, ogg, flac, webm。 422 voice_rejected 聲音提供者的檢查沒有接受這份樣本(例如知名或內建聲音、已知的 AI 合成聲音)。聲音不會保留,也不會收費。請使用您自己聲音的清楚錄音,或您有權使用的聲音。 429 voice_create_rate_limited 已達每日建立上限,請明天(UTC)再試。 429 voice_limit_reached 已達自訂聲音的數量上限。 502 upstream_failed 聲音建立失敗,未向您收費。請改用新的 Idempotency-Key 重試。 503 voice_capacity_full 自訂聲音的名額暫時已滿,未向您收費。請稍後再試。 504 upstream_timeout 聲音服務逾時未回應,未向您收費。請用同一個 Idempotency-Key 重試。
資料 API Coming soon/即將推出 — 透過 BazaarLink 的三個端點取得公開社群及電商資料。此服務預設關閉;啟用前請求會回傳 service_paused。
提交社群資料請求 POST /v1/data/social
請求參數 代碼 型別 必填 說明 platformstring是 取自目錄的平台識別碼,例如 twitter 或 instagram。 actionstring是 該平台支援的操作;可在目錄查詢有效組合。 paramsobject否 操作專用參數;請參考目錄中的 required_params 與 optional_params。 modesync | async否 選填。async 會回傳可輪詢的任務;僅支援非同步的操作在省略時也會回傳任務。
回應格式 HTTP 200 · data.social · id · object · platform · action · count · results · usage.cost
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
{
"id" : "req_example" ,
"object" : "data.social" ,
"platform" : "twitter" ,
"action" : "search" ,
"count" : 1 ,
"results" : [
{
"id" : "post_example" ,
"url" : "https://x.com/someone/status/post_example" ,
"text" : "Example post" ,
"like_count" : 120 ,
"reply_count" : 8 ,
"retweet_count" : 14 ,
"view_count" : 5400 ,
"posted_at" : "2026-10-07T00:48:38+00:00" ,
"author_username" : "someone" ,
"author_name" : "Someone" ,
"platform" : "twitter"
}
] ,
"usage" : {
"cost" : 0.0048
}
}
⌄ 顯示全部 25 行Reddit 連結貼文:在 subreddit_posts 中,連結貼文的列(限資料來源有提供的 subreddit)另外帶有 link_url,即目標網址,內容與 external_link 相同,external_link 維持不變。自貼文或沒有目標網址的列不會有這兩個欄位。search 與 post_detail 的列不含目標網址。
非同步任務 僅支援非同步的操作,或指定 mode 為 async 時,會回傳 HTTP 202 與不透明的任務 ID。輪詢 GET /v1/data/jobs/{id}:HTTP 202 表示處理中,HTTP 200 回傳完成的 data.social 結果。任務在 15 分鐘後過期(HTTP 410 job_expired)。不存在或屬於其他帳戶的任務回傳 HTTP 404 not_found。完成的任務只在首次成功取得結果時計費一次。
{
"platform" : "instagram" ,
"action" : "discover" ,
"params" : {
"keyword" : "coffee"
} ,
"mode" : "async"
}
⌄ 顯示全部 8 行HTTP 202
{
"id" : "job_example" ,
"object" : "data.job" ,
"status" : "pending" ,
"platform" : "instagram" ,
"action" : "discover"
} 輪詢非同步任務 GET /v1/data/jobs/{id}
HTTP 202 pending → HTTP 200 data.social · HTTP 410 job_expired · HTTP 404 not_found
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"id" : "job_example" ,
"object" : "data.social" ,
"platform" : "instagram" ,
"action" : "discover" ,
"count" : 1 ,
"results" : [
{
"id" : "post_example" ,
"url" : "https://www.instagram.com/p/example/" ,
"text" : "Example result" ,
"platform" : "instagram"
}
] ,
"usage" : {
"cost" : 0.0096
}
}
⌄ 顯示全部 18 行列出可用操作及價格 GET /v1/data/catalog
object · product · platforms · actions · required_params · optional_params · max_limit · async · price_usd
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
{
"object" : "data.catalog" ,
"product" : "BazaarLink Data API" ,
"platforms" : [
{
"platform" : "twitter" ,
"actions" : [
{
"action" : "search" ,
"label" : "Keyword search" ,
"required_params" : [
"keyword"
] ,
"optional_params" : [
"sort"
] ,
"max_limit" : 200 ,
"async" : false ,
"price_usd" : 0.0048
}
]
} ,
{
"platform" : "instagram" ,
"actions" : [
{
"action" : "discover" ,
"label" : "Discover" ,
"required_params" : [
"keyword"
] ,
"optional_params" : [ ] ,
"max_limit" : null ,
"async" : true ,
"price_usd" : 0.0096
}
]
}
]
}
⌄ 顯示全部 40 行計費 價格依平台及操作分級。GET /v1/data/catalog 列出每項已啟用操作的客戶價格。成功呼叫只計費一次;失敗及零結果呼叫免費。資料 API 與網路搜尋共用每日免費額度。
錯誤代碼 {"error":{"code":"<code>","message":"<fixed message>"}}
代碼 HTTP 說明 unauthorized401 缺少 API 金鑰或金鑰無效。 forbidden403 不允許此請求。 invalid_request400 請求內容無效。 invalid_params400 操作參數遭拒絕。 unsupported_capability400 平台或操作無法使用。 insufficient_credits402 餘額不足。 budget_cap_reached402 or policy status 已達帳戶消費上限。 body_too_large413 請求內容超過大小限制。 free_quota_exhausted432 每日免費額度已用完。 rate_limited429 已達速率限制;請依 Retry-After 稍後重試。 data_unavailable503 資料服務暫時無法使用。 timeout504 請求逾時。 bad_upstream_response502 資料服務回應無效。 job_expired410 任務在 15 分鐘後過期。 not_found404 任務不存在或屬於其他帳戶。 job_failed503 非同步任務失敗。 service_paused503 服務尚未啟用或已暫停。
範例 curl curl https://api.bazaarlink.ai/v1/data/social \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{"platform":"twitter","action":"search","params":{"keyword":"BazaarLink","limit":5}}' Python (requests) import os
import requests
response = requests.post(
"https://api.bazaarlink.ai/v1/data/social" ,
headers={"Authorization" : f"Bearer {os.environ['BAZAARLINK_API_KEY' ]} " },
json={"platform" : "twitter" , "action" : "search" , "params" : {"keyword" : "BazaarLink" , "limit" : 5 }},
timeout=30 ,
)
response.raise_for_status()
print (response.json())
⌄ 顯示全部 11 行JavaScript (fetch) const response = await fetch ("https://api.bazaarlink.ai/v1/data/social" , {
method : "POST" ,
headers : {
Authorization : `Bearer ${process.env.BAZAARLINK_API_KEY} ` ,
"Content-Type" : "application/json" ,
},
body : JSON .stringify ({ platform : "twitter" , action : "search" , params : { keyword : "BazaarLink" , limit : 5 } }),
});
if (!response.ok ) throw new Error (`HTTP ${response.status} ` );
console .log (await response.json ());
⌄ 顯示全部 10 行送出決策請求 使用輸出 decisions 的模型,依具名問題評估 state。此 alpha 端點回傳非串流 JSON。透過 GET /v1/models?output_modalities=decisions 查詢可用模型識別碼;Clef 請使用此端點。輸入 tokens 按所選模型的客戶單價計費,帳戶須有足夠餘額。請先將 API 金鑰設於 BAZAARLINK_API_KEY;範例會在 BAZAARLINK_AUTH_HEADER 組成完整的 Authorization 標頭。
查看決策 API 參考
export BAZAARLINK_AUTH_HEADER="Authorization: $(printf '%s %s' 'Bearer' "$BAZAARLINK_API_KEY " ) "
curl https://api.bazaarlink.ai/v1/alpha/decisions \
-H "$BAZAARLINK_AUTH_HEADER " \
-H "Content-Type: application/json" \
-d '{
"model": "cloudflare/clef-flash",
"state": "The support agent issued a full refund.",
"questions": {
"refunded": {
"type": "noul",
"instructions": "Was a refund issued?"
}
}
}'
⌄ 顯示全部 15 行Responses API 相容 OpenAI Responses API 格式的端點,支援無狀態多輪對話、工具呼叫與多模態輸入。適用於使用 OpenAI Python SDK ≥ 1.x 的 client.responses.create() 的 Agent 框架。
POST /v1/responses
Note
使用與 Chat Completions 相同的身份驗證與模型路由邏輯。
請求內文 model必填
string
使用 GET /v1/models 列出的 id 或 alias,例如「claude-sonnet-4.6」或「anthropic/claude-sonnet-4.6」。
input必填
string | Item[]
使用者輸入 — 純字串(單則訊息)或輸入項目陣列(多輪 / 多模態對話)。
instructions
string
系統層級指令,等同於 system 角色的訊息。每次請求都必須重新傳送。
stream
boolean
若為 true,回傳 Responses API SSE 串流事件,包含 response.created、response.output_text.delta、response.completed 等事件類型。
max_output_tokens
integer
最大輸出 Token 數量(o 系列推理模型包含推理 Token)。
temperature
number
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
tools
Tool[]
工具(函式)定義,格式與 Chat Completions 相同的 JSON Schema(接受扁平的 Responses 格式,也接受巢狀格式)。不支援 OpenAI 專屬的內建託管工具(web_search_preview、file_search、computer_use_preview);網頁搜尋可透過 plugins: [{id:"web"}] 啟用,僅部分模型路由支援。
tool_choice
string | object
控制工具使用:"auto"、"none" 或指定工具
parallel_tool_calls
boolean
啟用並行工具呼叫功能。預設:true。僅限 OpenAI 系列模型 —— 見下方說明。
response_format
object
強制結構化 JSON 輸出。請參閱結構化輸出章節
previous_response_id
string
本端點是無狀態的——傳入非 null 值會直接回 400(invalid_prompt),不是被接受後忽略。請改用無狀態模式:在 input 陣列中帶入完整對話歷史。
請求結構 (TypeScript) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
type ResponsesRequest = {
model : string ;
input : string | InputItem [];
instructions ?: string ;
stream ?: boolean ;
max_output_tokens ?: number ;
temperature ?: number ;
top_p ?: number ;
tools ?: Tool [];
tool_choice ?: "auto" | "none" | "required" | object ;
parallel_tool_calls ?: boolean ;
previous_response_id ?: string ;
};
type InputItem =
| { type ?: "message" ; role : "user" | "assistant" | "system" | "developer" ; content : string | ContentBlock [] }
| { type : "function_call_output" ; call_id : string ; output : string }
| { type : "function_call" ; call_id : string ; name : string ; arguments : string };
type ContentBlock =
| { type : "input_text" ; text : string }
| { type : "input_image" ; image_url : string ; detail ?: "auto" | "low" | "high" };
⌄ 顯示全部 24 行範例請求 cURL Python Multi-turn Streaming
curl https://api.bazaarlink.ai/v1/responses \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4-mini",
"instructions": "You are a helpful assistant.",
"input": "What is the capital of Taiwan?"
}'
⌄ 顯示全部 8 行回應格式 BazaarLink 回傳標準化回應,並移除上游專屬欄位。回應中不透明的 BazaarLink 請求 ID 與 x-request-id 相同;可搭配 GET /v1/generation 使用。非串流回應也會在 x-generation-id 回傳同一個 ID。usage.cost 是向客戶收取的美元金額。統計資料可能在完成後數秒才可用;若收到 404,請稍後短暫重試。
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
type ResponsesResponse = {
id : string ;
object : "response" ;
created_at : number ;
completed_at : number ;
status : "completed" | "failed" | "incomplete" ;
model : string ;
output : OutputItem [];
usage : {
input_tokens : number ;
output_tokens : number ;
total_tokens : number ;
cost ?: number ;
} | null ;
error : null | { code : string ; message : string };
};
type OutputItem =
| {
type : "message" ;
id : string ;
role : "assistant" ;
status : "completed" ;
content : Array <{ type : "output_text" ; text : string ; annotations : [] }>;
}
| { type : "function_call" ; id : string ; call_id : string ; name : string ; arguments : string ; status : "completed" };
⌄ 顯示全部 27 行從 Chat Completions 遷移 將 messages 改為 input(字串或陣列),以 instructions 取代 system 角色訊息,並從 output[0].content[0].text 讀取回應內容(原為 choices[0].message.content)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
response = client.chat.completions.create(
model="openai/gpt-5.4-mini" ,
messages=[
{"role" : "system" , "content" : "You are helpful." },
{"role" : "user" , "content" : "Hello" },
]
)
text = response.choices[0 ].message.content
response = client.responses.create(
model="openai/gpt-5.4-mini" ,
instructions="You are helpful." ,
input ="Hello"
)
text = response.output[0 ].content[0 ].text
⌄ 顯示全部 17 行限制事項 previous_response_id 或 store: true 會被拒絕並回傳 400(錯誤碼 invalid_prompt)——不是被接受後忽略。請一律使用無狀態模式,在 input 陣列中帶入完整對話歷史。 不支援 OpenAI 專屬的內建託管工具(web_search_preview、file_search、computer_use_preview)。網頁搜尋可透過 plugins: [{id:"web"}] 啟用,僅部分模型路由支援。 background: true 會被接受但忽略,請求一律同步執行到完成為止。 Messages(Anthropic 相容) 相容 Anthropic 的 Messages API,適用於 Claude SDK。將 SDK 指向 BazaarLink 並使用 BazaarLink API 金鑰;回應欄位與計費中繼資料遵循下方記載的 BazaarLink 規範。
POST /v1/messages
Note
支援 Bearer token 或 x-api-key header(相容 Anthropic SDK)。最大請求 body 為 10 MB。
請求內文 model必填
string
使用 GET /v1/models 列出的 id 或 alias,例如「claude-sonnet-4.6」或「anthropic/claude-sonnet-4.6」。
max_tokens必填
integer
生成的最大 token 數(正整數)。
messages必填
Message[]
對話訊息陣列(不可為空)。
system
string
選填的 system prompt。
stream
boolean
若為 true,返回 Server-Sent Events 串流。預設:false
temperature
number
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
top_k
integer
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
stop_sequences
string[]
自訂停止序列字串陣列。
tools
Tool[]
模型可以呼叫的工具(函式)列表
tool_choice
string | object
控制工具使用:"auto"、"none" 或指定工具
範例請求 Python TypeScript cURL
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_KEY"
)
response = client.messages.create(
model="anthropic/claude-opus-4.6" ,
max_tokens=1024 ,
messages=[{"role" : "user" , "content" : "Hello" }]
)
print (response.content[0 ].text)
⌄ 顯示全部 13 行回應 BazaarLink 回傳標準化回應,並移除上游專屬欄位。回應中不透明的 BazaarLink 請求 ID 與 x-request-id 相同;可搭配 GET /v1/generation 使用。非串流回應也會在 x-generation-id 回傳同一個 ID。usage.cost 與 usage.bz_cost 皆為向客戶收取的同一筆美元金額。統計資料可能在完成後數秒才可用;若收到 404,請稍後短暫重試。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"id" : "85e6f35c71a31f19-SJC" ,
"type" : "message" ,
"role" : "assistant" ,
"model" : "anthropic/claude-opus-4.6" ,
"content" : [
{ "type" : "text" , "text" : "Hello! How can I help you today?" }
] ,
"stop_reason" : "end_turn" ,
"usage" : {
"input_tokens" : 10 ,
"output_tokens" : 12 ,
"cache_read_input_tokens" : 0 ,
"cache_creation_input_tokens" : 0 ,
"cost" : 0.00042 ,
"bz_cost" : 0.00042
}
}
⌄ 顯示全部 18 行錯誤 envelope 會依失敗情況而異。若有 error.type,請搭配 HTTP 狀態碼判斷;error.code 可能是字串、數字 HTTP 狀態碼,也可能省略。處理方式請參閱「錯誤」章節。
模型 列出所有可用模型及其定價和能力資訊。 此端點不需要身份驗證。
GET /v1/models
cURL Python fetch
curl https://api.bazaarlink.ai/v1/models
curl "https://api.bazaarlink.ai/v1/models?output_modalities=all" 回應 {
"data" : [
{
"id" : "openai/gpt-4o" ,
"name" : "GPT 4.1" ,
"context_length" : 1047576 ,
"modality" : "text+image+file->text" ,
"pricing" : {
"prompt" : "2.00" ,
"completion" : "8.00"
}
}
]
}
⌄ 顯示全部 14 行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
type ModelsResponse = {
data : Model [];
};
type Model = {
id : string ;
name : string ;
context_length : number | null ;
modality : string | null ;
architecture ?: {
input_modalities ?: string [];
output_modalities ?: Array <
"text" | "image" | "embeddings" | "audio" |
"video" | "rerank" | "speech" | "transcription"
>;
};
pricing : {
prompt : string ;
completion : string ;
input_cache_read ?: string ;
input_cache_write ?: string ;
image_output ?: string ;
};
description ?: string | null ;
top_provider ?: {
max_completion_tokens ?: number ;
};
supported_parameters ?: string [];
pricing_tiers ?: {
above_prompt_tokens : number ;
prompt : string ;
completion : string ;
input_cache_read ?: string ;
input_cache_write ?: string ;
}[];
};
⌄ 顯示全部 37 行依輸入長度分階定價 部分模型在 prompt 超過 token 門檻後會切換到不同的整張價目表,並非只有超過門檻的部分套用新價 — 而是整張價目表切換。門檻為嚴格不等式:輸入 token 數剛好等於 N 時仍套用 N 以下的那一階,僅當輸入 token 數大於 N 時才套用較高階。
pricing_tiers 是 pricing 的同層欄位,僅當模型有超出基礎價的覆寫階層時才會出現。項目依 above_prompt_tokens 遞增排序;prompt/completion 為每 token 的美元價(與 pricing.prompt/pricing.completion 同單位)。pricing.prompt 與 pricing.completion 永遠是基礎(最低)那一階。
大多數模型沒有分階定價 — 對這些模型,回應中會完全沒有 pricing_tiers 這個欄位。
{
"id" : "openai/gpt-4o" ,
"name" : "GPT 4.1" ,
"pricing" : {
"prompt" : "2.00" ,
"completion" : "8.00"
} ,
"pricing_tiers" : [
{
"above_prompt_tokens" : 128000 ,
"prompt" : "4.00" ,
"completion" : "16.00"
}
]
}
⌄ 顯示全部 15 行可用模型 (201) 以下是目前 BazaarLink 上可用的模型,從資料庫動態載入:
Qwen
qwen/qwen3.8-max1000K ctx · $1.32/$3.96 text+image+video->text
qwen/qwen4-max1000K ctx · $1.41/$4.24 text+image+video->text
qwen/qwen3.7-plus1000K ctx · $0.26/$1.02 text+image->text
qwen/qwen3.7-max1000K ctx · $1.32/$3.96 text->text
qwen/qwen3.7-flash1000K ctx · $0.03/$0.13 text+image+video->text
qwen/qwen3-embedding-4b33K ctx · $0.02/$0.00 text->embeddings
qwen/qwen3.5-35b-a3b262K ctx · $0.25/$1.00 text+image+video->text
qwen/qwen3.5-27b262K ctx · $0.21/$2.08 text+image+video->text
qwen/qwen3-next-80b-a3b-instruct262K ctx · $0.09/$1.10 text->text
qwen/qwen3.6-35b-a3b262K ctx · $0.30/$1.80 text+image+video->text
qwen/qwen3.5-397b-a17b262K ctx · $0.44/$2.80 text+image+video->text
qwen/qwen3.6-plus1000K ctx · $0.26/$1.56 text+image+video->text
qwen/qwen3-coder-flash1000K ctx · $0.24/$1.20 text->text
qwen/qwen3-vl-235b-a22b-instruct262K ctx · $0.20/$0.88 text+image->text
qwen/qwen3.5-122b-a10b262K ctx · $0.32/$2.56 text+image+video->text
qwen/qwen3.6-27b262K ctx · $0.48/$2.88 text+image+video->text
qwen/qwen3.8-27b1024K ctx · $0.40/$2.40 text+image+video->text
qwen/qwen3.8-2.4t-a95b1049K ctx · $1.60/$4.80 text->text
qwen/qwen3.8-27b-abliterated33K ctx · $2.40/$18.00 text->text
qwen/qwen3-embedding-8b33K ctx · $0.01/$0.00 text->embeddings
qwen/qwen3-embedding-0.6b33K ctx · $0.07/$0.00 text->embeddings
qwen/qwen3.5-flash-02-231000K ctx · $0.07/$0.26 text+image+video->text
qwen/qwen3-coder-30b-a3b-instruct262K ctx · $0.07/$0.28 text->text
qwen/qwen3-coder-next262K ctx · $0.12/$0.80 text->text
qwen/qwen3-vl-30b-a3b-instruct262K ctx · $0.15/$0.60 text+image->text
qwen/qwen3.5-plus-02-151000K ctx · $0.26/$1.56 text+image+video->text
qwen/qwen3.5-plus-202604201000K ctx · $0.30/$1.80 text+image+video->text
qwen/qwen3-coder262K ctx · $0.30/$1.00 text->text
qwen/qwen-2.5-72b-instruct33K ctx · $0.36/$0.40 text->text
qwen/qwen-image-3-pro · $0.00/$0.00 text+image->image
qwen/qwen-image-3 · $0.00/$0.00 text+image->image
OpenAI
openai/gpt-5.3-codex400K ctx · $1.75/$14.00 text->text
openai/gpt-oss-120b131K ctx · $0.15/$0.60 text->text
openai/gpt-oss-safeguard-20b131K ctx · $0.07/$0.30 text->text
openai/gpt-6-luna1050K ctx · $0.09/$0.45 text+image+file->text
openai/gpt-5.6-luna1050K ctx · $0.18/$1.08 text+image+file->text
openai/gpt-5.4-mini400K ctx · $0.68/$4.05 text+image+file->text
openai/gpt-6.2-sol1050K ctx · $2.00/$10.00 text+image+file->text
openai/gpt-5.6-terra1050K ctx · $1.80/$10.80 text+image+file->text
openai/gpt-6.1-sol1050K ctx · $2.00/$10.00 text+image+file->text
openai/gpt-6-sol1050K ctx · $1.80/$9.00 text+image+file->text
openai/gpt-5.41050K ctx · $2.25/$13.50 text+image+file->text
openai/gpt-4o128K ctx · $2.25/$9.00 text+image+file->text
openai/gpt-5.6-sol1050K ctx · $4.50/$27.00 text+image+file->text
openai/gpt-5.51050K ctx · $5.00/$30.00 text+image+file->text
openai/gpt-6.2-astra1050K ctx · $8.00/$40.00 text+image+file->text
openai/gpt-6-astra1050K ctx · $9.00/$45.00 text+image+file->text
openai/gpt-transcribe · $0.00/$0.00 audio->transcription
openai/whisper-1 · $0.00/$0.00 audio->transcription
openai/text-embedding-3-small8K ctx · $0.02/$0.00 text->embeddings
openai/gpt-oss-20b131K ctx · $0.03/$0.13 text->text
openai/text-embedding-ada-0028K ctx · $0.10/$0.00 text->embeddings
openai/text-embedding-3-large · $0.13/$0.00 text->embeddings
openai/gpt-4o-mini-transcribe · $1.25/$5.00 audio->transcription
openai/gpt-4o-transcribe · $2.50/$10.00 audio->transcription
openai/gpt-image-1-mini400K ctx · $2.00/$8.00 text+image->image
openai/gpt-image-2.6-flare400K ctx · $8.00/$8.00 text+image->image
openai/gpt-image-2.6-sunburst400K ctx · $8.00/$8.00 text+image->image
openai/gpt-5.4-image-2272K ctx · $8.00/$15.00 text+image+file->text+image
openai/gpt-image-2.5-sunburst400K ctx · $5.00/$30.00 text+image->image
openai/gpt-image-2.5-flare400K ctx · $5.00/$30.00 text+image->image
openai/gpt-image-1400K ctx · $10.00/$10.00 text+image->image
Google
google/gemini-4-hydrogen1000K ctx · $1.50/$7.50 text+image+file+audio+video->text
google/gemini-4-argon1049K ctx · $2.00/$10.00 text+image+file+audio+video->text
google/gemini-4-carbon1049K ctx · $2.00/$10.00 text+image+file+audio+video->text
google/gemini-3.1-flash-lite-preview1049K ctx · $0.25/$1.50 text+image+file+audio+video->text
google/gemini-3.1-pro-preview1049K ctx · $1.80/$10.80 text+image+file+audio+video->text
google/veo-3.1 · $0.00/$0.00 text+image->video
google/gemma-3-4b-it131K ctx · $0.05/$0.10 text+image->text
google/gemini-3.1-flash-lite1049K ctx · $0.25/$1.50 text+image+file+audio+video->text
google/gemini-3.5-flash-lite1049K ctx · $0.27/$2.25 text+image+file+audio+video->text
google/gemini-3-flash-preview1049K ctx · $0.45/$2.70 text+image+file+audio+video->text
google/gemini-3.6-flash1049K ctx · $0.68/$3.38 text+image+file+audio+video->text
google/gemini-3.7-flash1049K ctx · $0.75/$3.75 text+image+file+audio+video->text
google/gemini-3.8-flash1049K ctx · $0.75/$3.75 text+image+file+audio+video->text
google/gemini-3.5-flash1049K ctx · $1.35/$8.10 text+image+file+audio+video->text
google/gemini-4-neon1000K ctx · $3.00/$15.00 text+image+file+audio+video->text
google/text-multilingual-embedding-0022K ctx · $0.03/$0.00 text->embeddings
google/text-embedding-0052K ctx · $0.15/$0.00 text->embeddings
google/gemma-4-31b-it262K ctx · $0.09/$0.34 text+image+video->text
google/gemini-embedding-00120K ctx · $0.15/$0.00 text->embeddings
google/gemma-4-26b-a4b-it262K ctx · $0.09/$0.34 text+image+video->text
google/gemini-2.5-flash-image33K ctx · $0.30/$2.50 text+image->text+image
google/gemini-3.1-flash-image-preview66K ctx · $0.50/$3.00 text+image->text+image
google/gemini-3.1-flash-image131K ctx · $0.50/$3.00 text+image->text+image
google/gemini-3-pro-image131K ctx · $2.00/$12.00 text+image->text+image
google/gemini-omni-1.2-flash · $0.00/$0.00 text+image+video->text+video
google/gemini-embedding-2-preview8K ctx · $0.20/$0.00 text+image+file+audio+video->embeddings
google/gemini-nano-banana-2.166K ctx · $1.50/$7.50 text+image->text+image
Anthropic
anthropic/claude-sonnet-4.61000K ctx · $3.00/$15.00 text+image+file->text
anthropic/claude-opus-4.61000K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-haiku-5.51000K ctx · $0.10/$0.50 text+image+file->text
anthropic/claude-haiku-4.5200K ctx · $1.00/$5.00 text+image+file->text
anthropic/claude-sonnet-5.51000K ctx · $2.00/$10.00 text+image+file->text
anthropic/claude-sonnet-51000K ctx · $2.00/$10.00 text+image+file->text
anthropic/claude-opus-5.51000K ctx · $4.00/$20.00 text+image+file->text
anthropic/claude-opus-4.5200K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-opus-51000K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-opus-4.71000K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-opus-4.81000K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-fable-51000K ctx · $10.00/$50.00 text+image+file->text
anthropic/claude-fable-5.11000K ctx · $10.00/$50.00 text+image+file->text
anthropic/claude-sonnet-4.51000K ctx · $3.00/$15.00 text+image+file->text
anthropic/claude-fable-5.21000K ctx · $8.00/$40.00 text+image+file->text
anthropic/claude-opus-4.1200K ctx · $15.00/$75.00 text+image+file->text
DeepSeek
deepseek/deepseek-v4.1-flash-10171049K ctx · $0.21/$0.85 text+image->text
deepseek/deepseek-v4.1-flash-1017-abliterated1049K ctx · $0.24/$0.90 text->text
deepseek/deepseek-v4-pro1049K ctx · $1.65/$3.30 text->text
deepseek/deepseek-v4-flash1000K ctx · $0.14/$0.28 text->text
deepseek/deepseek-v4.1-flash1049K ctx · $0.21/$0.85 text+image->text
deepseek/deepseek-v4-flash-07311049K ctx · $0.44/$1.32 text->text
deepseek/deepseek-chat-v3.1164K ctx · $0.21/$0.79 text->text
deepseek/deepseek-chat164K ctx · $0.26/$0.38 text->text
deepseek/deepseek-r164K ctx · $0.50/$2.15 text->text
deepseek/deepseek-r1-0528164K ctx · $0.50/$2.15 text->text
deepseek/deepseek-v4-pro-08131049K ctx · $0.89/$2.67 text->text
deepseek/deepseek-v4-flash-0731free1049K ctx · $0.20/$0.40 text->text
Zhipu AI
z-ai/glm-5.3-flash-abliterated1049K ctx · $0.24/$1.00 text->text
z-ai/glm-5.3-abliterated1049K ctx · $2.00/$4.00 text->text
z-ai/glm-5v-turbo203K ctx · $1.20/$4.00 text+image+video->text
z-ai/glm-4.7-flash200K ctx · $0.06/$0.40 text->text
z-ai/glm-5.3-flash1049K ctx · $0.15/$0.50 text+image+video->text
z-ai/glm-4.5-air131K ctx · $0.13/$0.85 text->text
z-ai/glm-4.6v131K ctx · $0.30/$0.90 text+image+video->text
z-ai/glm-5.3-flashx1049K ctx · $0.37/$1.25 text+image+video->text
z-ai/glm-4.6205K ctx · $0.60/$2.20 text->text
z-ai/glm-4.5131K ctx · $0.60/$2.20 text->text
z-ai/glm-4.5v66K ctx · $0.60/$1.80 text+image->text
z-ai/glm-5.31049K ctx · $1.02/$3.96 text->text
Elevenlabs
elevenlabs/scribe-v2 · $0.00/$0.00 audio->transcription
elevenlabs/eleven-v3 · $0.00/$0.00 text->speech
elevenlabs/eleven-v3-conversational · $0.00/$0.00 text->speech
elevenlabs/eleven-flash-v2 · $0.00/$0.00 text->speech
elevenlabs/eleven-v4 · $0.00/$0.00 text->speech
elevenlabs/eleven-v4-turbo · $0.00/$0.00 text->speech
elevenlabs/eleven-flash-v2.5 · $0.00/$0.00 text->speech
elevenlabs/eleven-multilingual-v2 · $0.00/$0.00 text->speech
elevenlabs/eleven-turbo-v2.5 · $0.00/$0.00 text->speech
elevenlabs/scribe-v2-medical · $0.00/$0.00 audio->transcription
elevenlabs/eleven-turbo-v2 · $0.00/$0.00 text->speech
Voyage
voyage/voyage-3.5-lite32K ctx · $0.02/$0.00 text->embeddings
voyage/voyage-4-lite32K ctx · $0.02/$0.00 text->embeddings
voyage/voyage-3.532K ctx · $0.06/$0.00 text->embeddings
voyage/voyage-432K ctx · $0.06/$0.00 text->embeddings
voyage/voyage-4-large32K ctx · $0.12/$0.00 text->embeddings
voyage/voyage-law-216K ctx · $0.12/$0.00 text->embeddings
voyage/voyage-code-216K ctx · $0.12/$0.00 text->embeddings
voyage/voyage-finance-232K ctx · $0.12/$0.00 text->embeddings
voyage/voyage-code-332K ctx · $0.18/$0.00 text->embeddings
voyage/voyage-3-large32K ctx · $0.18/$0.00 text->embeddings
xAI
x-ai/grok-imagine-video · $0.00/$0.00 text+image->video
x-ai/grok-imagine-video-1.5 · $0.00/$0.00 text+image->video
x-ai/grok-4.31000K ctx · $1.13/$2.25 text+image+file->text
x-ai/grok-4.5500K ctx · $1.80/$5.40 text+image+file->text
x-ai/grok-4.6500K ctx · $1.80/$5.40 text+image+file->text
x-ai/grok-4.7500K ctx · $2.00/$6.00 text+image->text
x-ai/grok-4.202000K ctx · $1.25/$2.50 text+image+file->text
x-ai/grok-imagine-image-2.0 · $0.00/$0.00 text+image->image
x-ai/grok-imagine-video-1.5-lite · $0.00/$0.00 text+image->video
Klingai
klingai/kling-v3.0-t2v-std · $0.00/$0.00 text->video
klingai/kling-v3.0-i2v-std · $0.00/$0.00 text+image->video
klingai/kling-v2.5-turbo-t2v-std · $0.00/$0.00 text->video
klingai/kling-v3.0-t2v · $0.00/$0.00 text->video
klingai/kling-v2.6-i2v · $0.00/$0.00 text+image->video
klingai/kling-v2.5-turbo-i2v-std · $0.00/$0.00 text+image->video
klingai/kling-v2.6-t2v · $0.00/$0.00 text->video
klingai/kling-v2.6-t2v-std · $0.00/$0.00 text->video
ByteDance
bytedance/seedance-2.5 · $0.00/$0.00 text+image->video
bytedance/seedance-2.0 · $0.00/$0.00 text+image->video
bytedance/seedance-2.0-mini · $0.00/$0.00 text+image->video
bytedance/seedance-2.5-flash · $0.00/$0.00 text+image->video
bytedance/seedance-2.0-fast · $0.00/$0.00 text+image+audio+video->video
MiniMax
minimax/minimax-m31049K ctx · $0.30/$1.20 text+image+video->text
minimax/minimax-h3 · $0.00/$0.00 text+image->video
minimax/hailuo-3-max · $0.00/$0.00 text+image->video
Moonshot AI
moonshotai/kimi-k31049K ctx · $2.83/$14.13 text+image+video->text
moonshotai/kimi-k2-0905262K ctx · $0.60/$2.50 text->text
moonshotai/kimi-k3.1-pro1049K ctx · $2.00/$10.00 text+image+video->text
Cohere
cohere/rerank-4-fast33K ctx · $0.00/$0.00 text->rerank
cohere/rerank-4-pro33K ctx · $0.00/$0.00 text->rerank
cohere/rerank-v3.54K ctx · $0.00/$0.00 text->rerank
Alibaba
alibaba/wan3.0 · $0.00/$0.00 text+image->video
alibaba/wan3.0-prime · $0.00/$0.00 text+image->video
Xiaomi
xiaomi/mimo-v2.6-flash1049K ctx · $0.14/$0.28 text+image+video+audio->text
xiaomi/mimo-v2.6-pro1049K ctx · $0.43/$0.87 text+image+video+audio->text
Perplexity
perplexity/pplx-embed-v1-0.6b32K ctx · $0.00/$0.00 text->embeddings
perplexity/pplx-embed-v1-4b32K ctx · $0.03/$0.00 text->embeddings
Mistral
mistralai/mistral-embed-23128K ctx · $0.10/$0.00 text->embeddings
mistralai/codestral-embed-25058K ctx · $0.15/$0.00 text->embeddings
ByteDance Seed
bytedance-seed/seed-2.0-mini262K ctx · $0.10/$0.40 text+image+video->text
bytedance-seed/seed-2.0-lite262K ctx · $0.25/$2.00 text+image+video->text
Cloudflare
cloudflare/clef-flash25K ctx · $0.09/$0.00 text+image->decisions
cloudflare/clef66K ctx · $0.24/$0.00 text+image->decisions
Tencent
tencent/hy4-flash1049K ctx · $0.07/$0.28 text+image->text
NVIDIA
nvidia/nemotron-3.5-lightning-free1000K ctx · $0.00/$0.00 text->text
Stealth
stealth/glyph-cluster256K ctx · $0.00/$0.00 text->text
Reflection AI
reflection/beam1049K ctx · $0.25/$1.00 text->text
inclusionAI
inclusionai/ling-3.1-flash-10191000K ctx · $0.30/$0.90 text->text
Meta
meta/muse-wonder1049K ctx · $4.00/$20.00 text+image+file->text
Amazon
amazon/titan-embed-text-v28K ctx · $0.02/$0.00 text->embeddings
Typesafe Ai
typesafe-ai/jev32K ctx · $0.04/$0.00 text->decisions
在 模型頁面 瀏覽所有模型。
結構化評估(Jev) Jev 會根據 JSON 狀態回答具名問題,並回傳 boolean、choice 或 score 類型的答案;適合將明確判準轉成程式可讀的評估結果。
僅供評估與判斷
Jev 不支援聊天。請將 Jev 請求送至 POST /v1/evaluations;若送至 POST /v1/chat/completions,會收到 HTTP 400。
POST /v1/evaluations
使用 BazaarLink API 金鑰呼叫以下端點。完整網址為 https://api.bazaarlink.ai/v1/evaluations。
欄位說明 model
string
選用。省略時預設為 typesafe-ai/jev;其他模型識別值會回傳 HTTP 400,錯誤代碼為 model_not_available。
state
string | object | array
必填,須為 JSON 字串、物件或陣列,作為待評估的狀態資料。序列化後的 state 與 questions 合計超過 32,000 tokens 時,會回傳 context_length_exceeded。
questions
record<string, Question>
必填,至少包含一個具名問題的物件。每個問題名稱會成為回應 answers 物件中的鍵。
type
boolean | choice | score
每個問題皆必填;可用 boolean、choice 或 score。
instructions
string | object | array
每個問題皆必填;可使用 JSON 字串、物件或陣列,描述要判斷的內容。
criteria
object | array
依 type 決定:boolean 可省略,若提供則為鍵名只能是 true 或 false 的物件;choice 必須是非空物件;score 必須是至少含兩項且順序有意義的陣列。
答案類型 boolean — criteria 可省略;如有提供,只接受 true 與 false 作為鍵。boolean 答案包含數值型的 probability。choice — criteria 必須是非空物件,以選項名稱對應 JSON criteria。答案包含字串 choice;probabilities 以選項名稱為鍵。score — criteria 必須是至少含兩項的有序陣列。答案包含數值 score;score 是依 criteria 陣列順序、在索引 0..N-1 上的期望值;probabilities 以相同索引的字串形式作為鍵。請求範例 cURL Python TypeScript
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
curl --fail-with-body https://api.bazaarlink.ai/v1/evaluations \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "typesafe-ai/jev",
"state": "The support agent issued a full refund and apologised for the delay.",
"questions": {
"refunded": {
"type": "boolean",
"instructions": "Was a refund issued?"
},
"tone": {
"type": "choice",
"instructions": "Tone of the agent?",
"criteria": {
"apologetic": "The agent apologises",
"neutral": "No emotional language",
"hostile": "The agent is rude"
}
},
"quality": {
"type": "score",
"instructions": "How complete was the resolution?",
"criteria": [
"poor",
"partial",
"complete"
]
}
}
}'
⌄ 顯示全部 31 行成功回應範例 範例回應包含 id、object、model、answers、usage、rounding 和 warnings。answers 以問題名稱為鍵。usage 包含 input_tokens、output_tokens 和 total_tokens;rounding 顯示 probabilityDecimals 和 scoreDecimals。warnings 是陣列,本例為空。answers 中的 choice probabilities 以選項名稱為鍵,score probabilities 則以 criteria 項目的索引字串為鍵。
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
{
"id" : "eval-a3d350e5-2705-4a9b-be7c-838fa4e4eb2b" ,
"object" : "evaluation" ,
"model" : "typesafe-ai/jev" ,
"answers" : {
"refunded" : {
"type" : "boolean" ,
"probability" : 0.99
} ,
"tone" : {
"type" : "choice" ,
"choice" : "apologetic" ,
"probabilities" : {
"apologetic" : 1 ,
"neutral" : 0 ,
"hostile" : 0
}
} ,
"quality" : {
"type" : "score" ,
"score" : 1.98 ,
"probabilities" : {
"0" : 0 ,
"1" : 0.02 ,
"2" : 0.98
}
}
} ,
"usage" : {
"input_tokens" : 394 ,
"output_tokens" : 74 ,
"total_tokens" : 468
} ,
"rounding" : {
"probabilityDecimals" : 2 ,
"scoreDecimals" : 2
} ,
"warnings" : [ ]
}
⌄ 顯示全部 39 行聊天端點的錯誤回應 將 Jev 傳給聊天端點會收到 HTTP 400。以下欄位和值符合端點處理程式;message 以佔位文字表示,實際文字由伺服器提供。
{
"error" : {
"message" : "<server-generated message>" ,
"type" : "invalid_request_error" ,
"code" : 400
}
} 串流 設定 stream: true 以接收 Server-Sent Events (SSE) 串流。每個事件包含一個回應片段。
Python cURL TypeScript fetch (SSE)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from openai import OpenAI
client = OpenAI(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY" ,
)
stream = client.chat.completions.create(
model="anthropic/claude-sonnet-4.6" ,
messages=[{"role" : "user" , "content" : "Count to 10 slowly." }],
stream=True ,
)
for chunk in stream:
content = chunk.choices[0 ].delta.content
if content:
print (content, end="" , flush=True )
⌄ 顯示全部 17 行SSE 格式 data: {"id" :"85e6f35c71a31f19-SJC" ,"choices" :[{"delta" :{"content" :"Hello" },"index" :0}]}
data: {"id" :"85e6f35c71a31f19-SJC" ,"choices" :[{"delta" :{"content" :" world" },"index" :0}]}
data: {"id" :"85e6f35c71a31f19-SJC" ,"choices" :[{"delta" :{},"finish_reason" :"stop" ,"index" :0}],"usage" :{"prompt_tokens" :10,"completion_tokens" :4,"total_tokens" :14}}
data: [DONE]串流中的使用量
串流時,使用量資料會在 [DONE] 訊息之前的最後一個區塊中返回,該區塊的 choices 陣列帶有一個空 delta 與 finish_reason: "stop"。
Keep-alive 與收尾行為 串流可能包含 SSE 註解列及未知或 ping keep-alive 事件;請忽略這些內容並解析 data frame。最後一個 data frame 可能在 data: [DONE] 前帶有 usage。
: keepalive <- SSE comment line — ignore, do NOT JSON.parse
data: {"id" :"85e6f35c71a31f19-SJC" ,"choices" :[{"delta" :{"content" :"Hi" },"index" :0}]}
data: {"id" :"85e6f35c71a31f19-SJC" ,"choices" :[{"delta" :{},"finish_reason" :"stop" ,"index" :0}],"usage" :{...}}
data: [DONE]串流取消 串流請求可透過關閉客戶端連線來取消 — 例如呼叫 AbortController.abort() 或關閉 stream 物件。BazaarLink 收到取消訊號後會立刻停止轉發後續內容,並中止對上游供應商的請求。
TypeScript Python
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
import OpenAI from "openai" ;
const client = new OpenAI ({
baseURL : "https://api.bazaarlink.ai/v1" ,
apiKey : "sk-bl-YOUR_API_KEY" ,
});
const controller = new AbortController ();
const stream = await client.chat .completions .create (
{
model : "anthropic/claude-sonnet-4.6" ,
messages : [{ role : "user" , content : "Write a long story." }],
stream : true ,
},
{ signal : controller.signal }
);
for await (const chunk of stream) {
const content = chunk.choices [0 ]?.delta ?.content ;
if (content) process.stdout .write (content);
}
controller.abort ();
⌄ 顯示全部 25 行被中斷的串流如何計費
串流在完成前由你的客戶端取消(例如呼叫 AbortController.abort())時,若模型服務提供者已處理該請求,BazaarLink 會依其回報的用量計費;無法取得回報用量時,依輸入內容及取消前已送達你客戶端的輸出內容估算計費。實際金額以「日誌」中該筆請求的 usage.cost 為準。
不保證上游立即停止
關閉連線會讓 BazaarLink 立刻停止轉發後續內容,但模型服務提供者是否立即停止生成,取決於提供者本身;若提供者回報了斷線後才產生的用量,該用量也會依上述方式計費。
串流中途出錯 錯誤幀沒有 choices 欄位
如果串流已經開始後才發生失敗(例如上游連線中斷),您會收到一個 {error:{message,type,code}} 形狀的 SSE 資料幀,而不是平常的 {choices:[...]} —— HTTP 狀態不會改變,因為 header 早就送出了。讀取 choices[0].delta 前請先檢查是否有 error 欄位;計費只會算到已經串流出去的 token(適用部分計費)。
data: {"id" :"85e6f35c71a31f19-SJC" ,"choices" :[{"delta" :{"content" :"The capital of " },"index" :0}]}
data: {"error" :{"message" :"The request could not be completed." ,"type" :"upstream_error" ,"code" :502}}
data: [DONE]嵌入向量 嵌入向量(Embeddings)是能捕捉語意的數值表示法——把文字轉換成向量(一串數字),可用於各種機器學習任務。BazaarLink 提供與 OpenAI Embeddings API 相容的統一端點,讓您透過同一組介面呼叫多家供應商的嵌入模型。
Embedding 回應使用不透明的 BazaarLink 請求 ID,與 x-request-id 相同;可搭配 GET /v1/generation 使用。非串流回應也會在 x-generation-id 回傳同一個 ID。usage.cost 是此請求向客戶收取的美元金額。統計資料可能在完成後數秒才可用;若收到 404,請稍後短暫重試。
什麼是嵌入向量? 嵌入向量把文字轉換成高維度向量,語意相近的文字在向量空間裡的距離也會更接近——例如「貓」與「小貓」的嵌入會很相似,但「貓」與「飛機」會相距很遠。這種向量表示法讓機器能夠理解文字之間的關聯,是許多 AI 應用的基礎。
常見應用場景 RAG(檢索增強生成) 打造能在生成答案前,先從知識庫中檢索相關內容的系統——嵌入向量能找出最相關的文件,放進 LLM 的上下文。
語意搜尋 把文件和查詢都轉成嵌入向量,再用向量相似度找出最相關的文件——比單純比對關鍵字更能理解語意、效果更好。
推薦系統 為商品、文章、影片等項目與使用者偏好產生嵌入向量,藉由向量比對推薦相近項目——即使沒有共同關鍵字也能找到語意相關的內容。
分群與分類 透過分析嵌入向量的模式,把相似的文件分群或分類——嵌入向量相近的文件通常屬於相同主題或類別。
重複內容偵測 透過比對嵌入向量的相似度找出重複或近似重複的內容——即使內容經過改寫或換句話說也能偵測到。
異常偵測 找出嵌入向量明顯偏離資料集一般模式的內容,藉此辨識異常或離群的內容。
POST /v1/embeddings
Note
若上游來源不支援所需的嵌入模型,請求可以改試其他可用來源;若沒有來源支援該模型,請求會回傳錯誤。
參數 model必填
string
要使用的嵌入模型,例如 "openai/text-embedding-3-small"。
input必填
string | string[] | ContentItem[]
要嵌入的文字 —— 可為單一字串、一次批次呼叫用的字串陣列,或(支援的模型)混合 text 與 image_url 部分的 {content:[...]} 項目陣列。
dimensions
integer
要求的輸出向量維度。只有支援可變維度的模型才會採用(例如 OpenAI text-embedding-3 系列);原樣轉發給上游供應商,不支援的模型會忽略此參數。
encoding_format
string
要求的嵌入編碼格式,例如 "float" 或 "base64"。原樣轉發給上游供應商 —— 是否支援視模型而定。
provider
object
Unsupported. The entire object is ignored and removed before forwarding; it cannot select an upstream or price tier.
基本請求 Python cURL TypeScript
from openai import OpenAI
client = OpenAI(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY" ,
)
response = client.embeddings.create(
model="openai/text-embedding-3-small" ,
input ="The quick brown fox jumps over the lazy dog" ,
)
print (response.data[0 ].embedding)
⌄ 顯示全部 13 行批次處理 傳送字串陣列,可在單一請求中嵌入多筆文字 —— 比逐筆呼叫更便宜也更快。
Python cURL TypeScript
response = client.embeddings.create(
model="openai/text-embedding-3-small" ,
input =[
"Machine learning is a subset of artificial intelligence" ,
"Deep learning uses neural networks with multiple layers" ,
"Natural language processing enables computers to understand text" ,
],
)
for i, item in enumerate (response.data):
print (f"Embedding {i} : {len (item.embedding)} dimensions" )
⌄ 顯示全部 11 行多模態輸入(圖片+文字) 支援圖片輸入的模型(output_modalities 含 "embeddings"、inputModalities 含 "image")接受 {content:[{type:"text",...}, {type:"image_url",...}]} 形式的輸入項目,讓您可以單獨嵌入圖片,或圖片與文字一起嵌入。
視模型而定
只有部分嵌入模型接受圖片輸入 —— 傳送 image_url 內容前,請先到 Models 頁面確認該模型支援的模態。純文字模型會拒絕這種格式。
Python cURL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import requests
response = requests.post(
"https://api.bazaarlink.ai/v1/embeddings" ,
headers={
"Authorization" : "Bearer sk-bl-YOUR_API_KEY" ,
"Content-Type" : "application/json" ,
},
json={
"model" : "google/gemini-embedding-2-preview" ,
"input" : [{
"content" : [
{"type" : "text" , "text" : "A scenic boardwalk through a green meadow" },
{"type" : "image_url" , "image_url" : {"url" : "https://example.com/boardwalk.jpg" }},
]
}],
"encoding_format" : "float" ,
},
)
embedding = response.json()["data" ][0 ]["embedding" ]
print (f"Embedding dimension: {len (embedding)} " )
⌄ 顯示全部 22 行尋找嵌入模型 沒有專屬的嵌入模型清單端點 —— 呼叫 GET /v1/models,在前端篩選 output_modalities 包含 "embeddings" 的項目,或直接到 Models 頁面瀏覽。
限制 不支援串流 —— 與 chat completions 不同,嵌入向量一律以完整回應形式回傳。 每個模型都有輸入長度上限;超過上限的文字會在上游被截斷或拒絕。 相同輸入的嵌入結果是確定性的(deterministic)—— 不涉及 temperature 或隨機性。 最佳實務 依速度/品質/成本的取捨選擇模型 —— 較小的模型(如 qwen/qwen3-embedding-4b)較便宜也較快;較大的模型(如 openai/text-embedding-3-large)通常嵌入精準度較高。 把多筆文字合併成一次請求,而不是逐筆呼叫 —— 減少往返次數與額外開銷。 快取結果 —— 相同輸入的嵌入結果永遠不變,應該儲存起來而非重新產生。 比對時用餘弦相似度(cosine similarity),不要用歐氏距離 —— 具尺度不變性,對高維向量效果更好。 留意每個模型的上下文長度 —— 長文件在嵌入前可能需要先分段(chunking)。 專用參數 取樣參數影響 token 產生過程。BazaarLink 會將支援的參數傳遞給上游 provider;不支援的參數會被静默忽略。
取樣參數 純轉發——沒有本地預設值
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
temperature
number
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
top_k
integer
取樣參數會轉送且不做範圍驗證;模型可能自行限制或忽略超出支援範圍的值。
frequency_penalty
number
懲罰重複的 token。範圍:[-2, 2]。預設:0
presence_penalty
number
基於存在情況懲罰 token。範圍:[-2, 2]。預設:0
repetition_penalty
number
降低輸入中 token 重複的機率。範圍:(0, 2]。預設:1
min_p
number
相對最高機率 token 的最低入選機率。範圍:[0, 1]。預設:0
top_a
number
基於最高機率 token 的動態 Top-P。範圍:[0, 1]。預設:0
seed
integer
整數隨機種子,用於確定性取樣。部分模型不保證
max_tokens
integer
要生成的最大 token 數量
logit_bias
object
將 token ID 映射到偏差値 [-100, 100],在取樣前加到機率。僅限 OpenAI 系列模型 —— 見下方說明。
logprobs
boolean
回傳每個輸出 token 的對數機率。僅限 OpenAI 系列模型 —— 見下方說明。
top_logprobs
integer
每個位置回傳概率最高的 N 個候選 token(需配合 logprobs: true)。範圍:0–20。僅限 OpenAI 系列模型 —— 見下方說明。
response_format
object
強制結構化 JSON 輸出。請參閱結構化輸出章節
structured_outputs
boolean
在支援的 provider 上要求嚴格符合 JSON schema 的輸出。原樣轉發
reasoning
object
Provider 專屬的 reasoning/thinking 設定。原樣轉發
reasoning_effort
string
OpenAI o 系列風格的 reasoning 強度:"low"、"medium" 或 "high"。原樣轉發
include_reasoning
boolean
true 時在 message.reasoning(串流為 delta.reasoning)回傳思考內容;false 則為預設會思考的模型關閉思考(見推理章節),因此不會計思考費用。沒有帶 reasoning_effort、reasoning 或 thinking 時,只有那些模型會預設思考並回傳;其他模型要帶參數才會回傳
stop
string | string[]
停止序列 — 遇到時停止生成
tools
Tool[]
模型可以呼叫的工具(函式)列表
tool_choice
string | object
控制工具使用:"auto"、"none" 或指定工具
parallel_tool_calls
boolean
啟用並行工具呼叫功能。預設:true。僅限 OpenAI 系列模型 —— 見下方說明。
黏地板路由(provider.sticky) provider.sticky
boolean
boolean,預設 true。使用 :floor 模型時,選定最便宜的主機後會持續送往同一台,讓提示快取持續有效。把 provider.sticky 設為 false,則每次請求都重新挑選最便宜的主機。 「同一段對話固定在同一台主機」目前只在測試環境驗證過,正式站的流量驗證尚未完成。
請求範例(每次重新挑最便宜的主機)
curl https://bazaarlink.ai/api/v1/chat/completions \
-H "Authorization: Bearer $BAZAARLINK_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4-flash:floor",
"messages": [{ "role": "user", "content": "Hello" }],
"provider": { "sticky": false }
}'
⌄ 顯示全部 8 行信用額度 查詢當前信用額度餘額與累積 API 使用量。
GET /v1/credits
Auth
需要 Bearer token(標準 API key sk-bl-...)。
範例請求 cURL Python
curl https://api.bazaarlink.ai/v1/credits \
-H "Authorization: Bearer sk-bl-YOUR_KEY" 回應 {
"data" : {
"total_credits" : 100.00 ,
"total_usage" : 12.34
}
} 錯誤:401(金鑰無效或遺失)、403(帳號已停權)。
生成詳細資料 使用回應 id 或 x-request-id 標頭中的不透明 BazaarLink 請求 ID 呼叫 GET /v1/generation;非串流回應也會在 x-generation-id 提供此 ID。統計資料可能延遲數秒;若收到 404,請短暫重試。
GET /v1/generation?id=<generation-id>
Auth
需要 Bearer token(標準 API key)。必填 query 參數:id。
範例請求 curl "https://api.bazaarlink.ai/v1/generation?id=BAZAARLINK_REQUEST_ID" \
-H "Authorization: Bearer sk-bl-YOUR_KEY" 回應 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
{
"data" : {
"id" : "85e6f35c71a31f19-SJC" ,
"model" : "openai/gpt-4o" ,
"provider" : "bazaarlink" ,
"created_at" : "2026-04-20T10:00:00.000Z" ,
"app_name" : "MyApp" ,
"finish_reason" : "stop" ,
"status" : 200 ,
"duration_ms" : 1234 ,
"first_token_ms" : 234 ,
"throughput" : 45.6 ,
"usage" : {
"prompt_tokens" : 100 ,
"completion_tokens" : 200 ,
"total_tokens" : 300 ,
"prompt_tokens_details" : { "cached_tokens" : 50 } ,
"completion_tokens_details" : { "reasoning_tokens" : 30 } ,
"cost" : 0.00123
} ,
"cost_breakdown" : {
"subtotal" : 0.00123 ,
"cache_discount" : 0.00015 ,
"total" : 0.00108
}
}
}
⌄ 顯示全部 27 行錯誤:400(缺少 id)、401(auth)、404(找不到該 generation)。
API 金鑰資訊 查詢當前 API key 的 rate limit 層級與累計使用量(回應格式與業界慣用的金鑰查詢 API 相容)。
GET /v1/key
Auth
需要 Bearer token(標準 API key)。
回應 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"data" : {
"label" : "Production Key" ,
"limit" : null ,
"limit_remaining" : 100.00 ,
"limit_reset" : null ,
"expires_at" : null ,
"is_free_tier" : false ,
"is_management_key" : false ,
"is_provisioning_key" : false ,
"usage" : 12.34 ,
"usage_daily" : 0.12 ,
"usage_weekly" : 0.45 ,
"usage_monthly" : 1.23 ,
"requests" : 1234 ,
"requests_daily" : 10 ,
"requests_weekly" : 50 ,
"requests_monthly" : 200 ,
"rate_limit" : { "requests" : 600 , "interval" : "1m" , "note" : "Paid-tier rate limit." }
}
}
⌄ 顯示全部 21 行Note
當信用餘額低於 $10 時,is_free_tier 為 true。統計區間以 UTC 為準:daily = 當日、weekly = 週一至週日、monthly = 當月 1 日至月底。若該 API key 有設定個別用量上限(透過建立/更新 key 時的 limit 參數),limit / limit_remaining / limit_reset 會反映該上限與對應週期的已用量;未設定時 limit 為 null,limit_remaining 退回帳號信用餘額。expires_at 為該 key 的到期時間(未設定則為 null)。is_management_key 與 is_provisioning_key 目前為同一概念的別名,皆表示這是一把管理金鑰。
BYOK
BazaarLink 目前沒有提供「自帶金鑰」(BYOK)方案,因此本端點不會回傳 byok_usage 相關欄位。
錯誤:401(auth)、404(找不到使用者,極少發生)。
錯誤代碼 錯誤回應格式 錯誤 envelope 依端點而異。若有 error.type,請搭配 HTTP 狀態碼判斷;error.code 可能是字串或數字狀態碼,也可能省略;error.message 僅供顯示。
{
"error" : {
"message" : "Insufficient credits. Please top up to continue." ,
"type" : "invalid_request_error" ,
"code" : "insufficient_credits"
}
} HTTP 狀態與 error.code 錯誤 envelope 依端點而異。若有 error.type,請搭配 HTTP 狀態碼判斷;error.code 可能是字串或數字狀態碼,也可能省略;error.message 僅供顯示。
424依賴失敗 您自行設定的 BYOK 金鑰被上游供應商拒絕;請在 BYOK 設定中檢查或輪替。此錯誤只會在 strict 模式出現
400請求無效 請求格式錯誤、messages 陣列為空,或缺少必填欄位
401未授權 API 金鑰遺失、無效或已停用
402需要付款 帳戶點數不足、單一金鑰花費上限已達,或每週 / 每月預算上限已達
403禁止存取 帳戶已停用或沒有此操作的權限
404找不到資源 指定的模型、生成工作、金鑰或其他資源不存在
409狀態衝突 資源尚未進入必要狀態,例如影片工作尚未完成
410資源已移除 指定模型已退役,必須改用其他模型
413請求體過大 請求 body 超過 10 MB;請縮小內容或分拆請求
416範圍無法滿足 生成影片內容所要求的 byte range 無效
429請求過多 已超過速率限制;請查看 Retry-After 標頭後再重試
432免費額度用盡 Tavily 相容端點(/v1/search、/v1/extract、/v1/crawl、/v1/map):免費搜尋額度已用完,或餘額為 0 以下;請儲值後繼續。回應內容為 Tavily 格式:{"detail":{"error":"..."}}
500伺服器錯誤 BazaarLink 內部錯誤
502閘道錯誤 所有上游來源皆無法處理;請求會回傳錯誤。
503服務不可用 此模型沒有設定上游提供者;請聯絡管理員
504閘道逾時 上游連線或串流停滯並超過等待時間
機器可讀的帳務代碼 同樣是 402,也可能代表不同的帳務控制。請依下列穩定代碼顯示正確的處理方式。
byok_key_invalid您自行設定的 BYOK 金鑰被上游供應商拒絕;請在 BYOK 設定中檢查或輪替。此錯誤只會在 strict 模式出現。
budget_cap_reached已達每週或每月的提醒型預算上限;提高或重設預算上限。
credit_limit_exceeded月結組織已用盡硬性信用額度;請聯絡帳務人員。
insufficient_credits預付用戶或組織無法保留足夠餘額;請先加值。
spend_limit_exceededAPI 金鑰已達每日、每週或每月花費上限。
capacity_unavailable此模型暫時容量不足,請稍後重試;Retry-After 標頭會告知等待秒數。
詳細錯誤代碼 API 請求失敗時,error.code 會告訴你更具體的原因。即使兩個錯誤都是 HTTP 400,處理方式也可能不同:例如 unknown_model 表示模型名稱有誤,image_too_large 則表示圖片太大。請依下表找到原因與對應的處理方向。
模型與端點
模型查找、生命週期、定價、模態及端點相容性錯誤。
unknown_model400
invalid_model_id400
model_not_found404
model_retired410
model_endpoint_mismatch400
embedding_on_chat_endpoint400
model_not_priced400
invalid_modality_for_model400
請求與安全
參數、上下文、工具、結構描述及內容安全拒絕。
missing_required_field400
unsupported_param400
max_tokens_invalid400
context_too_long400
tool_use_unsupported400
malformed_tool_messages400
invalid_response_format_schema400
invalid_tools_definition400
content_moderation403
content_filter403
unknown_4xx400
圖片生成與編輯
圖片輸入、multipart 編輯、輸出及圖片管線錯誤。
invalid_image_url400
input_images_not_supported400
invalid_content_type400
mask_not_supported400
unsupported_response_format400
missing_prompt400
missing_image400
too_many_images400
invalid_image_type400
image_too_large400
invalid_n400
pipeline_error502
no_images502
上游路由
經安全處理的供應商連線、驗證、限流及可用性錯誤。
upstream_unreachable502
upstream_auth_failed502
upstream_rate_limited429
capacity_unavailable429
upstream_unavailable502/503
byok_key_invalid424
內容審查 所有請求在送往模型端之前,都會先經過自動化內容審查。不符合使用規範的請求會被拒絕,不會送達模型,並回傳 403 錯誤。
會被攔截的內容類別 審查依據我們的使用規範(Acceptable Use Policy)進行,主要攔截以下類別的內容:
性剝削內容 暴力威脅 違法行為的操作指導 生物危害相關內容 403 回應格式 請求被審查攔截時,會收到以下格式的錯誤回應:
{
"error" : {
"message" : "Your prompt was blocked by content moderation." ,
"type" : "invalid_request_error" ,
"code" : "content_filter"
}
} 被攔截的請求不會計費——你不會為被拒絕的請求付費。
誤判申訴 如果你認為某次請求被誤判攔截,請聯繫支援團隊並附上請求時間與(如方便的話)request id,我們會協助複查。
隱私說明 請求會經過自動化內容審查,最新輸入的文字與圖片可能送交第三方內容安全評分服務。
判定為違規、疑似違規、接近門檻或隨機抽樣的請求,我們可能保存其全文或前段文字,供合規舉證、爭議處理與稽核之用,不承諾固定刪除期限。
其他一般成功請求不保存提示詞與回應內容;使用 ZDR 金鑰的請求不適用前兩項。
速率限制、預算與緊急煞車 這些控制可能拒絕原本有效的請求。它們與供應商錯誤不同,也需要不同的復原方式。
請求速率限制 429字串 code 或數字 code 429;請使用 Retry-After 與 X-RateLimit-* 標頭。
限流懲罰封鎖 429數字 code 429、暫時限制訊息及 Retry-After。
全域支出緊急煞車 503數字 code 503、全域支出上限訊息,以及 30 或 300 秒的 Retry-After。
組織/團隊/成員/使用者支出煞車 429數字 code 429,訊息會指出 spend circuit breaker 及受影響範圍。
帳務與預算控制 402使用上方列出的穩定帳務字串代碼。
錯誤 envelope 依端點而異。若有 error.type,請搭配 HTTP 狀態碼判斷;error.code 可能是字串或數字狀態碼,也可能省略;error.message 僅供顯示。
影片與媒體資源狀態 影片驗證通常回傳數字 code 400;工作不存在為 404、模型退役為 410、影片內容尚未完成為 409、影片 byte range 無效為 416。重試前請先輪詢至完成,或修正 Range 標頭。
重試策略 只有在不修改請求也可能恢復的錯誤才應重試。若有 Retry-After,請依指定秒數等待;否則使用帶 jitter 的指數退避。限制重試次數,也不要同時疊加 SDK 自動重試與手動重試。
可退避重試
429、502、503、504。有 Retry-After 時必須優先遵守。生成類請求若遇到結果不明的網路中斷,應先查詢原工作,避免建立第二個工作。
修正後再重試
400、401、402、403、404、409、410、413、416。請先修正請求、憑證、餘額、權限、資源狀態或 Range 標頭。
錯誤處理 Python TypeScript
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
import random
import time
from openai import OpenAI, APIStatusError
client = OpenAI(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY" ,
max_retries=0 ,
)
RETRYABLE = {429 , 502 , 503 , 504 }
for attempt in range (5 ):
try :
response = client.chat.completions.create(
model="openai/gpt-4o" ,
messages=[{"role" : "user" , "content" : "Hello!" }],
)
break
except APIStatusError as error:
if error.status_code not in RETRYABLE or attempt == 4 :
raise
retry_after = error.response.headers.get("Retry-After" )
delay = (
float (retry_after)
if retry_after
else min (8 , 0.5 * (2 ** attempt)) + random.uniform(0 , 0.25 )
)
time.sleep(delay)
⌄ 顯示全部 29 行串流錯誤格式 在任何 token 串流之前發生的錯誤,會以標準 HTTP 錯誤回應(JSON body)回傳。
串流一旦開始,HTTP 回應已經是 200。用戶端必須解析每個 SSE data frame;只要出現頂層 error,或 choices[0].finish_reason === "error",就應視為失敗且回應不完整。
若串流開始後才失敗,BazaarLink 可能送出最後一個 SSE 事件,內含頂層 error 物件,之後送出 data: [DONE]。請將此回應視為不完整,不要把部分輸出當成完成的結果。
data: {"error":{"message":"The request could not be completed.","type":"upstream_error","code":502}}
data: [DONE]
// Branch on error.code; error.type can vary by failure path.版本管理 BazaarLink 只提供單一穩定的 API 路徑 /v1 —— 沒有依日期釘選的版本、也不需要管理版本 header。API 是持續演進,不是靠編號釋出版本。
非破壞性變更 以下這些會在不事先預告的情況下上線:
新增端點 目錄新增模型 新增選填請求參數 新增回應欄位 新增帶選填屬性的 schema 新增回應狀態/錯誤代碼 用防禦性寫法實作用戶端
請忽略您不認得的回應欄位,也不要在遇到列舉型欄位的未知值時直接失敗 —— 隨著目錄與功能擴充,會持續新增新值。
破壞性變更 這些情況很少見,包含:
刪除或改名端點、參數、或回應欄位 改變欄位型別 把選填參數改成必填 就算真的發生,破壞性變更也只會影響特定端點,不會波及整個 /v1 —— 沒有單一版本升級能一次弄壞所有串接。我們目前還沒有發布正式、帶 Breaking 標籤的 changelog(見下方「掌握最新動態」)—— 若是對您串接來說很關鍵的部分,建議先聯繫 Support 確認,不要依賴沒有文件記載的行為。
下架政策 唯一該預期的常態性「破壞性」事件:個別模型會隨上游供應商淘汰而下架。可透過 GET /v1/models 查詢模型目前的狀態。
GET https://api.bazaarlink.ai/v1/models
Authorization: Bearer sk-bl-YOUR_API_KEY
掌握最新動態 我們目前還沒有發布專屬的 API changelog 或 RSS feed。現階段請直接查看這個頁面、透過 GET /v1/models 追蹤模型狀態,或若您有關鍵串接需要提前得知變更,可聯繫 Support。