API 参考 BazaarLink API 概览
BazaarLink 在不同模型和供应商之间提供统一且兼容 OpenAI 的请求与响应格式。你只需集成一次,即可切换模型,无需重写应用程序。
客户路由字段会被忽略
如果请求包含 provider(整个对象)、transforms、route、顶层 service_tier 或 preset,这些字段会在发送上游前移除,无法选择上游或价格层级。Chat Completions 和 Responses 端点支持 models 数组作为本地备用列表:BazaarLink 会自行路由每个模型,并按该模型的 BazaarLink 客户价格计费;此列表不会转发给上游。客户提供的 :nitro、:floor 和 :exacto 后缀会被忽略;: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 付费注册入口创建账户。
POST https://api.bazaarlink.ai/api/v1/agents/register
未付费注册接受 name、可选的 description 和 referral_code。201 响应包含 API 密钥、额度、7 天 claim token 及到期时间、升级网址、推荐码、free_model auto:free、基础 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 流与混合 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"`)。如果你的客户端读取超时足够长(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 秒才会实际请求上游(避免限流)
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 minimax/hailuo-3-max text+image->video t2v, i2v google/veo-3.1 text+image->video t2v, i2v bytedance/seedance-2.5 text+image+audio+video->video — x-ai/grok-imagine-video-1.5-lite text+image->video t2v, i2v bytedance/seedance-2.0 text+image+audio+video->video t2v, i2v bytedance/seedance-1-5-pro text+image->video t2v, i2v bytedance/seedance-2.0-fast text+image+audio+video->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;请求正文上限 50 MiB,允许 base64。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,并选择支持音频的模型。按配置的输入与输出 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-compatible 接口兼容:发送 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 是 语音模型 ID,例如 elevenlabs/eleven-flash-v2.5。 input string 是 要合成的文字,每次最多 4,096 个字符(elevenlabs/eleven-v4 与 eleven-v4-turbo 为 10,000)。更长的文字请拆成多次请求。 voice string 是 要使用的声音,格式取决于模型。参见下方的声音规则。 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 则更平稳。
声音规则 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-style 声音名称仅适用于列出这些声音的模型。请在模型页查看。
自定义声音(克隆)正在分阶段开放:请见下方“自定义声音”章节(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 保存文件。
计费 语音合成按输入字符数计费。每字符价格见 /models 中的模型页,以及 GET /v1/models 中的 pricing.character。模型页按每百万字符展示。
示例 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;unknown_model(请在 /models 核对 ID)。 401 API 密钥缺失或无效。请通过 Authorization: Bearer 发送 BazaarLink 密钥。 402 余额不足,请充值后重试。 403 管理密钥不能调用模型,或账号已被停用。请使用普通 API 密钥。 429 达到速率限制,请按 Retry-After 响应头等待后重试。 502 模型服务暂时不可用,或音频传输中断。请重试;失败的请求不收费。
完整参数参考: 语音合成
语音转文字(转录)指南 POST /v1/audio/transcriptions 与 OpenAI-compatible 接口兼容:通过 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 是 转录模型 ID,例如 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 密钥缺失或无效。 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 日计)。 账号需已验证邮箱,且余额至少 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(邮箱)。一律返回 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 请先验证邮箱。 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 即将推出 — 通过三个 BazaarLink 端点获取公开的社交和商业数据。此服务默认关闭,启用前请求会返回 service_paused。
提交社交数据请求 POST /v1/data/social
请求参数 代码 类型 必填 含义 platformstring是 目录中的平台 ID,例如 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 行异步任务 仅支持异步的操作或 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 显示每个已启用操作的客户价格。成功调用只计费一次;失败调用和零结果调用免费。Data API 与网页搜索共享每日免费额度。
错误代码 {"error":{"code":"<code>","message":"<fixed message>"}}
代码 HTTP 含义 unauthorized401 API key 缺失或无效。 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 行Submit a decisions request Evaluate a state against named questions with a decisions-output model. This alpha endpoint returns non-streaming JSON. Find available model ids with GET /v1/models?output_modalities=decisions; use this endpoint for Clef instead of chat/completions. Input tokens are billed at the selected model's customer price. Sufficient credits are required. Set BAZAARLINK_API_KEY to your API key; the sample builds its complete Authorization header in BAZAARLINK_AUTH_HEADER.
View the decisions API reference
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 行可用模型 (171) 以下是目前 BazaarLink 上可用的模型,从资料库动态载入:
Qwen
qwen/qwen3.8-max1000K ctx · $1.65/$4.95 text+image+video->text
qwen/qwen3.7-plus1000K ctx · $0.32/$1.28 text+image->text
qwen/qwen3.7-max1000K ctx · $1.65/$4.95 text->text
qwen/qwen3.7-flash1000K ctx · $0.03/$0.13 text+image+video->text
qwen/qwen3.5-35b-a3b262K ctx · $0.31/$1.25 text+image+video->text
qwen/qwen3.5-27b262K ctx · $0.26/$2.60 text+image+video->text
qwen/qwen3-next-80b-a3b-instruct262K ctx · $0.14/$0.57 text->text
qwen/qwen3.5-397b-a17b262K ctx · $0.55/$3.50 text+image+video->text
qwen/qwen3.6-plus1000K ctx · $0.33/$1.95 text+image+video->text
qwen/qwen3-coder-flash1000K ctx · $0.20/$0.97 text->text
qwen/qwen3.5-122b-a10b262K ctx · $0.40/$3.20 text+image+video->text
qwen/qwen3-vl-235b-a22b-instruct262K ctx · $0.20/$0.88 text+image->text
qwen/qwen3.8-27b1000K ctx · $0.50/$3.00 text+image+video->text
qwen/qwen3.8-2.4t-a95b1049K ctx · $2.00/$6.00 text->text
qwen/qwen3-embedding-8b33K ctx · $0.01/$0.00 text->embeddings
qwen/qwen3-embedding-0.6b33K ctx · $0.01/$0.00 text->embeddings
qwen/qwen3-embedding-4b33K ctx · $0.02/$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.6-35b-a3b262K ctx · $0.15/$1.00 text+image+video->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.6-27b262K ctx · $0.29/$2.40 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 · $0.00/$0.00 text+image->image
qwen/qwen-image-3-pro · $0.00/$0.00 text+image->image
Google
google/gemini-4-argon1049K 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 · $2.00/$12.00 text+image+file+audio+video->text
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.30/$2.50 text+image+file+audio+video->text
google/gemini-3-flash-preview1049K ctx · $0.50/$3.00 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.6-flash1049K ctx · $0.75/$3.75 text+image+file+audio+video->text
google/gemini-3.5-flash1049K ctx · $1.50/$9.00 text+image+file+audio+video->text
google/text-embedding-0052K ctx · $0.03/$0.00 text->embeddings
google/text-multilingual-embedding-0022K ctx · $0.03/$0.00 text->embeddings
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/gemma-4-31b-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/veo-3.1 · $0.00/$0.00 text+image->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
OpenAI
openai/gpt-5.3-codex400K ctx · $1.75/$14.00 text->text
openai/gpt-6-luna1050K ctx · $0.10/$0.50 text+image+file->text
openai/gpt-5.6-luna1050K ctx · $0.20/$1.20 text+image+file->text
openai/gpt-5.4-mini400K ctx · $0.75/$4.50 text+image+file->text
openai/gpt-6.1-sol1050K ctx · $2.00/$10.00 text+image+file->text
openai/gpt-6-sol1050K ctx · $2.00/$10.00 text+image+file->text
openai/gpt-5.41050K ctx · $2.50/$15.00 text+image+file->text
openai/gpt-5.51050K ctx · $5.00/$30.00 text+image+file->text
openai/gpt-6-astra1050K ctx · $10.00/$50.00 text+image+file->text
openai/gpt-5.6-terra1050K ctx · $2.00/$12.00 text+image+file->text
openai/text-embedding-3-small8K ctx · $0.02/$0.00 text->embeddings
openai/gpt-oss-safeguard-20b128K ctx · $0.07/$0.30 text->text
openai/gpt-oss-120b131K ctx · $0.15/$0.60 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-5.6-sol1050K ctx · $4.00/$20.00 text+image+file->text
openai/gpt-oss-20b131K ctx · $0.03/$0.13 text->text
openai/gpt-4o128K ctx · $2.50/$10.00 text+image+file->text
openai/gpt-image-1-mini400K ctx · $2.50/$2.50 text+image->image
openai/gpt-5.4-image-2272K ctx · $8.00/$15.00 text+image+file->text+image
openai/gpt-image-2.5-flare400K ctx · $8.00/$8.00 text+image->image
openai/gpt-image-2.5-sunburst400K ctx · $8.00/$8.00 text+image->image
openai/gpt-image-1400K ctx · $10.00/$10.00 text+image->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-51000K ctx · $2.00/$10.00 text+image+file->text
anthropic/claude-sonnet-5.51000K ctx · $2.00/$10.00 text+image+file->text
anthropic/claude-sonnet-4.51000K ctx · $3.00/$15.00 text+image+file->text
anthropic/claude-opus-5.51000K ctx · $4.00/$20.00 text+image+file->text
anthropic/claude-opus-4.81000K 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-51000K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-opus-4.5200K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-fable-5.11000K ctx · $10.00/$50.00 text+image+file->text
anthropic/claude-fable-51000K ctx · $10.00/$50.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-flash1049K ctx · $0.14/$0.28 text->text
deepseek/deepseek-v4-pro1049K ctx · $1.65/$3.30 text->text
deepseek/deepseek-v4.1-flash1049K ctx · $0.21/$0.85 text+image->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-v4-pro-08131049K ctx · $0.89/$2.67 text->text
deepseek/deepseek-v4-flash-07311000K ctx · $0.44/$1.32 text->text
deepseek/deepseek-r1-0528164K ctx · $0.50/$2.15 text->text
deepseek/deepseek-v4-flash-0731free1049K ctx · $0.20/$0.40 text->text
elevenlabs
elevenlabs/eleven-v4-turbo · $0.00/$0.00 text->speech
elevenlabs/eleven-multilingual-v2 · $0.00/$0.00 text->speech
elevenlabs/eleven-v4 · $0.00/$0.00 text->speech
elevenlabs/eleven-turbo-v2.5 · $0.00/$0.00 text->speech
elevenlabs/eleven-flash-v2 · $0.00/$0.00 text->speech
elevenlabs/eleven-v3-conversational · $0.00/$0.00 text->speech
elevenlabs/eleven-flash-v2.5 · $0.00/$0.00 text->speech
elevenlabs/eleven-v3 · $0.00/$0.00 text->speech
elevenlabs/eleven-turbo-v2 · $0.00/$0.00 text->speech
elevenlabs/scribe-v2 · $0.00/$0.00 audio->transcription
elevenlabs/scribe-v2-medical · $0.00/$0.00 audio->transcription
Zhipu AI
z-ai/glm-5v-turbo203K ctx · $1.20/$4.00 text+image+video->text
z-ai/glm-5.3-flash1049K ctx · $0.15/$0.50 text+image+video->text
z-ai/glm-4.6205K ctx · $0.60/$2.20 text->text
z-ai/glm-5.3-flashx1049K ctx · $0.37/$1.25 text+image+video->text
z-ai/glm-5.31049K ctx · $1.13/$4.40 text->text
z-ai/glm-4.7-flash200K ctx · $0.06/$0.40 text->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-4.5v66K ctx · $0.60/$1.80 text+image->text
z-ai/glm-4.5131K ctx · $0.60/$2.20 text->text
voyage
voyage/voyage-4-lite32K ctx · $0.02/$0.00 text->embeddings
voyage/voyage-3.5-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-finance-232K ctx · $0.12/$0.00 text->embeddings
voyage/voyage-code-216K ctx · $0.12/$0.00 text->embeddings
voyage/voyage-3-large32K ctx · $0.18/$0.00 text->embeddings
voyage/voyage-code-332K ctx · $0.18/$0.00 text->embeddings
xAI
x-ai/grok-build-0.1256K ctx · $1.00/$2.00 text+image+file->text
x-ai/grok-4.31000K ctx · $1.25/$2.50 text+image+file->text
x-ai/grok-4.6500K ctx · $2.00/$6.00 text+image+file->text
x-ai/grok-4.5500K ctx · $2.00/$6.00 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-video-1.5-lite · $0.00/$0.00 text+image->video
x-ai/grok-imagine-image-2.0 · $0.00/$0.00 text+image->image
bytedance-seed
bytedance-seed/seed-1.6-flash262K ctx · $0.07/$0.30 text+image+video->text
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
bytedance-seed/seed-1.6262K ctx · $0.25/$2.00 text+image+video->text
ByteDance
bytedance/seedance-2.5 · $0.00/$0.00 text+image+audio+video->video
bytedance/seedance-2.0 · $0.00/$0.00 text+image+audio+video->video
bytedance/seedance-1-5-pro · $0.00/$0.00 text+image->video
bytedance/seedance-2.0-fast · $0.00/$0.00 text+image+audio+video->video
Moonshot AI
moonshotai/kimi-k31049K ctx · $2.83/$14.13 text+image+video->text
moonshotai/kimi-k3.1-pro1049K ctx · $2.00/$10.00 text+image+video->text
moonshotai/kimi-k2-0905262K ctx · $0.60/$2.50 text->text
Cohere
cohere/rerank-v3.54K ctx · $0.00/$0.00 text->rerank
cohere/rerank-4-pro33K ctx · $0.00/$0.00 text->rerank
cohere/rerank-4-fast33K ctx · $0.00/$0.00 text->rerank
MiniMax
minimax/minimax-m31049K ctx · $0.30/$1.20 text+image+video->text
minimax/hailuo-3-max · $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
reflection
reflection/beam-free1049K ctx · $0.00/$0.00 text->text
reflection/beam1049K ctx · $0.00/$0.00 text->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
cloudflare
cloudflare/clef-flash25K ctx · $0.09/$0.00 text+image->decisions
cloudflare/clef66K ctx · $0.24/$0.00 text+image->decisions
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
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 帧。最后一个 data 帧可能在 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 行被中断的流不收费
如果流在最后的 usage chunk 到达前就结束 — 包括客户端主动取消的情况 — 这次请求就没有可信的 token 用量依据,BazaarLink 会全额退还预扣的额度。取消前已发送到你客户端的内容不会计费。
不保证上游立即停止
关闭连接会让 BazaarLink 立即停止转发并停止为后续 token 计费,但上游供应商是否会在自己的服务器上瞬间停止生成,取决于该供应商本身 — 有些供应商断线后仍会短暂继续运算。
串流中途出错 错误帧没有 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 系列模型 —— 见下方说明。
信用额度 查询当前信用额度余额与累积 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,我们会协助复查。
隐私说明 每一笔请求都会经过自动化内容审查。
判定为违规的请求,我们会保留其内容作为合规举证之用。
其他请求不会保留完整提示词内容。
速率限制、预算与紧急刹车 这些控制可能拒绝原本有效的请求。它们与供应商故障不同,需要不同的恢复操作。
请求速率限制 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。