bailian-cli 0.1.2 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,21 @@
1
1
  ---
2
2
  name: bailian-api-doc
3
- description: "DashScope API Documentation Reference — MUST READ when writing ANY code that needs AI/LLM capabilities: text generation, image generation, video generation, speech synthesis, speech recognition, vision understanding, web search, RAG knowledge retrieval, memory, or app orchestration. This is the canonical API reference for integrating Alibaba Cloud Bailian (DashScope) AI services into applications, scripts, backends, or tools. Contains complete API endpoints, request/response schemas, curl examples, authentication (auto-detect local API Key), streaming/async patterns. WHEN TO USE: user is writing code / building an app / creating a service / developing a tool / implementing a feature that involves calling any AI model (LLM, VLM, TTS, ASR, image gen, video gen, etc.). Trigger keywords: 'write code', 'build app', 'integrate API', 'call model', 'HTTP request', 'curl example', 'backend service', 'generate text/image/video/audio programmatically', '接入大模型', '调用API', '写代码调用', '开发应用'."
3
+ description: "DashScope API Documentation Reference — MUST READ when writing ANY code that needs AI/LLM capabilities: text generation, image generation, video generation, speech synthesis, speech recognition, vision understanding, web search, RAG knowledge retrieval, memory, or app orchestration. This is the canonical API reference for integrating Aliyun Model Studio (DashScope) AI services into applications, scripts, backends, or tools. Contains complete API endpoints, request/response schemas, curl examples, authentication (auto-detect local API Key), streaming/async patterns. WHEN TO USE: user is writing code / building an app / creating a service / developing a tool / implementing a feature that involves calling any AI model (LLM, VLM, TTS, ASR, image gen, video gen, etc.). Trigger keywords: 'write code', 'build app', 'integrate API', 'call model', 'HTTP request', 'curl example', 'backend service', 'generate text/image/video/audio programmatically', '接入大模型', '调用API', '写代码调用', '开发应用'."
4
4
  ---
5
5
 
6
6
  # DashScope API Reference — Integration Guide
7
7
 
8
8
  > **When to use this document**: Whenever you are writing code (in any language) that needs AI capabilities — text generation, image creation, video production, speech synthesis/recognition, vision understanding, web search, RAG, or memory — refer to this document for the correct API endpoints, request formats, and authentication.
9
9
  >
10
- > This is the single source of truth for integrating Alibaba Cloud Bailian (DashScope) AI services into your applications, scripts, backends, and tools.
10
+ > This is the single source of truth for integrating Aliyun Model Studio (DashScope) AI services into your applications, scripts, backends, and tools.
11
11
 
12
12
  ## Base URL
13
13
 
14
- | Region | Base URL |
15
- |--------|----------|
16
- | cn (default) | `https://dashscope.aliyuncs.com` |
17
- | us | `https://dashscope-us.aliyuncs.com` |
18
- | intl | `https://dashscope-intl.aliyuncs.com` |
14
+ | Region | Base URL |
15
+ | ------------ | ------------------------------------- |
16
+ | cn (default) | `https://dashscope.aliyuncs.com` |
17
+ | us | `https://dashscope-us.aliyuncs.com` |
18
+ | intl | `https://dashscope-intl.aliyuncs.com` |
19
19
 
20
20
  ## Authentication
21
21
 
@@ -30,25 +30,29 @@ Authorization: Bearer sk-xxxxxxxxxxxxxxxx
30
30
  Before requesting a new key, check if one already exists locally:
31
31
 
32
32
  **1. Environment Variable (Highest Priority)**
33
+
33
34
  ```bash
34
35
  echo $DASHSCOPE_API_KEY
35
36
  ```
37
+
36
38
  If set, use it directly.
37
39
 
38
- **2. Bailian CLI Config File**
40
+ **2. Aliyun Model Studio CLI Config File**
41
+
39
42
  ```bash
40
- # Check if Bailian CLI has saved credentials
43
+ # Check if Aliyun Model Studio CLI has saved credentials
41
44
  cat ~/.bailian/config.json | grep api_key
42
45
 
43
46
  # Or use CLI command
44
47
  bl auth status
45
48
  ```
49
+
46
50
  If `api_key` exists in `~/.bailian/config.json`, use it directly.
47
51
 
48
52
  **3. Apply for a New Key**
49
53
 
50
54
  Only if neither of the above is available, get a new API Key at:
51
- https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key
55
+ https://bailian.console.aliyun.com/cn-beijing/?tab=app#/api-key
52
56
 
53
57
  #### Quick Integration Snippet
54
58
 
@@ -57,7 +61,7 @@ https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/ap
57
61
  API_KEY="${DASHSCOPE_API_KEY:-$(cat ~/.bailian/config.json 2>/dev/null | grep -o '"api_key":\s*"[^"]*"' | cut -d'"' -f4)}"
58
62
 
59
63
  if [ -z "$API_KEY" ]; then
60
- echo "No API Key found. Get one at: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key"
64
+ echo "No API Key found. Get one at: https://bailian.console.aliyun.com/cn-beijing/?tab=app#/api-key"
61
65
  exit 1
62
66
  fi
63
67
 
@@ -87,19 +91,20 @@ Authorization: ACS3-HMAC-SHA256 Credential={AccessKeyId},SignedHeaders=host;x-ac
87
91
  ```
88
92
 
89
93
  Typical architecture:
94
+
90
95
  - **Frontend**: Calls your own backend API (e.g., `POST /api/chat`)
91
96
  - **Backend**: Forwards request to DashScope API with API Key, returns response to frontend
92
97
  - **API Key**: Stored on server only — NEVER expose API Key in frontend code
93
98
 
94
99
  ## Common Headers
95
100
 
96
- | Header | Value | Description |
97
- |--------|-------|-------------|
98
- | `Content-Type` | `application/json` | Required for all JSON requests |
99
- | `Authorization` | `Bearer sk-xxx` | API Key authentication |
100
- | `x-dashscope-source-config` | JSON array (see below) | Source tracking / channel identification |
101
- | `X-DashScope-Async` | `enable` | Enable async mode (returns task_id) |
102
- | `X-DashScope-OssResourceResolve` | `enable` | Required when using `oss://` URLs |
101
+ | Header | Value | Description |
102
+ | -------------------------------- | ---------------------- | ---------------------------------------- |
103
+ | `Content-Type` | `application/json` | Required for all JSON requests |
104
+ | `Authorization` | `Bearer sk-xxx` | API Key authentication |
105
+ | `x-dashscope-source-config` | JSON array (see below) | Source tracking / channel identification |
106
+ | `X-DashScope-Async` | `enable` | Enable async mode (returns task_id) |
107
+ | `X-DashScope-OssResourceResolve` | `enable` | Required when using `oss://` URLs |
103
108
 
104
109
  ### x-dashscope-source-config (Required)
105
110
 
@@ -112,21 +117,23 @@ x-dashscope-source-config: [{"channel":"bailian-cli","tags":{"t1":"","t2":"publi
112
117
  Formatted value:
113
118
 
114
119
  ```json
115
- [{
116
- "channel": "bailian-cli",
117
- "tags": {
118
- "t1": "",
119
- "t2": "public",
120
- "t3": "skill-doc"
120
+ [
121
+ {
122
+ "channel": "bailian-cli",
123
+ "tags": {
124
+ "t1": "",
125
+ "t2": "public",
126
+ "t3": "skill-doc"
127
+ }
121
128
  }
122
- }]
129
+ ]
123
130
  ```
124
131
 
125
- | Field | Description |
126
- |-------|-------------|
127
- | `channel` | Source channel identifier, fixed as `bailian-cli` |
128
- | `tags.t1` | Reserved tag |
129
- | `tags.t2` | Access scope: `public` for external integration |
132
+ | Field | Description |
133
+ | --------- | -------------------------------------------------------- |
134
+ | `channel` | Source channel identifier, fixed as `bailian-cli` |
135
+ | `tags.t1` | Reserved tag |
136
+ | `tags.t2` | Access scope: `public` for external integration |
130
137
  | `tags.t3` | Integration source: `skill-doc` indicates API doc driven |
131
138
 
132
139
  ## Error Response Format
@@ -173,13 +180,15 @@ Fully compatible with OpenAI Chat Completions API format.
173
180
  ```json
174
181
  {
175
182
  "model": "qwen-vl-max",
176
- "messages": [{
177
- "role": "user",
178
- "content": [
179
- { "type": "text", "text": "Describe this image" },
180
- { "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
181
- ]
182
- }]
183
+ "messages": [
184
+ {
185
+ "role": "user",
186
+ "content": [
187
+ { "type": "text", "text": "Describe this image" },
188
+ { "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
189
+ ]
190
+ }
191
+ ]
183
192
  }
184
193
  ```
185
194
 
@@ -207,16 +216,18 @@ Voices: `Cherry`, `Serena`, `Ethan`, `Chelsie`, `Tina`.
207
216
  "id": "chatcmpl-xxx",
208
217
  "object": "chat.completion",
209
218
  "model": "qwen3.6-plus",
210
- "choices": [{
211
- "index": 0,
212
- "message": {
213
- "role": "assistant",
214
- "content": "Hello! How can I help you?",
215
- "reasoning_content": null,
216
- "tool_calls": null
217
- },
218
- "finish_reason": "stop"
219
- }],
219
+ "choices": [
220
+ {
221
+ "index": 0,
222
+ "message": {
223
+ "role": "assistant",
224
+ "content": "Hello! How can I help you?",
225
+ "reasoning_content": null,
226
+ "tool_calls": null
227
+ },
228
+ "finish_reason": "stop"
229
+ }
230
+ ],
220
231
  "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30 }
221
232
  }
222
233
  ```
@@ -265,10 +276,12 @@ Synchronous generation via `qwen-image-2.0` series.
265
276
  {
266
277
  "model": "qwen-image-2.0",
267
278
  "input": {
268
- "messages": [{
269
- "role": "user",
270
- "content": [{ "text": "A cat in space" }]
271
- }]
279
+ "messages": [
280
+ {
281
+ "role": "user",
282
+ "content": [{ "text": "A cat in space" }]
283
+ }
284
+ ]
272
285
  },
273
286
  "parameters": {
274
287
  "size": "1024*1024",
@@ -289,14 +302,16 @@ Size options: `1024*1024`, `720*1280`, `1280*720`, or ratios `1:1`, `3:4`, `4:3`
289
302
  {
290
303
  "model": "qwen-image-2.0",
291
304
  "input": {
292
- "messages": [{
293
- "role": "user",
294
- "content": [
295
- { "image": "https://example.com/photo.png" },
296
- { "image": "https://example.com/bg.png" },
297
- { "text": "Merge these two images" }
298
- ]
299
- }]
305
+ "messages": [
306
+ {
307
+ "role": "user",
308
+ "content": [
309
+ { "image": "https://example.com/photo.png" },
310
+ { "image": "https://example.com/bg.png" },
311
+ { "text": "Merge these two images" }
312
+ ]
313
+ }
314
+ ]
300
315
  },
301
316
  "parameters": { "size": "1024*1024", "n": 1 }
302
317
  }
@@ -307,13 +322,17 @@ Size options: `1024*1024`, `720*1280`, `1280*720`, or ratios `1:1`, `3:4`, `4:3`
307
322
  ```json
308
323
  {
309
324
  "output": {
310
- "choices": [{
311
- "finish_reason": "stop",
312
- "message": {
313
- "role": "assistant",
314
- "content": [{ "image": "https://dashscope-result.oss.aliyuncs.com/xxx.png", "type": "image" }]
325
+ "choices": [
326
+ {
327
+ "finish_reason": "stop",
328
+ "message": {
329
+ "role": "assistant",
330
+ "content": [
331
+ { "image": "https://dashscope-result.oss.aliyuncs.com/xxx.png", "type": "image" }
332
+ ]
333
+ }
315
334
  }
316
- }],
335
+ ],
317
336
  "finished": true
318
337
  },
319
338
  "usage": { "image_count": 1 },
@@ -445,6 +464,7 @@ Multi-subject reference-to-video generation with optional voice cloning. Use `
445
464
  ```
446
465
 
447
466
  **Media types**:
467
+
448
468
  - `reference_image` — reference person/object/background image
449
469
  - `reference_video` — reference video clip
450
470
  - `reference_voice` (optional per media) — voice audio for the subject
@@ -493,6 +513,7 @@ Poll until `task_status` becomes `SUCCEEDED` or `FAILED`. Recommended interval:
493
513
  Task statuses: `PENDING` → `RUNNING` → `SUCCEEDED` | `FAILED`.
494
514
 
495
515
  Result fields vary by task type:
516
+
496
517
  - Video: `output.video_url`
497
518
  - Image (async): `output.choices[].message.content[].image`
498
519
  - ASR: `output.results[].transcription_url`
@@ -533,7 +554,10 @@ Voices: `Cherry`, `Serena`, `Ethan`, `Chelsie`.
533
554
  ```json
534
555
  {
535
556
  "output": {
536
- "audio": { "url": "https://dashscope-result.oss.aliyuncs.com/xxx.wav", "expires_at": "2024-01-02T00:00:00Z" },
557
+ "audio": {
558
+ "url": "https://dashscope-result.oss.aliyuncs.com/xxx.wav",
559
+ "expires_at": "2024-01-02T00:00:00Z"
560
+ },
537
561
  "finish_reason": "stop"
538
562
  },
539
563
  "usage": {},
@@ -678,20 +702,24 @@ curl -X POST "https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcrip
678
702
  "text": "Response text",
679
703
  "finish_reason": "stop",
680
704
  "session_id": "session_xxx",
681
- "thoughts": [{
682
- "thought": "I need to search...",
683
- "action_type": "api",
684
- "action_name": "search",
685
- "action_input": "{}",
686
- "response": "",
687
- "observation": "Search results..."
688
- }],
689
- "doc_references": [{
690
- "index_id": "idx_xxx",
691
- "title": "Doc Title",
692
- "doc_id": "doc_xxx",
693
- "text": "Relevant text snippet"
694
- }]
705
+ "thoughts": [
706
+ {
707
+ "thought": "I need to search...",
708
+ "action_type": "api",
709
+ "action_name": "search",
710
+ "action_input": "{}",
711
+ "response": "",
712
+ "observation": "Search results..."
713
+ }
714
+ ],
715
+ "doc_references": [
716
+ {
717
+ "index_id": "idx_xxx",
718
+ "title": "Doc Title",
719
+ "doc_id": "doc_xxx",
720
+ "text": "Relevant text snippet"
721
+ }
722
+ ]
695
723
  },
696
724
  "usage": { "models": [{ "model_id": "qwen-plus", "input_tokens": 100, "output_tokens": 50 }] },
697
725
  "request_id": "xxx"
@@ -792,7 +820,7 @@ Response: `{ "request_id": "xxx", "memory_nodes": [{ "memory_node_id": "xxx", "c
792
820
 
793
821
  ## 9. Knowledge Retrieve (AK/SK Required)
794
822
 
795
- **Endpoint**: `POST https://bailian.cn-beijing.aliyuncs.com` (Bailian Cloud API, POP style)
823
+ **Endpoint**: `POST https://bailian.cn-beijing.aliyuncs.com` (Aliyun Model Studio Cloud API, POP style)
796
824
 
797
825
  Requires AK/SK V3 ROA signing, NOT Bearer token.
798
826
 
@@ -813,7 +841,7 @@ x-acs-content-sha256: <sha256 of body>
813
841
  ```json
814
842
  {
815
843
  "IndexId": "idx_xxx",
816
- "Query": "如何使用百炼",
844
+ "Query": "如何使用阿里云百炼",
817
845
  "DenseSimilarityTopK": 100,
818
846
  "SparseSimilarityTopK": 100,
819
847
  "RerankTopN": 5,
@@ -831,11 +859,13 @@ Query parameter: `?WorkspaceId=ws_xxx`
831
859
  "Success": true,
832
860
  "RequestId": "xxx",
833
861
  "Data": {
834
- "Nodes": [{
835
- "Text": "Relevant knowledge text...",
836
- "Score": 0.95,
837
- "Metadata": { "doc_name": "guide.pdf", "page": 3 }
838
- }]
862
+ "Nodes": [
863
+ {
864
+ "Text": "Relevant knowledge text...",
865
+ "Score": 0.95,
866
+ "Metadata": { "doc_name": "guide.pdf", "page": 3 }
867
+ }
868
+ ]
839
869
  }
840
870
  }
841
871
  ```
@@ -851,7 +881,12 @@ Uses JSON-RPC 2.0 over Streamable HTTP (MCP protocol).
851
881
  ### Step 1: Initialize
852
882
 
853
883
  ```json
854
- { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2025-03-26", "capabilities": {} } }
884
+ {
885
+ "jsonrpc": "2.0",
886
+ "id": 1,
887
+ "method": "initialize",
888
+ "params": { "protocolVersion": "2025-03-26", "capabilities": {} }
889
+ }
855
890
  ```
856
891
 
857
892
  ### Step 2: Call Tool
@@ -875,10 +910,12 @@ Uses JSON-RPC 2.0 over Streamable HTTP (MCP protocol).
875
910
  "jsonrpc": "2.0",
876
911
  "id": 2,
877
912
  "result": {
878
- "content": [{
879
- "type": "text",
880
- "text": "{ \"results\": [{ \"title\": \"...\", \"url\": \"...\", \"snippet\": \"...\" }] }"
881
- }]
913
+ "content": [
914
+ {
915
+ "type": "text",
916
+ "text": "{ \"results\": [{ \"title\": \"...\", \"url\": \"...\", \"snippet\": \"...\" }] }"
917
+ }
918
+ ]
882
919
  }
883
920
  }
884
921
  ```
@@ -951,6 +988,7 @@ curl -X POST "{upload_host}" \
951
988
  Result: `oss://{upload_dir}/{filename}`
952
989
 
953
990
  **Important**: When using `oss://` URLs in subsequent API calls, you MUST include the header:
991
+
954
992
  ```
955
993
  X-DashScope-OssResourceResolve: enable
956
994
  ```
@@ -959,12 +997,12 @@ X-DashScope-OssResourceResolve: enable
959
997
 
960
998
  ## Integration Patterns Summary
961
999
 
962
- | Pattern | APIs | Header |
963
- |---------|------|--------|
964
- | **Sync Request** | Chat, Image Gen/Edit, TTS, App Call, Memory | Standard |
965
- | **Async Task** | Video Gen/Edit, ASR (long), Image (legacy) | `X-DashScope-Async: enable` |
966
- | **Streaming (SSE)** | Chat, TTS, App Call | `stream: true` in body |
967
- | **Polling** | All async tasks | `GET /api/v1/tasks/{id}` |
968
- | **File Upload** | Two-step OSS | `X-DashScope-OssResourceResolve: enable` |
969
- | **MCP Protocol** | WebSearch | JSON-RPC 2.0 + `Mcp-Session-Id` |
970
- | **AK/SK Signing** | Knowledge Retrieve | ACS3-HMAC-SHA256 |
1000
+ | Pattern | APIs | Header |
1001
+ | ------------------- | ------------------------------------------- | ---------------------------------------- |
1002
+ | **Sync Request** | Chat, Image Gen/Edit, TTS, App Call, Memory | Standard |
1003
+ | **Async Task** | Video Gen/Edit, ASR (long), Image (legacy) | `X-DashScope-Async: enable` |
1004
+ | **Streaming (SSE)** | Chat, TTS, App Call | `stream: true` in body |
1005
+ | **Polling** | All async tasks | `GET /api/v1/tasks/{id}` |
1006
+ | **File Upload** | Two-step OSS | `X-DashScope-OssResourceResolve: enable` |
1007
+ | **MCP Protocol** | WebSearch | JSON-RPC 2.0 + `Mcp-Session-Id` |
1008
+ | **AK/SK Signing** | Knowledge Retrieve | ACS3-HMAC-SHA256 |