เอกสารอ้างอิง API ภาพรวม API ของ BazaarLink
BazaarLink มีรูปแบบคำขอและการตอบกลับที่เป็นหนึ่งเดียวและเข้ากันได้กับ OpenAI สำหรับหลายโมเดลและผู้ให้บริการ เชื่อมต่อเพียงครั้งเดียวแล้วสลับโมเดลได้โดยไม่ต้องเขียนแอปใหม่
ข้อกำหนด OpenAPI API ของ BazaarLink ทั้งหมดจัดทำเป็นข้อกำหนด OpenAPI และเข้าถึงได้ในรูปแบบ YAML และ JSON:
ใช้ข้อกำหนดเหล่านี้กับ Swagger UI, Postman หรือเครื่องมือสร้างโค้ดที่รองรับ OpenAPI เพื่อสำรวจ API หรือสร้างไลบรารีไคลเอนต์
คำขอ เนื้อหาคำขอสำหรับ Chat Completions จะส่งไปยัง endpoint ต่อไปนี้:
POST /v1/chat/completions
ดูรายการฟิลด์ที่รองรับทั้งหมดได้ที่ พารามิเตอร์ 。
Request Schema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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" ;
reasoning ?: ReasoningConfig ;
thinking ?: ThinkingConfig ;
enable_thinking ?: boolean ;
transforms ?: Array <"middle-out" >;
models ?: string [];
route ?: "fallback" ;
provider ?: ProviderPreferences ;
};
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 ;
};
type ProviderPreferences = {
order ?: string [];
only ?: string [];
ignore ?: string [];
allow_fallbacks ?: boolean ;
sort ?:
| "price"
| "latency"
| "throughput"
| {
by : string ;
partition ?: string ;
};
require_parameters ?: boolean ;
data_collection ?: "allow" | "deny" ;
quantizations ?: string [];
max_price ?: Record <string , number >;
};
⌄ ดูทั้งหมด 225 บรรทัดเอาต์พุตที่มีโครงสร้าง บังคับให้โมเดลส่งคืน JSON ที่ถูกต้องตาม schema จำเป็นสำหรับการสร้างแอปพลิเคชันที่เชื่อถือได้ที่แยกวิเคราะห์เอาต์พุตโมเดลด้วยโปรแกรม
json_object — โหมด JSON พื้นฐาน โดยโมเดลจะส่งคืน JSON ที่ถูกต้องjson_schema — โหมด schema แบบเข้มงวด โดยผลลัพธ์ต้องตรงกับ JSON Schema ที่กำหนดPlugins BazaarLink จะส่งต่ออาร์เรย์ plugins ไปยังเส้นทาง upstream ที่เลือก ความพร้อมใช้งานขึ้นอยู่กับโมเดลและผู้ให้บริการ และโมเดลแบบ :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 ปรับรูปแบบการตอบกลับ completion จากหลายโมเดลและผู้ให้บริการให้เป็นรูปแบบเดียวที่เข้ากันได้กับ 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
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 ;
native_finish_reason : string | null ;
message : {
role : "assistant" ;
content : string | null ;
tool_calls ?: ToolCall [];
};
};
type StreamingChoice = {
index : number ;
finish_reason : string | null ;
native_finish_reason : string | null ;
delta : {
role ?: string ;
content ?: string | null ;
tool_calls ?: ToolCall [];
};
};
⌄ ดูทั้งหมด 44 บรรทัดเหตุผลการสิ้นสุด finish_reason ใช้ค่ามาตรฐาน เช่น stop, length, tool_calls, content_filter และ error ส่วน native_finish_reason จะเก็บค่าดั้งเดิมจากผู้ให้บริการ
JSON
{
"finish_reason" : "stop" ,
"native_finish_reason" : "stop"
} การสอบถามค่าใช้จ่ายและสถิติ ดึงข้อมูลสถิติโดยละเอียดสำหรับการเสร็จสมบูรณ์ครั้งเดียวด้วย ID รุ่น (จาก id การตอบกลับ chat/completions หรือการสตรีมส่วนหัว x-bz-gen-id)
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 บรรทัดChat Completions Endpoint หลัก รองรับ OpenAI Chat Completions API
POST /v1/chat/completions
เนื้อความคำขอ modelจำเป็น
string
Model ID เช่น "openai/gpt-4o" หรือ "anthropic/claude-sonnet-4.6"
messagesจำเป็น
Message[]
อาร์เรย์ของออบเจ็กต์ข้อความพร้อม role และ content
stream
boolean
ถ้า true จะส่งคืน Server-Sent Events stream ค่าเริ่มต้น: false
temperature
number
อุณหภูมิการสุ่มตัวอย่าง 0–2 สูงกว่า = สุ่มมากกว่า ค่าเริ่มต้น: 1
max_tokens
integer
จำนวนโทเค็นสูงสุดที่จะสร้าง
max_completion_tokens
integer
ชื่อแทนสำหรับ max_tokens (รองรับ OpenAI o-series) ทั้งสองรับได้; อันไหนที่ระบุจะมีผล
top_p
number
มวลความน่าจะเป็นการสุ่มตัวอย่าง Nucleus ค่าเริ่มต้น: 1
top_k
integer
จำกัดตัวเลือกโทเค็นเป็น top-K 0 = ปิดใช้งาน (พิจารณาทั้งหมด) ค่าเริ่มต้น: 0
frequency_penalty
number
ลงโทษโทเค็นที่ซ้ำ ช่วง: [-2, 2] ค่าเริ่มต้น: 0
presence_penalty
number
ลงโทษโทเค็นตามการมีอยู่ ช่วง: [-2, 2] ค่าเริ่มต้น: 0
repetition_penalty
number
ลดการซ้ำโทเค็นจากอินพุต ช่วง: (0, 2] ค่าเริ่มต้น: 1
min_p
number
ความน่าจะเป็นขั้นต่ำเทียบกับโทเค็นสูงสุด ช่วง: [0, 1] ค่าเริ่มต้น: 0
top_a
number
top-P แบบไดนามิกตามโทเค็นที่มีความน่าจะเป็นสูงสุด ช่วง: [0, 1] ค่าเริ่มต้น: 0
seed
integer
ค่า seed จำนวนเต็มสำหรับการสุ่มตัวอย่างแบบกำหนดได้ ไม่รับประกันสำหรับทุกโมเดล
n
integer
จำนวน completions ที่จะสร้าง ค่าเริ่มต้น: 1
user
string
ตัวระบุผู้ใช้ปลายทางสำหรับการตรวจสอบและตรวจจับการละเมิด ไม่มีผลต่อการเรียกเก็บเงิน ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
stop
string | string[]
ลำดับหยุด — การสร้างจะหยุดเมื่อพบ
logit_bias
object
แมป ID โทเค็นกับค่าอคติ [-100, 100] ที่เพิ่มก่อนการสุ่มตัวอย่าง ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
logprobs
boolean
ส่งคืนค่า log probabilities ของแต่ละโทเค็นเอาต์พุต ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
top_logprobs
integer
จำนวนโทเค็นที่น่าจะเป็นไปได้มากที่สุดที่จะส่งคืนต่อตำแหน่ง (ต้องใช้ logprobs: true) ช่วง: 0–20 ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
tools
Tool[]
รายการเครื่องมือ (ฟังก์ชัน) ที่โมเดลอาจเรียกใช้
tool_choice
string | object
ควบคุมการใช้เครื่องมือ: "auto", "none" หรือเครื่องมือเฉพาะ
parallel_tool_calls
boolean
เปิดใช้งานการเรียกฟังก์ชันแบบขนานเมื่อมีเครื่องมือ ค่าเริ่มต้น: true ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
response_format
object
บังคับเอาต์พุต JSON ที่มีโครงสร้าง ดูส่วน Structured Output
structured_outputs
boolean
ขอผลลัพธ์ที่สอดคล้องกับ JSON schema อย่างเคร่งครัดกับผู้ให้บริการที่รองรับ ส่งต่อตามเดิม
reasoning
object
การตั้งค่า reasoning/thinking เฉพาะผู้ให้บริการ ส่งต่อตามเดิม
reasoning_effort
string
ระดับความพยายามในการ reasoning สไตล์ OpenAI ซีรีส์ o: "low", "medium" หรือ "high" ส่งต่อตามเดิม
transforms
string[]
การแปลงข้อความที่จะใช้ เช่น ["middle-out"] ละเว้นเพื่อใช้อัตโนมัติกับโมเดลที่มีบริบท ≤8k
models
string[]
รายการโมเดลสำรอง — BazaarLink ลองแต่ละตัวตามลำดับถ้าตัวหลักล้มเหลว
route
string
ฟิลด์ความเข้ากันได้ของการกำหนดเส้นทางขั้นสูง — ผู้ใช้ส่วนใหญ่ไม่จำเป็นต้องใช้ ใช้ "models" สำหรับ fallback
provider
object
การตั้งค่าเส้นทางขั้นสูง — ผู้ใช้ส่วนใหญ่ไม่จำเป็นต้องใช้
user, logprobs, top_logprobs, logit_bias และ parallel_tool_calls ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น
พารามิเตอร์ทั้งห้านี้จะถูกตัดออกจากคำขอ upstream เมื่อโมเดลที่แก้ไขแล้วไม่ถูกระบุว่าเป็นของ OpenAI เอง — การส่งไปยัง anthropic/claude-*, google/gemini-* หรือเป้าหมายที่ไม่ใช่ OpenAI อื่น ๆ จะได้รับ 200 กลับมาโดยพารามิเตอร์ถูกละเว้นอย่างเงียบ ๆ ไม่ใช่ข้อผิดพลาด หากคุณตั้งค่าพารามิเตอร์เหล่านี้แล้วไม่เห็นผล ให้ตรวจสอบว่าโมเดลเป้าหมายเป็นของ OpenAI หรือไม่
Request Schema (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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" ;
reasoning ?: ReasoningConfig ;
thinking ?: ThinkingConfig ;
enable_thinking ?: boolean ;
transforms ?: Array <"middle-out" >;
models ?: string [];
route ?: "fallback" ;
provider ?: ProviderPreferences ;
};
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 ;
};
type ProviderPreferences = {
order ?: string [];
only ?: string [];
ignore ?: string [];
allow_fallbacks ?: boolean ;
sort ?:
| "price"
| "latency"
| "throughput"
| {
by : string ;
partition ?: string ;
};
require_parameters ?: boolean ;
data_collection ?: "allow" | "deny" ;
quantizations ?: string [];
max_price ?: Record <string , number >;
};
⌄ ดูทั้งหมด 225 บรรทัดตัวอย่างคำขอ 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" : "chatcmpl-abc123" ,
"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 ทำการ normalize เพียงสองฟิลด์เท่านั้น — model และการลบฟิลด์ provider — แล้วส่งต่อส่วนที่เหลือของการตอบกลับจาก upstream ตามเดิม ฟิลด์อย่าง native_finish_reason, system_fingerprint และ reasoning จะปรากฏก็ต่อเมื่อผู้ให้บริการ upstream รายนั้นกำหนดค่าไว้เท่านั้น — อย่าคาดหวังว่าจะมีอยู่ในทุกโมเดล usage.cost เป็นข้อยกเว้น — เป็นจำนวนที่ BazaarLink คำนวณและเรียกเก็บเองเสมอ ไม่ใช่ค่าที่ส่งต่อมาจาก upstream
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
type Response = {
id : string ;
object : "chat.completion" | "chat.completion.chunk" ;
created : number ;
model : string ;
choices : (NonStreamingChoice | StreamingChoice )[];
usage ?: ResponseUsage ;
cost ?: number ;
};
type NonStreamingChoice = {
index : number ;
finish_reason : "stop" | "length" | "tool_calls" | "content_filter" | null ;
native_finish_reason : string | null ;
message : {
role : "assistant" ;
content : string | null ;
tool_calls ?: ToolCall [];
};
};
type StreamingChoice = {
index : number ;
finish_reason : string | null ;
native_finish_reason : string | null ;
delta : {
role ?: string ;
content ?: string | null ;
tool_calls ?: ToolCall [];
};
};
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 };
};
⌄ ดูทั้งหมด 53 บรรทัดการสร้างภาพ Generate images from text prompts using models like DALL·E and GPT-4o. Use the `modalities` parameter to request image output from the chat completions endpoint. การแก้ไขภาพ (แก้ไขภาพที่มีอยู่) ใช้ 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 คืนค่า JSON ซิงโครนัสที่เข้ากันได้กับ OpenAI เป็นค่าเริ่มต้น (ตั้งแต่ 2026-07-25) — client.images.generate() ใช้ได้โดยไม่ต้องมี wrapper ส่ง stream: true เพื่อเปลี่ยนไปใช้สตรีมเหตุการณ์ SSE ซึ่งให้ความคืบหน้าสำหรับโมเดลที่ใช้เวลาสร้างนาน
A. /v1/chat/completions (native, แนะนำ) 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: ใส่ส่วน image_url ในอาร์เรย์ content รองรับ data URI หรือ URL รูปภาพแบบ https (http:// จะถูกปฏิเสธ) สูงสุด 8 รูป ~10MB ต่อ data URI ข้อความที่แนบรูปต้องมีส่วนข้อความด้วย (คำสั่งแก้ไข) บางโมเดลยังรองรับ image_config (เช่น {"strength": 0.7}, 0–1 — ค่าต่ำกว่าจะใกล้เคียงรูปต้นฉบับมากกว่า) ซึ่งส่งต่อไปยัง upstream ตามเดิม
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
client.images.edit() ของ OpenAI SDK ใช้งานได้ทันที (อัปโหลด multipart, ตอบกลับ JSON แบบซิงโครนัสคืนค่า data: [{ url }]) ข้อจำกัดเหมือน image-to-image: สูงสุด 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
promptจำเป็น
string
พรอมป์ข้อความ
size
string
ขนาดเอาต์พุต (แมปอัตโนมัติ)
n
integer
จำนวนรูป (ค่าเริ่มต้น 1)
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 Both endpoints emit the same event types:
event: heartbeat # every 60 s, keeps Cloudflare happy
data: {}
event: image # upstream URL, fastest path
data: {"index": 0, "url": "https://upstream/a.png"}
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: {}
⌄ ดูทั้งหมด 14 บรรทัดโมเดลรูปภาพที่รองรับ Model ID Modality i2i (edits)
การสร้างวิดีโอ กระบวนการแบบอะซิงโครนัสสามขั้นตอน (submit → poll → content) การสร้างวิดีโอใช้เวลา 30 วินาที–5 นาที ซึ่งไม่เข้ากับความหมายของคำขอ/การตอบแบบซิงโครนัสของ chat-completions — ดังนั้น BazaarLink จึงแยกวิดีโอไปที่ endpoint เฉพาะ /v1/videos โดยใช้รูปแบบ job-id: submit จะได้ ID vjob_* → poll สถานะ → fetch bytes เมื่อเสร็จ การเรียกโมเดลวิดีโอผ่าน /chat/completions หรือ /images/generations จะได้ 400 (code: wrong_endpoint_for_video) ค่าใช้จ่ายจะชำระตาม usage.cost จริงเมื่อ completed
ประเภทงานวิดีโอ เอนด์พอยต์เดียวครอบคลุมหลายงาน งานใดจะทำงานขึ้นอยู่กับฟิลด์ที่คุณส่ง —— โมเดลเดียวสามารถทำ image-to-video, keyframes และการต่อวิดีโอได้ ไม่ใช่ทุกโมเดลจะรองรับทุกงาน คำขอที่ไม่รองรับจะคืนค่า 400
ข้อความเป็นวิดีโอ
prompt
สร้างจากพรอมป์ตข้อความเพียงอย่างเดียว — ไม่ต้องมีสื่ออินพุต
ภาพเป็นวิดีโอ
frame_images: [ first frame ]
ภาพของคุณคือภาพนั้นเอง: กลายเป็นเฟรมแรกแล้วถูกทำให้เคลื่อนไหว โดยยังคงซื่อตรงต่อภาพต้นฉบับ เช่น ภาพถ่ายแมว → แมวตัวเดิมหันหัวในฉากเดิม
คีย์เฟรม (แรก + สุดท้าย)
frame_images: [ first, last ]
ให้ภาพเริ่มต้นและภาพสุดท้าย โมเดลจะแทรกการเคลื่อนไหวระหว่างทั้งสอง
การต่อวิดีโอ
input_video
ต่อคลิปที่มีอยู่ duration ที่ขอต้องมากกว่าความยาวของวิดีโอต้นฉบับ
อ้างอิงเป็นวิดีโอ
input_references: [ images ]
ภาพของคุณเป็นภาพอ้างอิง ไม่ใช่เฟรม: โมเดลคงวัตถุ/สไตล์ไว้และสร้างฉากใหม่ทั้งหมด เช่น ภาพแมว + "เต้นในป่า" → วิดีโอใหม่ที่คงหน้าตาของแมวไว้แต่ฉากและการเคลื่อนไหวเป็นของใหม่ (1–9 ภาพอ้างอิง) ต่างจากภาพเป็นวิดีโอ: i2v ซื่อตรงต่อภาพต้นฉบับที่แน่นอน ส่วน r2v นำวัตถุมาแสดงใหม่ในฟุตเทจใหม่
แก้ไขวิดีโอ
input_video + prompt
แก้ไขวิดีโอที่มีอยู่ — เปลี่ยนฉาก สไตล์ หรือการเคลื่อนไหว คิดเงินตามวินาทีวิดีโออินพุต + วินาทีเอาต์พุต
1. ส่งงาน (คืน vjob_xxx ทันที) POST /v1/videos
modelจำเป็น
string
ID โมเดล เช่น bytedance/seedance-2.0
promptจำเป็น
string
พรอมป์ข้อความ
duration
integer
ระยะเวลาเป็นวินาที (ขึ้นกับโมเดล)
resolution
string
ความละเอียด — 480p / 720p / 1080p ฯลฯ
generate_audio
boolean
สร้างแทร็กเสียง (true/false)
frame_images
array
ภาพเฟรมแรก/สุดท้าย (image-to-video, keyframes) อ็อบเจ็กต์ { type: "image_url", image_url: { url }, frame_type: "first_frame" | "last_frame" } หรือสตริง URL ธรรมดา
input_references
array
ภาพอ้างอิงสำหรับ reference-to-video —— ชี้นำวัตถุ/สไตล์ ไม่ใช่เฟรมที่แม่นยำ
input_video
string|object
URL วิดีโอต้นฉบับสำหรับการต่อวิดีโอและการแก้ไขวิดีโอ ต้องให้ upstream เข้าถึงได้แบบสาธารณะ
aspect_ratio
string
อัตราส่วนภาพ เช่น 16:9 หรือ 9:16 จะถูกละเว้นเมื่อภาพอินพุตกำหนดอัตราส่วน
watermark
boolean
เพิ่มลายน้ำ ค่าเริ่มต้น false
callback_url
string
URL 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
เมื่อ submit จะกันเงินตามกรณีเลวร้ายสุด × ระยะเวลา × ตัวคูณ; เมื่อ completed จะใช้ usage.cost จริงจาก upstream ชำระส่วนต่าง
2. Poll สถานะ GET /v1/videos/{id}
curl -H "Authorization: Bearer $BL_API_KEY " \
https://api.bazaarlink.ai/v1/videos/vjob_xxxNote
แต่ละ GET ต้องห่างกัน ≥ 8 วินาทีจึงจะส่งไปยัง upstream จริง (หลีกเลี่ยง rate limit)
Note
เมื่อ status=failed จะคืนยอดที่กันไว้ทั้งหมดให้ผู้ใช้
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 สาธารณะ โฮสต์ที่ป้องกัน hotlink (เช่น wiki บางแห่ง) จะล้มเหลว สื่ออินพุตจะผ่านการตรวจสอบเนื้อหาของ upstream และบางครั้งอาจถูกปฏิเสธ สำหรับการต่อวิดีโอ duration ที่ขอต้องมากกว่าความยาววิดีโอต้นฉบับ อัตราส่วนภาพเอาต์พุตจะเป็นไปตามภาพอินพุต —— ภาพสี่เหลี่ยมจัตุรัสให้วิดีโอสี่เหลี่ยมจัตุรัส การแก้ไขวิดีโอคิดเงินตามวินาทีของวิดีโออินพุตบวกวินาทีของเอาต์พุตที่สร้างขึ้น input_video (การแก้ไข / การต่อวิดีโอ) ต้องเป็น URL สาธารณะ วิดีโอที่คุณสร้างที่นี่ถูกให้บริการหลัง API key ของคุณ upstream จึงดึงไม่ได้ —— โฮสต์วิดีโอต้นฉบับของคุณไว้บน URL ที่เข้าถึงได้สาธารณะ Payload ของ webhook ไม่มีลายเซ็น — ยืนยันสถานะ/จำนวนเงินผ่าน GET /videos/{id} ก่อนดำเนินการ และสังเกตว่า unsigned_urls ที่นั่นเป็นแบบสัมบูรณ์ (ต่างจาก path แบบสัมพัทธ์ในการตอบกลับ poll) โมเดลวิดีโอที่รองรับ Model ID Modality Tasks bytedance/seedance-2.0 text+image+audio+video->video t2v, i2v bytedance/seedance-2.0-fast text+image+audio+video->video t2v, i2v minimax/hailuo-3-max text+image->video t2v, i2v google/veo-3.1 text+image->video t2v, i2v openai/sora-2-pro text+image->video t2v, i2v bytedance/seedance-1-5-pro text+image->video t2v, i2v bytedance/seedance-2.5 text+image+audio+video->video —
Responses API Endpoint ที่รองรับ OpenAI Responses API สำหรับการสนทนาหลายรอบแบบ stateless, tool calling และอินพุต multimodal เหมาะสำหรับ agent และเฟรมเวิร์กที่ใช้ OpenAI Python SDK ≥ 1.x กับ client.responses.create()
POST /v1/responses
Note
รับการยืนยันตัวตนและการกำหนดเส้นทางโมเดลเดียวกับ Chat Completions
เนื้อความคำขอ modelจำเป็น
string
Model ID เช่น "openai/gpt-4o" หรือ "anthropic/claude-sonnet-4.6"
inputจำเป็น
string | Item[]
อินพุตผู้ใช้ — สตริงธรรมดา (ข้อความเดียว) หรืออาร์เรย์ของรายการอินพุตสำหรับการสนทนาหลายรอบ/multimodal
instructions
string
คำสั่งระดับระบบ เทียบเท่ากับข้อความระบบ ต้องส่งใหม่ทุกคำขอ
stream
boolean
ถ้า true จะส่งคืน Responses API SSE stream events ประเภทเหตุการณ์: response.created, response.output_text.delta, response.completed
max_output_tokens
integer
จำนวนโทเค็นเอาต์พุตสูงสุดที่จะสร้าง (รวมโทเค็นการใช้เหตุผลสำหรับโมเดล o-series)
temperature
number
อุณหภูมิการสุ่มตัวอย่าง 0–2 สูงกว่า = สุ่มมากกว่า ค่าเริ่มต้น: 1
top_p
number
มวลความน่าจะเป็นการสุ่มตัวอย่าง Nucleus ค่าเริ่มต้น: 1
tools
Tool[]
คำจำกัดความเครื่องมือ (ฟังก์ชัน) — รูปแบบ JSON Schema เดียวกับ Chat Completions (รับทั้งรูปแบบแบนของ 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 ที่มีโครงสร้าง ดูส่วน Structured Output
models
string[]
รายการโมเดลสำรอง — BazaarLink ลองแต่ละตัวตามลำดับถ้าตัวหลักล้มเหลว
transforms
string[]
การแปลงข้อความที่จะใช้ เช่น ["middle-out"] ละเว้นเพื่อใช้อัตโนมัติกับโมเดลที่มีบริบท ≤8k
previous_response_id
string
เอนด์พอยต์นี้ไม่มีสถานะ — การส่งค่าที่ไม่ใช่ null จะคืนค่า 400 (invalid_prompt) ทันที ไม่เคยถูกยอมรับแล้วละเว้น ให้ใช้โหมด stateless แทน: ส่งประวัติการสนทนาเต็มในอาร์เรย์ input
provider
object
การตั้งค่าเส้นทางขั้นสูง — ผู้ใช้ส่วนใหญ่ไม่จำเป็นต้องใช้
Request Schema (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
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 ;
provider ?: ProviderPreferences ;
};
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" };
⌄ ดูทั้งหมด 25 บรรทัดตัวอย่างคำขอ 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 บรรทัดรูปแบบการตอบกลับ 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 แทนข้อความบทบาทระบบ และอ่าน 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) — ไม่ใช่ถูกยอมรับแล้วละเว้น ให้ใช้โหมด stateless เสมอ: ส่งประวัติการสนทนาเต็มในอาร์เรย์ input เครื่องมือโฮสต์ในตัวของ OpenAI เอง (web_search_preview, file_search, computer_use_preview) ไม่รองรับ การค้นหาเว็บใช้ได้ผ่าน plugins: [{id:"web"}] — รองรับเฉพาะบางเส้นทางโมเดล background: true ได้รับการยอมรับแต่ถูกละเว้น — ทุกคำขอทำงานแบบซิงโครนัสจนเสร็จสมบูรณ์เสมอ Messages (Anthropic) Anthropic-เข้ากันได้กับข้อความ API สำหรับ Claude SDK ใช้ทุกประการตามที่คุณต้องการกับ API ของ Anthropic — เพียงเปลี่ยนฐาน URL และส่วนหัวการตรวจสอบสิทธิ์
POST /v1/messages
Note
Accepts Bearer token หรือส่วนหัว x-api-key (ความเข้ากันได้ Anthropic SDK) ขนาดตัวเครื่องสูงสุด: 10 MB
เนื้อความคำขอ modelจำเป็น
string
Model ID เช่น "openai/gpt-4o" หรือ "anthropic/claude-sonnet-4.6"
max_tokensจำเป็น
integer
จำนวนโทเค็นสูงสุดที่จะสร้าง (จำนวนเต็มบวก)
messagesจำเป็น
Message[]
Array ของข้อความการสนทนา (ไม่ว่างเปล่า)
system
string
พร้อมท์ระบบเสริม
stream
boolean
ถ้า true จะส่งคืน Server-Sent Events stream ค่าเริ่มต้น: false
temperature
number
อุณหภูมิการสุ่มตัวอย่าง 0–2 สูงกว่า = สุ่มมากกว่า ค่าเริ่มต้น: 1
top_p
number
มวลความน่าจะเป็นการสุ่มตัวอย่าง Nucleus ค่าเริ่มต้น: 1
top_k
integer
จำกัดตัวเลือกโทเค็นเป็น top-K 0 = ปิดใช้งาน (พิจารณาทั้งหมด) ค่าเริ่มต้น: 0
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" ,
max_tokens=1024 ,
messages=[{"role" : "user" , "content" : "Hello" }]
)
print (response.content[0 ].text)
⌄ ดูทั้งหมด 13 บรรทัดการตอบสนอง 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"id" : "msg_..." ,
"type" : "message" ,
"role" : "assistant" ,
"model" : "anthropic/claude-opus-4" ,
"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 ,
"bz_cost" : 0.00042
}
}
⌄ ดูทั้งหมด 17 บรรทัดErrors: 400 (การตรวจสอบความถูกต้อง), 402 (เครดิตไม่เพียงพอ), 429 (ขีดจำกัดอัตรา), 502 (ข้อผิดพลาดอัปสตรีม / คีย์หายไป), 503 (รีสตาร์ทเซิร์ฟเวอร์)
โมเดล แสดงรายการโมเดลทั้งหมดที่พร้อมใช้งานพร้อมข้อมูลราคาและความสามารถ ไม่ต้องยืนยันตัวตนสำหรับ endpoint นี้
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
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 ;
};
description ?: string | null ;
top_provider ?: {
max_completion_tokens ?: number ;
};
supported_parameters ?: string [];
pricing_tiers ?: {
above_prompt_tokens : number ;
prompt : string ;
completion : string ;
}[];
};
⌄ ดูทั้งหมด 32 บรรทัดราคาแบบขั้นบันไดตามความยาวอินพุต บางโมเดลจะเปลี่ยนไปใช้ตารางราคาอื่นเมื่อพรอมต์เกินเกณฑ์ token — ตารางทั้งหมดเปลี่ยน ไม่ใช่แค่ส่วนที่เกินเกณฑ์ เกณฑ์เป็นอสมการแบบเข้ม: พรอมต์ที่มี token เท่ากับ N พอดียังคงคิดราคาที่ขั้นต่ำกว่า N; ขั้นที่สูงกว่าจะใช้ก็ต่อเมื่อ token อินพุตมากกว่า N เท่านั้น
pricing_tiers เป็นฟิลด์ระดับเดียวกับ pricing จะปรากฏเฉพาะเมื่อโมเดลมีขั้นราคาที่ override เกินกว่าราคาฐาน รายการเรียงตาม above_prompt_tokens จากน้อยไปมาก; prompt/completion คือราคา USD ต่อ 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 บรรทัดโมเดลที่พร้อมใช้งาน (189) เหล่านี้คือโมเดลที่พร้อมใช้งานบน BazaarLink โหลดแบบไดนามิกจากฐานข้อมูลของเรา:
Qwen
qwen/qwen3.8-max1000K ctx · $2.00/$6.00 text+image+video->text
qwen/qwen3.7-max1000K ctx · $1.48/$4.42 text->text
qwen/qwen3-next-80b-a3b-thinking262K ctx · $0.15/$1.20 text->text
qwen/qwen3-coder-plus1000K ctx · $0.65/$3.25 text->text
qwen/qwen3.5-flash-02-231000K ctx · $0.07/$0.26 text+image+video->text
qwen/qwen2.5-vl-72b-instruct128K ctx · $0.80/$1.00 text+image->text
qwen/qwen3-32b131K ctx · $0.08/$0.28 text->text
qwen/qwen3-next-80b-a3b-instruct262K ctx · $0.10/$1.10 text->text
qwen/qwen3-embedding-4b33K ctx · $0.02/$0.00 text->embeddings
qwen/qwen3.8-2.4t-a95b1049K ctx · $2.00/$6.00 text->text
qwen/qwen-2.5-7b-instruct33K ctx · $0.10/$0.20 text->text
qwen/qwen3-30b-a3b-instruct-2507262K ctx · $0.05/$0.19 text->text
qwen/qwen3.5-plus-202604201000K ctx · $0.30/$1.80 text+image+video->text
qwen/qwen3.8-27b1000K ctx · $0.45/$3.20 text+image+video->text
qwen/qwen3-8b131K ctx · $0.12/$0.46 text->text
qwen/qwen3.6-27b262K ctx · $0.29/$2.40 text+image+video->text
qwen/qwen3-vl-30b-a3b-instruct262K ctx · $0.15/$0.60 text+image->text
qwen/qwen3-max262K ctx · $0.78/$3.90 text->text
qwen/qwen3-coder-flash1000K ctx · $0.20/$0.97 text->text
qwen/qwen3.5-plus-02-151000K ctx · $0.26/$1.56 text+image+video->text
qwen/qwen3-coder-30b-a3b-instruct262K ctx · $0.07/$0.28 text->text
qwen/qwen3.5-397b-a17b262K ctx · $0.55/$3.50 text+image+video->text
qwen/qwen3-embedding-8b33K ctx · $0.01/$0.00 text->embeddings
qwen/qwen-2.5-coder-32b-instruct33K ctx · $0.66/$1.00 text->text
qwen/qwen3-235b-a22b131K ctx · $0.46/$1.82 text->text
qwen/qwen3.7-flash1000K ctx · $0.03/$0.13 text+image+video->text
qwen/qwen3-30b-a3b131K ctx · $0.13/$0.52 text->text
qwen/qwen3-vl-8b-instruct262K ctx · $0.12/$0.46 text+image->text
qwen/qwen3-vl-8b-thinking131K ctx · $0.18/$2.10 text+image->text
qwen/qwen3-vl-30b-a3b-thinking262K ctx · $0.20/$2.40 text+image->text
qwen/qwen3.5-27b262K ctx · $0.20/$1.56 text+image+video->text
qwen/qwen3.5-122b-a10b262K ctx · $0.29/$2.40 text+image+video->text
qwen/qwen3-coder262K ctx · $0.30/$1.00 text->text
qwen/qwen3-235b-a22b-thinking-2507131K ctx · $0.23/$2.30 text->text
qwen/qwen3-coder-next262K ctx · $0.12/$0.80 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
qwen/qwen3-vl-235b-a22b-instruct262K ctx · $0.21/$1.90 text+image->text
qwen/qwen3-vl-235b-a22b-thinking131K ctx · $0.40/$4.00 text+image->text
qwen/qwen3.6-plus1000K ctx · $0.33/$1.95 text+image+video->text
qwen/qwen3-max-thinking262K ctx · $0.78/$3.90 text->text
qwen/qwen3-30b-a3b-thinking-250782K ctx · $0.20/$2.40 text->text
qwen/qwen3-14b131K ctx · $0.23/$0.91 text->text
qwen/qwen3.6-35b-a3b262K ctx · $0.10/$0.90 text+image+video->text
qwen/qwen-plus-2025-07-281000K ctx · $0.26/$0.78 text->text
qwen/qwen3.5-35b-a3b262K ctx · $0.31/$1.25 text+image+video->text
qwen/qwen3.5-9b262K ctx · $0.10/$0.15 text+image+video->text
qwen/qwen-2.5-72b-instruct33K ctx · $0.36/$0.40 text->text
qwen/qwen-plus1000K ctx · $0.26/$0.78 text->text
qwen/qwen3-vl-32b-instruct131K ctx · $0.10/$0.42 text+image->text
qwen/qwen3-235b-a22b-2507262K ctx · $0.09/$0.35 text->text
OpenAI
openai/gpt-5.3-codex400K ctx · $1.75/$14.00 text+image+file->text
openai/gpt-5-mini400K ctx · $0.25/$2.00 text+image+file->text
openai/gpt-5.1400K ctx · $1.25/$10.00 text+image+file->text
openai/gpt-5.41050K ctx · $2.50/$15.00 text+image+file->text
openai/gpt-5.6-sol1050K ctx · $2.00/$10.00 text+image+file->text
openai/text-embedding-ada-0028K ctx · $0.10/$0.00 text->embeddings
openai/o1-pro200K ctx · $150.00/$600.00 text+image+file->text
openai/o3-mini-high200K ctx · $1.10/$4.40 text+file->text
openai/text-embedding-3-small8K ctx · $0.02/$0.00 text->embeddings
openai/o1200K ctx · $15.00/$60.00 text+image+file->text
openai/gpt-5.6-luna-pro1050K ctx · $0.20/$1.20 text+image+file->text
openai/gpt-6-astra1050K ctx · $10.00/$50.00 text+image+file->text
openai/gpt-5.4-mini400K ctx · $0.75/$4.50 text+image+file->text
openai/gpt-5-nano400K ctx · $0.05/$0.40 text+image+file->text
openai/gpt-oss-120b131K ctx · $0.15/$0.60 text->text
openai/gpt-5.6-terra-pro1050K ctx · $2.00/$12.00 text+image+file->text
openai/gpt-5.6-terra1050K ctx · $2.00/$12.00 text+image+file->text
openai/o3200K ctx · $2.00/$8.00 text+image+file->text
openai/gpt-5400K ctx · $1.25/$10.00 text+image+file->text
openai/o3-pro200K ctx · $20.00/$80.00 text+image+file->text
openai/sora-2-pro · $0.00/$0.00 text+image->video
openai/text-embedding-3-large8K ctx · $0.13/$0.00 text->embeddings
openai/gpt-5.4-pro1050K ctx · $30.00/$180.00 text+image+file->text
openai/gpt-5.6-luna1050K ctx · $0.20/$1.20 text+image+file->text
openai/gpt-image-2.5-sunburst400K ctx · $8.00/$8.00 text+image->image
openai/gpt-4o-2024-11-20128K ctx · $2.50/$10.00 text+image+file->text
openai/gpt-image-2.5-flare400K ctx · $8.00/$8.00 text+image->image
openai/gpt-4o128K ctx · $2.50/$10.00 text+image+file->text
openai/gpt-5.4-image-2272K ctx · $8.00/$15.00 text+image+file->text+image
openai/o4-mini200K ctx · $1.10/$4.40 text+image+file->text
openai/gpt-oss-safeguard-20b131K ctx · $0.07/$0.30 text->text
openai/o3-mini200K ctx · $1.10/$4.40 text+file->text
openai/gpt-3.5-turbo16K ctx · $0.50/$1.50 text->text
openai/o4-mini-high200K ctx · $1.10/$4.40 text+image+file->text
openai/gpt-5.6-sol-pro1050K ctx · $2.00/$10.00 text+image+file->text
openai/gpt-5.51050K ctx · $5.00/$30.00 text+image+file->text
openai/gpt-oss-20b131K ctx · $0.03/$0.13 text->text
openai/gpt-image-1400K ctx · $10.00/$10.00 text+image->image
openai/gpt-image-1-mini400K ctx · $2.50/$2.50 text+image->image
Google
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/gemini-2.5-flash-lite1049K ctx · $0.10/$0.40 text+image+file+audio+video->text
google/gemma-4-31b-it262K ctx · $0.09/$0.34 text+image+video->text
google/gemma-4-26b-a4b-it262K ctx · $0.09/$0.34 text+image+video->text
google/gemini-3.1-flash-image-preview66K ctx · $0.50/$3.00 text+image->text+image
google/gemma-3-4b-it131K ctx · $0.05/$0.10 text+image->text
google/gemini-3.5-flash-lite1049K ctx · $0.30/$2.50 text+image+file+audio+video->text
google/gemma-3-27b-it131K ctx · $0.08/$0.45 text+image->text
google/gemini-3-flash-preview1049K ctx · $0.50/$3.00 text+image+file+audio+video->text
google/gemini-2.5-pro-preview1049K ctx · $1.25/$10.00 text+image+file+audio->text
google/gemini-2.5-flash1049K ctx · $0.30/$2.50 text+image+file+audio+video->text
google/gemini-3.1-flash-image131K ctx · $0.50/$3.00 text+image->text+image
google/gemini-embedding-2-preview8K ctx · $0.20/$0.00 text+image+file+audio+video->embeddings
google/veo-3.1 · $0.00/$0.00 text+image->video
google/gemini-3-pro-image131K ctx · $2.00/$12.00 text+image->text+image
google/gemini-3.5-flash1049K ctx · $1.50/$9.00 text+image+file+audio+video->text
google/gemini-3.7-flash1049K ctx · $0.75/$3.75 text+image+file+audio+video->text
google/gemma-3-12b-it131K ctx · $0.05/$0.15 text+image->text
google/gemini-2.5-flash-image33K ctx · $0.30/$2.50 text+image->text+image
google/gemini-2.5-pro1049K ctx · $1.25/$10.00 text+image+file+audio+video->text
google/gemini-2.5-pro-preview-05-061049K ctx · $1.25/$10.00 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.1-pro-preview-customtools1049K ctx · $2.00/$12.00 text+image+file+audio+video->text
google/gemma-2-27b-it8K ctx · $0.65/$0.65 text->text
google/gemini-3.6-flash1049K ctx · $1.50/$7.50 text+image+file+audio+video->text
google/gemini-embedding-00120K ctx · $0.15/$0.00 text->embeddings
Anthropic
anthropic/claude-opus-4.61000K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-sonnet-4.61000K ctx · $3.00/$15.00 text+image+file->text
anthropic/claude-sonnet-51000K ctx · $2.00/$10.00 text+image+file->text
anthropic/claude-haiku-4.5200K ctx · $1.00/$5.00 text+image+file->text
anthropic/claude-sonnet-4.51000K ctx · $3.00/$15.00 text+image+file->text
anthropic/claude-opus-4.71000K 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-sonnet-41000K ctx · $3.00/$15.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-opus-4.1200K ctx · $15.00/$75.00 text+image+file->text
anthropic/claude-opus-4.5200K ctx · $5.00/$25.00 text+image+file->text
anthropic/claude-opus-4200K ctx · $15.00/$75.00 text+image+file->text
anthropic/claude-3-haiku200K ctx · $0.25/$1.25 text+image->text
anthropic/claude-opus-51000K ctx · $5.00/$25.00 text+image+file->text
DeepSeek
deepseek/deepseek-v3.2164K ctx · $0.28/$0.42 text->text
deepseek/deepseek-v4-flash1049K ctx · $0.20/$0.40 text->text
deepseek/deepseek-v4-pro1049K ctx · $2.40/$4.80 text->text
deepseek/deepseek-chat-v3-0324164K ctx · $0.25/$1.00 text->text
deepseek/deepseek-v4-pro-08131049K ctx · $1.32/$3.96 text->text
deepseek/deepseek-v3.2-exp164K ctx · $0.27/$0.41 text->text
deepseek/deepseek-r1-0528164K ctx · $0.50/$2.15 text->text
deepseek/deepseek-v4-flash-07311049K ctx · $0.20/$0.40 text->text
deepseek/deepseek-r1-distill-llama-70b8K ctx · $0.80/$0.80 text->text
deepseek/deepseek-v3.1-terminus164K ctx · $0.27/$1.00 text->text
deepseek/deepseek-chat164K ctx · $0.40/$1.30 text->text
deepseek/deepseek-chat-v3.1164K ctx · $0.25/$0.95 text->text
deepseek/deepseek-v4.1-flash1049K ctx · $0.30/$1.20 text+image->text
deepseek/deepseek-r164K ctx · $0.70/$2.50 text->text
Zhipu AI
z-ai/glm-5.1205K ctx · $1.40/$4.40 text->text
z-ai/glm-4.7205K ctx · $0.40/$1.75 text->text
z-ai/glm-5205K ctx · $1.00/$3.20 text->text
z-ai/glm-5v-turbo203K ctx · $1.20/$4.00 text+image+video->text
z-ai/glm-5-turbo203K ctx · $1.20/$4.00 text->text
z-ai/glm-5.21049K ctx · $1.40/$4.40 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.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.5131K ctx · $0.60/$2.20 text->text
z-ai/glm-4.6205K ctx · $0.43/$1.75 text->text
z-ai/glm-5.31311K ctx · $1.40/$4.40 text->text
z-ai/glm-5.3-flash1311K ctx · $0.15/$0.50 text+image+video->text
Moonshot AI
moonshotai/kimi-k2.7-code262K ctx · $0.95/$4.00 text+image->text
moonshotai/kimi-k31049K ctx · $3.00/$15.00 text+image+video->text
moonshotai/kimi-k2.5262K ctx · $0.60/$3.00 text+image->text
moonshotai/kimi-k2.6262K ctx · $0.95/$4.00 text+image->text
moonshotai/kimi-k2-thinking262K ctx · $0.60/$2.50 text->text
moonshotai/kimi-k2131K ctx · $0.57/$2.30 text->text
moonshotai/kimi-k2-0905262K ctx · $0.60/$2.50 text->text
xAI
x-ai/grok-4.31000K 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-4.6500K ctx · $2.00/$6.00 text+image+file->text
x-ai/grok-4.202000K ctx · $1.25/$2.50 text+image+file->text
x-ai/grok-4.20-multi-agent2000K ctx · $1.25/$2.50 text+image+file->text
x-ai/grok-build-0.1256K ctx · $1.00/$2.00 text+image+file->text
x-ai/grok-4.5500K ctx · $2.00/$6.00 text+image+file->text
MiniMax
minimax/minimax-m2.7205K ctx · $0.30/$1.20 text->text
minimax/minimax-m2.5205K ctx · $0.30/$1.20 text->text
minimax/minimax-m31049K ctx · $0.30/$1.20 text+image+video->text
minimax/minimax-m2.1205K ctx · $0.30/$1.20 text->text
minimax/hailuo-3-max · $0.00/$0.00 text+image->video
bytedance-seed
bytedance-seed/seed-1.6262K ctx · $0.25/$2.00 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.6-flash262K ctx · $0.07/$0.30 text+image+video->text
ByteDance
bytedance/seedance-2.0 · $0.00/$0.00 text+image+audio+video->video
bytedance/seedance-2.0-fast · $0.00/$0.00 text+image+audio+video->video
bytedance/seedance-1-5-pro · $0.00/$0.00 text+image->video
bytedance/seedance-2.5 · $0.00/$0.00 text+image+audio+video->video
xiaomi
xiaomi/mimo-v2.5-pro1050K ctx · $0.43/$0.87 text->text
xiaomi/mimo-v2.51050K ctx · $0.14/$0.28 text+image+audio+video->text
เรียกดูโมเดลทั้งหมดบน หน้าโมเดล
Streaming ตั้ง stream: true เพื่อรับ Server-Sent Events (SSE) stream แต่ละเหตุการณ์มีส่วนหนึ่งของการตอบกลับ
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" :"chatcmpl-abc" ,"choices" :[{"delta" :{"content" :"Hello" },"index" :0}]}
data: {"id" :"chatcmpl-abc" ,"choices" :[{"delta" :{"content" :" world" },"index" :0}]}
data: {"id" :"chatcmpl-abc" ,"choices" :[{"delta" :{},"finish_reason" :"stop" ,"index" :0}],"usage" :{"prompt_tokens" :10,"completion_tokens" :4,"total_tokens" :14}}
data: [DONE]การใช้งานใน streaming
เมื่อ streaming ข้อมูลการใช้งานจะถูกส่งคืนในชิ้นสุดท้ายก่อนข้อความ [DONE] พร้อมอาร์เรย์ choices ที่มี delta ว่างและ finish_reason: "stop"
Keep-alive และ chunk สุดท้าย สตรีมอาจมีบรรทัดคอมเมนต์ SSE (ขึ้นต้นด้วยเครื่องหมายโคลอน) หรือ event heartbeat เป็น keep-alive — ให้ข้ามบรรทัดที่ไม่ใช่ data: แทนการ JSON.parse สตรีมดิบ chunk ข้อมูลสุดท้ายจะมี usage (จำนวนโทเค็นและค่าใช้จ่าย) ก่อน data: [DONE] การตอบสนองที่สำเร็จจะมี header X-Request-Id — แนบมาด้วยเมื่อรายงานปัญหา
: keepalive <- SSE comment line — ignore, do NOT JSON.parse
data: {"id" :"chatcmpl-abc" ,"choices" :[{"delta" :{"content" :"Hi" },"index" :0}]}
data: {"id" :"chatcmpl-abc" ,"choices" :[{"delta" :{},"finish_reason" :"stop" ,"index" :0}],"usage" :{...}}
data: [DONE]การยกเลิกสตรีม คำขอ streaming สามารถยกเลิกได้ด้วยการปิดการเชื่อมต่อฝั่งไคลเอนต์ — เช่น เรียก AbortController.abort() หรือปิดออบเจ็กต์ stream ทันทีที่ BazaarLink ได้รับสัญญาณยกเลิก จะหยุดส่งต่อ chunk ถัดไปและยกเลิกคำขอที่ส่งไปยังผู้ให้บริการ
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 บรรทัดสตรีมที่ถูกขัดจังหวะไม่มีค่าใช้จ่าย
ถ้าสตรีมจบลงก่อนที่ chunk usage สุดท้ายจะมาถึง — รวมถึงกรณีที่ไคลเอนต์ยกเลิกเอง — จะไม่มีข้อมูลจำนวนโทเค็นที่เชื่อถือได้สำหรับคำขอนั้น BazaarLink จึงคืนเงินที่กันไว้เต็มจำนวน คุณจะไม่ถูกเรียกเก็บเงินสำหรับเนื้อหาที่ส่งถึงไคลเอนต์ไปแล้วก่อนการยกเลิก
ไม่รับประกันว่าผู้ให้บริการจะหยุดทันที
การปิดการเชื่อมต่อทำให้ BazaarLink หยุดส่งต่อและหยุดคิดค่าใช้จ่ายโทเค็นถัดไปทันที แต่ผู้ให้บริการต้นทางจะหยุดการสร้างข้อมูลบนเซิร์ฟเวอร์ของตนเองทันทีที่การเชื่อมต่อขาดหรือไม่นั้น ขึ้นอยู่กับผู้ให้บริการรายนั้น ๆ — บางรายอาจยังประมวลผลต่ออีกสักครู่หลังจากตัดการเชื่อมต่อ
ข้อผิดพลาดกลางสตรีม เฟรม error ไม่มีฟิลด์ choices
หากเกิดความล้มเหลวหลังจากที่ streaming เริ่มไปแล้ว (เช่น การเชื่อมต่อ upstream หลุด) คุณจะได้รับ SSE data frame รูปแบบ {error:{message,type,code}} แทนที่ {choices:[...]} ตามปกติ — โดยไม่มีการเปลี่ยนสถานะ HTTP เนื่องจาก header ถูกส่งไปแล้ว ให้ตรวจสอบ error key ก่อนอ่าน choices[0].delta และจะเรียกเก็บเงินเฉพาะโทเค็นที่ stream ไปแล้วเท่านั้น (ใช้การเรียกเก็บเงินบางส่วน)
data: {"id" :"chatcmpl-abc" ,"choices" :[{"delta" :{"content" :"The capital of " },"index" :0}]}
data: {"error" :{"message" :"Upstream connection lost." ,"type" :"upstream_error" ,"code" :502}}
data: [DONE]Embeddings Embeddings คือการแทนค่าตัวเลขของข้อความที่จับความหมายเชิงความหมาย (semantic) — แปลงข้อความเป็นเวกเตอร์ (ชุดตัวเลข) ที่นำไปใช้กับงาน machine learning ได้หลากหลาย BazaarLink มี endpoint แบบรวมศูนย์ที่รองรับ OpenAI Embeddings API ให้คุณเรียกใช้โมเดล embedding จากหลายผู้ให้บริการผ่านอินเทอร์เฟซเดียว
Embeddings คืออะไร? Embeddings แปลงข้อความเป็นเวกเตอร์มิติสูง โดยข้อความที่มีความหมายใกล้เคียงกันจะอยู่ใกล้กันในปริภูมิเวกเตอร์ — เช่น "cat" กับ "kitten" จะมี embedding ที่คล้ายกัน แต่ "cat" กับ "airplane" จะอยู่ห่างกันมาก การแทนค่าแบบเวกเตอร์นี้ทำให้เครื่องจักรเข้าใจความสัมพันธ์ระหว่างข้อความ ซึ่งเป็นรากฐานของแอปพลิเคชัน AI จำนวนมาก
กรณีการใช้งานทั่วไป RAG (รุ่นที่ดึงข้อมูลเพิ่ม) สร้างระบบที่ดึงบริบทที่เกี่ยวข้องจากฐานความรู้ก่อนสร้างคำตอบ — embeddings ช่วยหาเอกสารที่เกี่ยวข้องที่สุดเพื่อใส่ในบริบทของ LLM
การค้นหาเชิงความหมาย (Semantic Search) แปลงเอกสารและคำค้นหาเป็น embeddings แล้วหาเอกสารที่เกี่ยวข้องที่สุดด้วยความคล้ายคลึงของเวกเตอร์ — เข้าใจความหมายแทนที่จะจับคู่แค่คำสำคัญ ให้ผลลัพธ์ดีกว่าการค้นหาด้วยคำสำคัญ
ระบบแนะนำ สร้าง embeddings สำหรับสินค้า บทความ วิดีโอ และความชอบของผู้ใช้เพื่อแนะนำรายการที่คล้ายกัน — การเปรียบเทียบเวกเตอร์หารายการที่เกี่ยวข้องเชิงความหมายได้แม้ไม่มีคำสำคัญร่วมกัน
การจัดกลุ่มและจำแนกประเภท จัดกลุ่มเอกสารที่คล้ายกันหรือจำแนกข้อความโดยวิเคราะห์รูปแบบ embedding — เอกสารที่มี embedding คล้ายกันมักอยู่หัวข้อหรือหมวดหมู่เดียวกัน
ตรวจจับเนื้อหาซ้ำ หาเนื้อหาที่ซ้ำหรือใกล้เคียงกันโดยเปรียบเทียบความคล้ายคลึงของ embedding — ใช้ได้แม้เนื้อหาถูกเขียนใหม่ด้วยถ้อยคำต่างกัน
ตรวจจับความผิดปกติ ระบุเนื้อหาที่ผิดปกติหรือหลุดกรอบโดยหา embedding ที่เบี่ยงเบนไปจากรูปแบบทั่วไปของชุดข้อมูลอย่างมีนัยสำคัญ
POST /v1/embeddings
Note
ไม่ใช่ผู้ให้บริการ upstream ทุกรายรองรับ embeddings หากผู้ให้บริการที่กำหนดค่าไม่รองรับโมเดลที่ร้องขอ BazaarLink จะสำรองไปยังผู้ให้บริการถัดไปที่พร้อมใช้งานโดยอัตโนมัติ
พารามิเตอร์ modelจำเป็น
string
โมเดล embedding ที่จะใช้ เช่น "openai/text-embedding-3-small"
inputจำเป็น
string | string[] | ContentItem[]
ข้อความที่จะแปลงเป็น embedding — สตริงเดียว, อาร์เรย์ของสตริงสำหรับเรียกแบบ batch ครั้งเดียว หรือ (สำหรับโมเดลที่รองรับ) อาร์เรย์ของรายการ {content:[...]} ที่ผสมส่วน text และ image_url
dimensions
integer
ขนาดเวกเตอร์ผลลัพธ์ที่ร้องขอ ใช้ได้เฉพาะกับโมเดลที่รองรับมิติแบบปรับได้ (เช่น ตระกูล OpenAI text-embedding-3) ส่งต่อไปยังผู้ให้บริการ upstream ตามเดิมและถูกละเว้นในโมเดลที่ไม่รองรับ
encoding_format
string
รูปแบบการเข้ารหัส embedding ที่ร้องขอ เช่น "float" หรือ "base64" ส่งต่อไปยังผู้ให้บริการ upstream ตามเดิม — การรองรับขึ้นอยู่กับโมเดล
provider
object
ค่ากำหนดการเลือกเส้นทางผู้ให้บริการ — order, allow_fallbacks, data_collection และฟิลด์อื่น ๆ ที่อธิบายไว้ใน Provider Selection
คำขอพื้นฐาน 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 บรรทัดการประมวลผลแบบ Batch ส่งอาร์เรย์ของสตริงเพื่อแปลงข้อความหลายรายการเป็น embedding ในคำขอเดียว — ถูกกว่าและเร็วกว่าการเรียกทีละข้อความ
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",...}]} ทำให้คุณแปลงรูปภาพเดี่ยว ๆ หรือร่วมกับข้อความเป็น embedding ได้
ขึ้นอยู่กับโมเดล
มีเพียงบางโมเดล embedding เท่านั้นที่รับอินพุตรูปภาพ — ตรวจสอบโมดัลิตีที่โมเดลรองรับในหน้า Models ก่อนส่งเนื้อหา image_url โมเดลที่รองรับเฉพาะข้อความจะปฏิเสธรูปแบบนี้
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 บรรทัดการเลือกเส้นทางผู้ให้บริการ ควบคุมว่า upstream ใดจะให้บริการคำขอ embedding เช่นเดียวกับ chat completions — ดูรายละเอียดฟิลด์ทั้งหมดได้ที่ Provider Selection
{
"model" : "openai/text-embedding-3-small" ,
"input" : "Your text here" ,
"provider" : {
"order" : [ "openai" ] ,
"allow_fallbacks" : true ,
"data_collection" : "deny"
}
}
⌄ ดูทั้งหมด 9 บรรทัดการค้นหาโมเดล Embedding ไม่มี endpoint สำหรับแสดงรายการโมเดล embedding โดยเฉพาะ — เรียก GET /v1/models แล้วกรองฝั่งไคลเอนต์หารายการที่ output_modalities มี "embeddings" หรือดูที่หน้า Models
ข้อจำกัด ไม่รองรับ streaming — embeddings จะถูกส่งกลับเป็นการตอบสนองแบบสมบูรณ์เสมอ ต่างจาก chat completions แต่ละโมเดลมีความยาวอินพุตสูงสุด ข้อความที่เกินขีดจำกัดจะถูกตัดหรือปฏิเสธที่ upstream embeddings สำหรับอินพุตเดียวกันมีความแน่นอน (deterministic) — ไม่มี temperature หรือความสุ่มเข้ามาเกี่ยวข้อง แนวทางปฏิบัติที่ดี เลือกโมเดลตามความสมดุลระหว่างความเร็ว/คุณภาพ/ต้นทุน — โมเดลขนาดเล็ก (เช่น qwen/qwen3-embedding-4b) ถูกกว่าและเร็วกว่า ส่วนโมเดลขนาดใหญ่ (เช่น openai/text-embedding-3-large) มักให้ผลลัพธ์แม่นยำกว่า รวมข้อความหลายรายการไว้ในคำขอเดียวแทนการเรียกทีละข้อความ — ลดจำนวนรอบการเรียกและ overhead แคชผลลัพธ์ไว้ — embedding ของอินพุตเดียวกันจะไม่เปลี่ยนแปลง ควรเก็บไว้แทนการสร้างใหม่ เปรียบเทียบด้วย cosine similarity แทน Euclidean distance — ไม่ขึ้นกับสเกลและเหมาะกับเวกเตอร์มิติสูงกว่า ระวังความยาว context ของแต่ละโมเดล — เอกสารยาวอาจต้องแบ่งเป็นส่วน (chunking) ก่อนแปลงเป็น embedding พารามิเตอร์ พารามิเตอร์การสุ่มตัวอย่างกำหนดกระบวนการสร้างโทเค็น BazaarLink ส่งพารามิเตอร์ที่รองรับไปยังผู้ให้บริการ upstream; พารามิเตอร์ที่ไม่รองรับจะถูกเพิกเฉย
พารามิเตอร์การสุ่มตัวอย่าง ส่งต่อล้วนๆ — ไม่มีค่าเริ่มต้นในเครื่อง
พารามิเตอร์เหล่านี้จะถูกส่งต่อไปยังผู้ให้บริการต้นทางตามที่ส่งมาทุกประการ — BazaarLink จะไม่ใส่หรือบังคับค่าเริ่มต้นใดๆ "ค่าเริ่มต้น" ด้านล่างอธิบายพฤติกรรมของผู้ให้บริการเองเมื่อละเว้นฟิลด์ ไม่ใช่การรับประกันจาก BazaarLink
temperature
number
อุณหภูมิการสุ่มตัวอย่าง 0–2 สูงกว่า = สุ่มมากกว่า ค่าเริ่มต้น: 1
top_p
number
มวลความน่าจะเป็นการสุ่มตัวอย่าง Nucleus ค่าเริ่มต้น: 1
top_k
integer
จำกัดตัวเลือกโทเค็นเป็น top-K 0 = ปิดใช้งาน (พิจารณาทั้งหมด) ค่าเริ่มต้น: 0
frequency_penalty
number
ลงโทษโทเค็นที่ซ้ำ ช่วง: [-2, 2] ค่าเริ่มต้น: 0
presence_penalty
number
ลงโทษโทเค็นตามการมีอยู่ ช่วง: [-2, 2] ค่าเริ่มต้น: 0
repetition_penalty
number
ลดการซ้ำโทเค็นจากอินพุต ช่วง: (0, 2] ค่าเริ่มต้น: 1
min_p
number
ความน่าจะเป็นขั้นต่ำเทียบกับโทเค็นสูงสุด ช่วง: [0, 1] ค่าเริ่มต้น: 0
top_a
number
top-P แบบไดนามิกตามโทเค็นที่มีความน่าจะเป็นสูงสุด ช่วง: [0, 1] ค่าเริ่มต้น: 0
seed
integer
ค่า seed จำนวนเต็มสำหรับการสุ่มตัวอย่างแบบกำหนดได้ ไม่รับประกันสำหรับทุกโมเดล
max_tokens
integer
จำนวนโทเค็นสูงสุดที่จะสร้าง
n
integer
จำนวน completions ที่จะสร้าง ค่าเริ่มต้น: 1
logit_bias
object
แมป ID โทเค็นกับค่าอคติ [-100, 100] ที่เพิ่มก่อนการสุ่มตัวอย่าง ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
logprobs
boolean
ส่งคืนค่า log probabilities ของแต่ละโทเค็นเอาต์พุต ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
top_logprobs
integer
จำนวนโทเค็นที่น่าจะเป็นไปได้มากที่สุดที่จะส่งคืนต่อตำแหน่ง (ต้องใช้ logprobs: true) ช่วง: 0–20 ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
response_format
object
บังคับเอาต์พุต JSON ที่มีโครงสร้าง ดูส่วน Structured Output
structured_outputs
boolean
ขอผลลัพธ์ที่สอดคล้องกับ JSON schema อย่างเคร่งครัดกับผู้ให้บริการที่รองรับ ส่งต่อตามเดิม
reasoning
object
การตั้งค่า reasoning/thinking เฉพาะผู้ให้บริการ ส่งต่อตามเดิม
reasoning_effort
string
ระดับความพยายามในการ reasoning สไตล์ OpenAI ซีรีส์ o: "low", "medium" หรือ "high" ส่งต่อตามเดิม
stop
string | string[]
ลำดับหยุด — การสร้างจะหยุดเมื่อพบ
tools
Tool[]
รายการเครื่องมือ (ฟังก์ชัน) ที่โมเดลอาจเรียกใช้
tool_choice
string | object
ควบคุมการใช้เครื่องมือ: "auto", "none" หรือเครื่องมือเฉพาะ
parallel_tool_calls
boolean
เปิดใช้งานการเรียกฟังก์ชันแบบขนานเมื่อมีเครื่องมือ ค่าเริ่มต้น: true ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
พารามิเตอร์เฉพาะ BazaarLink transforms
string[]
การแปลงข้อความที่จะใช้ เช่น ["middle-out"] ละเว้นเพื่อใช้อัตโนมัติกับโมเดลที่มีบริบท ≤8k
models
string[]
รายการโมเดลสำรอง — BazaarLink ลองแต่ละตัวตามลำดับถ้าตัวหลักล้มเหลว
route
string
ฟิลด์ความเข้ากันได้ของการกำหนดเส้นทางขั้นสูง — ผู้ใช้ส่วนใหญ่ไม่จำเป็นต้องใช้ ใช้ "models" สำหรับ fallback
provider
object
การตั้งค่าเส้นทางขั้นสูง — ผู้ใช้ส่วนใหญ่ไม่จำเป็นต้องใช้
เครดิต สอบถามยอดเครดิตปัจจุบันและการใช้งาน API ตลอดอายุการใช้งาน
GET /v1/credits
Auth
Requires Bearer token (คีย์ API มาตรฐาน 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
}
} Errors: 401 (คีย์ missing/invalid), 403 (ผู้ใช้ที่ถูกระงับ)
รายละเอียดรุ่น ดึงข้อมูลสถิติโดยละเอียดสำหรับการเสร็จสมบูรณ์ครั้งเดียวด้วย ID รุ่น (จาก id การตอบกลับ chat/completions หรือการสตรีมส่วนหัว x-bz-gen-id)
GET /v1/generation?id=<generation-id>
Auth
Requires Bearer token (คีย์ API มาตรฐาน) พารามิเตอร์การสืบค้นที่จำเป็น: id
ตัวอย่างคำขอ curl "https://api.bazaarlink.ai/v1/generation?id=gen_abc123" \
-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" : "gen_xyz..." ,
"model" : "openai/gpt-4o" ,
"provider" : "openai" ,
"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 (รับรองความถูกต้อง), 404 (ไม่พบรุ่น)
API ข้อมูลสำคัญ Query ระดับขีดจำกัดอัตราของคีย์ API ปัจจุบันและตัวนับการใช้งานแบบรวม (รูปแบบการตอบกลับเป็นไปตามแบบแผน API คีย์ข้อมูลอุตสาหกรรมทั่วไป)
GET /v1/key
Auth
Requires Bearer token (คีย์ API มาตรฐาน)
การตอบสนอง 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
is_free_tier = true เมื่อยอดเครดิต < $10 Windows อยู่ใน UTC: รายวัน = วันปัจจุบัน รายสัปดาห์ = จันทร์–อาทิตย์ รายเดือน = 1st–EOM เมื่อคีย์มีการตั้งค่าขีดจำกัดการใช้จ่ายต่อคีย์ (ผ่านพารามิเตอร์ขีดจำกัดบนคีย์ creation/update) Limit / Limit_remaining / Limit_reset สะท้อนถึงขีดจำกัดนั้นและการใช้งานของระยะเวลาที่ตรงกัน มิฉะนั้นขีดจำกัดจะเป็นโมฆะและขีดจำกัดที่เหลือจะกลับไปอยู่ที่ยอดเครดิตในบัญชีของคุณ หมดอายุ_at คือเวลาหมดอายุของคีย์ (ค่าว่างหากไม่มี) is_management_key และ is_provisioning_key เป็นนามแฝงสำหรับแนวคิดเดียวกัน — เป็นจริงทั้งคู่สำหรับคีย์การจัดการ
BYOK
BazaarLink ไม่มีโปรแกรม Bring-your-own-key (BYOK) ดังนั้นจุดสิ้นสุดนี้จึงไม่ส่งคืนฟิลด์ byok_usage ใดๆ
Errors: 401 (auth), 404 (ผู้ใช้หายไป — หายาก)
รหัสข้อผิดพลาด Error รูปแบบการตอบสนอง ปลายทางการอนุมานโมเดลจะส่งคืนซองข้อผิดพลาดที่เข้ากันได้กับ OpenAI โดยฟิลด์ type อาจแตกต่างหรือถูกละไว้ได้ โปรดใช้สถานะ HTTP และ error.code ในตรรกะโปรแกรมแทนการแยกวิเคราะห์ข้อความ
{
"error" : {
"message" : "Insufficient credits. Please top up to continue." ,
"type" : "invalid_request_error" ,
"code" : "insufficient_credits"
}
} HTTP สถานะและข้อผิดพลาดรหัส Before streaming, the HTTP status identifies the broad failure class. error.code is either that number or a stable string for a specific remedy. Prefer the string code when present, otherwise use the HTTP status.
400คำขอไม่ถูกต้อง คำขอมีรูปแบบไม่ถูกต้อง อาร์เรย์ข้อความว่างเปล่า หรือช่องที่ต้องกรอกหายไป
คีย์
401ไม่ได้รับอนุญาต API หายไป ไม่ถูกต้อง หรือปิดใช้งาน
402ต้องชำระเงิน เครดิตบัญชีไม่เพียงพอ ถึงขีดจำกัดการใช้จ่ายต่อคีย์แล้ว หรือเกินขีดจำกัดงบประมาณ monthly/weekly
403ห้าม บัญชีถูกระงับหรือไม่ได้รับอนุญาต
404ไม่พบ Requested model, generation, key, or other resource does not exist
409ความขัดแย้ง Resource is not in the required state, such as an incomplete video job
410ไปแล้ว Requested model has been retired and must be replaced
413เนื้อหาใหญ่เกินไป เนื้อหาคำขอเกิน 10 MB; ลดขนาดเนื้อหาหรือแยกคำขอ
416Range ไม่น่าพอใจ Requested byte range is invalid for generated video content
429คำขอมากเกินไป Rate เกินขีดจำกัด; ตรวจสอบส่วนหัว Retry-After ก่อนที่จะลองอีกครั้ง
500ข้อผิดพลาดเซิร์ฟเวอร์ ข้อผิดพลาดภายใน BazaarLink
502เกตเวย์ไม่ถูกต้อง ผู้ให้บริการอัปสตรีมทั้งหมดล้มเหลว มีการพยายามเฟลโอเวอร์
503บริการไม่พร้อมใช้งาน ไม่มีการกำหนดค่าผู้ให้บริการอัปสตรีมสำหรับรุ่นนี้ ติดต่อผู้ดูแลระบบ
504เกตเวย์หมดเวลา Upstream connection or stream stalled and timed out
รหัสการเรียกเก็บเงินที่เครื่องอ่านได้ A 402 can represent different controls. Use these stable codes to choose the correct action.
budget_cap_reachedA weekly or monthly budget cap was reached; raise or reset the cap.
credit_limit_exceededA monthly-billing organization's credit line was exhausted; contact billing.
insufficient_creditsThe prepaid balance is insufficient; add credits.
spend_limit_exceededThe API key reached its daily, weekly, or monthly spend limit.
Stable error.code catalog These string codes are emitted by public inference and media paths. Branch on the string code when present; the HTTP status remains the broad failure class.
รุ่นและจุดสิ้นสุด
การค้นหาโมเดล วงจรการใช้งาน ราคา รูปแบบ และข้อผิดพลาดความเข้ากันได้ของอุปกรณ์ปลายทาง
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
การสร้างและแก้ไขภาพ
ข้อผิดพลาดอินพุตรูปภาพ การแก้ไขหลายส่วน เอาต์พุต และข้อผิดพลาดไปป์ไลน์รูปภาพ
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
upstream_unavailable502/503
การตรวจสอบเนื้อหา คำขอทั้งหมดจะถูกตรวจสอบโดยอัตโนมัติก่อนส่งไปยังโมเดล คำขอที่ละเมิดนโยบายการใช้งานของเราจะถูกปฏิเสธก่อนถึงโมเดล และจะได้รับข้อผิดพลาด 403
หมวดหมู่เนื้อหาที่จะถูกบล็อก การตรวจสอบเป็นไปตามนโยบายการใช้งานที่ยอมรับได้ (Acceptable Use Policy) ของเรา และจะบล็อกเนื้อหาในหมวดหมู่ต่อไปนี้เป็นหลัก:
เนื้อหาการแสวงหาประโยชน์ทางเพศ การขู่ใช้ความรุนแรง คำแนะนำในการดำเนินการที่ผิดกฎหมาย เนื้อหาที่เกี่ยวข้องกับอันตรายทางชีวภาพ รูปแบบการตอบกลับ 403 คำขอที่ถูกบล็อกโดยการตรวจสอบจะได้รับข้อผิดพลาดในรูปแบบนี้:
{
"error" : {
"message" : "Your prompt was blocked by content moderation." ,
"type" : "invalid_request_error" ,
"code" : "content_filter"
}
} คำขอที่ถูกบล็อกจะไม่ถูกเรียกเก็บเงิน — คุณจะไม่ถูกเรียกเก็บเงินสำหรับคำขอที่ถูกปฏิเสธ
การอุทธรณ์กรณีตรวจจับผิดพลาด หากคุณเชื่อว่าคำขอถูกบล็อกอย่างไม่ถูกต้อง โปรดติดต่อฝ่ายสนับสนุนพร้อมระบุเวลาของคำขอ และ (หากสะดวก) request id เราจะตรวจสอบให้
ความเป็นส่วนตัว คำขอทุกรายการจะถูกตรวจสอบเนื้อหาโดยอัตโนมัติ
คำขอที่พบว่าละเมิดนโยบายจะถูกเก็บเนื้อหาไว้เป็นหลักฐานการปฏิบัติตามข้อกำหนด
คำขออื่น ๆ จะไม่มีการเก็บเนื้อหาพรอมต์แบบเต็ม
อัตราจำกัด งบประมาณ และเบรกฉุกเฉิน These controls can reject an otherwise valid request and require different recovery actions.
การควบคุม
HTTP
จะระบุได้อย่างไร
อัตราการร้องขอจำกัด 429รหัสตัวเลข 429; ใช้ส่วนหัว Retry-After และ X-RateLimit-*
บล็อกการลงโทษจำกัดอัตรา 429รหัสตัวเลข 429 และข้อความจำกัดชั่วคราว ใช้ลองใหม่หลังจาก
Global ใช้เบรกฉุกเฉิน 503รหัสตัวเลข 503 ข้อความจำกัดการใช้จ่ายทั่วโลก และลองอีกครั้งหลังจากผ่านไป 30 หรือ 300 วินาที
Scoped spend brake 429Numeric code 429 and a spend circuit-breaker message naming the scope.
การควบคุมการเรียกเก็บเงินและงบประมาณ 402ใช้รหัสสตริงการเรียกเก็บเงินแบบคงที่ตามรายการด้านบน
Compatibility note: rate-limit and emergency-brake paths currently emit numeric error.code values. Use HTTP status, Retry-After, and the documented response message.
สถานะทรัพยากรวิดีโอและสื่อ Video validation commonly returns numeric code 400. Missing jobs return 404, retired models 410, unfinished video content 409, and invalid video byte ranges 416.
ลองนโยบายอีกครั้ง Retry only failures that may recover without changing the request. Honor Retry-After or use exponential backoff with jitter. Do not stack SDK and manual retries.
ลองอีกครั้งโดยถอยกลับ
429, 502, 503, and 504. Check the original generation job before creating another after an ambiguous network failure.
Fix ก่อนลองอีกครั้ง
400, 401, 402, 403, 404, 409, 410, 413, and 416. Fix the request, credentials, balance, permissions, resource state, or Range header first.
การจัดการข้อผิดพลาด 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 บรรทัดรูปแบบข้อผิดพลาด Streaming Errors ที่เกิดขึ้นก่อนที่จะสตรีมโทเค็นใดๆ จะส่งกลับการตอบสนองข้อผิดพลาด HTTP มาตรฐานพร้อมเนื้อหา JSON
After a stream starts, the HTTP response is already 200. Parse each SSE data frame and treat a top-level error or choices[0].finish_reason === "error" as a failed, incomplete response.
หากสตรีมล้มเหลวกลางทาง BazaarLink จะส่ง event SSE สุดท้ายที่มีอ็อบเจ็กต์ error ระดับบนสุด ตามด้วย data: [DONE] ส่วน chunk ที่ถูกส่งต่อจาก upstream บางรายแบบไม่แก้ไข อาจใส่ข้อผิดพลาดไว้ที่ choice แทน (choices[0].finish_reason === "error") — ให้รองรับทั้งสองแบบ
// If the stream fails mid-flight, BazaarLink emits a final SSE event
// with a top-level "error" object, followed by data: [DONE]
data: {"error":{"message":"Upstream stream interrupted. The response is incomplete.","type":"upstream_error","code":502}}
data: [DONE]
// Chunks relayed verbatim from some upstreams may instead carry the error
// inline on the choice: choices[0].finish_reason === "error" with an
// "error" object ({ code, message }) on the choice — handle both shapes.
// Branch on error.code; error.type can vary by failure path.
⌄ ดูทั้งหมด 10 บรรทัดการจัดการเวอร์ชัน BazaarLink เปิดให้ใช้ API path ที่เสถียรเพียงเส้นทางเดียวคือ /v1 — ไม่มีเวอร์ชันที่ผูกกับวันที่หรือ header เวอร์ชันให้ต้องจัดการ API มีการพัฒนาอย่างต่อเนื่องแทนที่จะออกเป็นรุ่นที่มีหมายเลข
การเปลี่ยนแปลงที่ไม่กระทบการทำงานเดิม สิ่งเหล่านี้จะถูกปล่อยออกมาโดยไม่แจ้งล่วงหน้า:
endpoint ใหม่ โมเดลใหม่ที่เพิ่มเข้าแคตตาล็อก พารามิเตอร์คำขอที่เป็นตัวเลือกใหม่ ฟิลด์การตอบกลับใหม่ schema ใหม่ที่มีคุณสมบัติเป็นตัวเลือก รหัสสถานะ/ข้อผิดพลาดของการตอบกลับเพิ่มเติม เขียนไคลเอนต์แบบป้องกันไว้ก่อน
ให้ข้ามฟิลด์การตอบกลับที่ไม่รู้จัก และอย่าให้ล้มเหลวเมื่อพบค่าที่ไม่รู้จักในฟิลด์ประเภท enum — ค่าใหม่จะถูกเพิ่มเข้ามาเมื่อแคตตาล็อกและฟีเจอร์ขยายตัว
การเปลี่ยนแปลงที่กระทบการทำงานเดิม สิ่งเหล่านี้เกิดขึ้นได้ยาก และครอบคลุม:
การลบหรือเปลี่ยนชื่อ endpoint พารามิเตอร์ หรือฟิลด์การตอบกลับ การเปลี่ยนชนิดของฟิลด์ การทำให้พารามิเตอร์ที่เป็นตัวเลือกกลายเป็นบังคับ เมื่อเกิดขึ้นจริง การเปลี่ยนแปลงที่กระทบการทำงานเดิมจะใช้กับ endpoint เฉพาะเจาะจง ไม่ใช่ทั้งหมดของ /v1 — ไม่มีการเลื่อนเวอร์ชันครั้งเดียวที่จะทำให้ทุกการเชื่อมต่อพังพร้อมกัน เรายังไม่ได้เผยแพร่ changelog อย่างเป็นทางการที่มีแท็ก Breaking (ดู "ติดตามความเคลื่อนไหว" ด้านล่าง) — สำหรับสิ่งที่สำคัญต่อการเชื่อมต่อของคุณ กรุณาติดต่อ Support ก่อนที่จะพึ่งพาพฤติกรรมที่ไม่มีเอกสารรองรับ
นโยบายการเลิกใช้งาน เหตุการณ์ "กระทบการทำงานเดิม" ตามปกติเพียงอย่างเดียวที่คุณควรคาดการณ์ไว้คือ โมเดลแต่ละตัวจะถูกเลิกใช้เมื่อผู้ให้บริการ upstream เลิกสนับสนุน ตรวจสอบสถานะปัจจุบันของโมเดลได้ผ่าน 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 หากคุณต้องการแจ้งเตือนล่วงหน้าสำหรับการเชื่อมต่อที่สำคัญ