Skip to main content
使用 API

使用百鍊 CLI

阿里雲百鍊 CLI 是阿里雲百鍊平台專為 AI Agent 打造的命令列工具。只需一行安裝指令並完成認證,即可將百鍊平台的 AI 能力整合至各類 AI 工具中。

安裝與配置

安裝

前置要求:Node.js ≥ 22.12.0。百鍊 CLI 僅支援通過 npm 安裝。
方式一:在 AI Agent 中安裝(推薦) 在 AI Agent 中告訴 Agent:
請閱讀 https://bailian.aliyun.com/cli/install.md 並按照說明為我安裝阿里雲百鍊 CLI
方式二:手動安裝
# 第 1 步:安裝 CLI
npm install -g bailian-cli

# 第 2 步:安裝 Skills(將百鍊能力描述檔案註冊到各 Agent 的 Skills 目錄)
npx skills add modelstudioai/cli --all -g

# 第 3 步:驗證安裝
bl --version

認證與配置

使用百鍊 CLI 前,您需要完成身份認證。支援以下認證方式:

認證方式

命令

適用情境

控制台登入(推薦)

bl auth login --console

模型調用 + 應用管理(拉起瀏覽器完成 OAuth 登入)

API Key

bl auth login --api-key sk-xxx擷取 API Key

模型調用(文本、映像、視頻、語音等)

Token Plan API Key

bl auth login --config token-plan --api-key sk-sp-xxx擷取 Token Plan API Key

Token Plan 個人版訂閱使用者的模型調用。使用 bl config use --name token-plan 切換為預設配置,或在命令中加 --config token-plan 單次指定

環境變數

配置 API Key 環境變數

CI/CD、無介面環境

設定檔

bl config set --key api_key --value sk-xxx

持久化(不校正 Key 有效性)

臨時傳入

bl text chat --api-key sk-xxx --message "你好"

單次調用,不落盤

控制台登入和 API Key 可同時配置,互不覆蓋。
如果您通過控制台登入後,執行 bl text chat 等模型調用命令時仍提示"缺少 API Key",請先運行 bl update 升級到最新版本。若升級後問題仍然存在,請單獨配置 API Key:bl auth login --api-key <your-key>
認證完成後,您可以通過 bl config 設定模型、輸出目錄等參數:
# 查看當前配置
bl config show

# 設定預設文本模型
bl config set --key default-text-model --value qwen3.7-max

# 設定輸出目錄
bl config set --key output_dir --value ~/bailian-output

參數

說明

--api-key <key>

指定 API Key(僅本次生效)

--region <cn|us|intl>

切換地區(預設 cn)

--base-url <url>

自訂 API 端點

--output <text|json>

輸出格式

--timeout <seconds>

請求逾時時間

--quiet

靜默模式,減少輸出

--verbose

列印 HTTP 要求/響應詳情

--no-color

禁用 ANSI 顏色

--dry-run

預覽請求,不實際執行

--non-interactive

非互動模式,適用於 Agent 和 CI/CD

--concurrent <n>

並發請求數(預設 1)

百鍊 CLI 相容 Claude Code、Cursor、Codex、Qwen Code 等主流 AI 工具和架構。完整相容列表和整合方式,請參見百鍊 CLI GitHub 倉庫

情境實戰

電商套圖產生

告訴 Agent:
幫我產生一套亞馬遜電商主圖,6 張圖,產品是純黑色夏日男裝 T 恤
Agent 會組合多個命令完成任務:
  1. 產生 6 張產品主圖:
 bl image generate --prompt "純黑色夏日男裝T恤,白色背景,亞馬遜電商主圖風格" --n 6 --out-dir ./ecommerce/
  1. 如需調整某張圖:
 bl image edit --image ./ecommerce/image_01.png --prompt "添加模特穿著效果"
  1. 如需產生產品展示視頻:
 bl video generate --image ./ecommerce/image_01.png --prompt "T恤360度旋轉展示" --download tshirt-demo.mp4

新聞播客產生

告訴 Agent:
搜尋今天關於 AI 的新聞,寫一段相聲,然後產生男女音色區分的音頻播客
Agent 會依次執行:
  1. 連網搜尋擷取新聞素材:
 bl search web --query "今天AI新聞"
  1. 用大模型撰寫相聲稿本:
 bl text chat --message "根據以下新聞素材,寫一段相聲..."
  1. 分角色產生音頻:
 bl speech synthesize --text "甲:您聽說了嗎..." --voice Ethan --out host_male.mp3
 bl speech synthesize --text "乙:怎麼了?..." --voice Cherry --out host_female.mp3
  1. 用 ffmpeg 合并音頻片段為完整播客。

故事書產生

告訴 Agent:
幫我產生一部小紅帽的故事書,真人寫實版本,保持人物連續一致性,需要有 20 頁,尺寸是 16:9 的,變成 PDF 給我
Agent 會自動完成:為每頁產生故事文字 → 根據文字產生風格一致的配圖 → 排版並輸出 PDF。

命令參考

文本對話

bl text chat 發送文本對話請求,相容 OpenAI 介面格式。
bl text chat --message <text> [flags]

參數

說明

預設值

--model <model>

模型 ID

qwen3.7-max

--message <text>

訊息內容(可重複,首碼 role: 設定角色)

--messages-file <path>

從 JSON 檔案讀取訊息(- 表示標準輸入)

--system <text>

系統提示詞

--max-tokens <n>

最大產生 token 數

4096

--temperature <n>

採樣溫度 (0.0, 2.0]

--top-p <n>

核採樣閾值

--stream

流式輸出(TTY 下預設開啟)

--tool <json-or-path>

工具定義,JSON 或檔案路徑(可重複)

--enable-thinking

開啟思考模式(適用於 qwen3/qwq 模型)

--thinking-budget <n>

思考模式最大 token 數

4096

全模態理解

bl omni 全模態對話,支援圖片、音頻、視頻輸入,文本和語音輸出。
bl omni --message <text> [flags]

參數

說明

預設值

--message <text>

訊息內容(可重複)

--model <model>

模型 ID

qwen3.5-omni-plus

--system <text>

系統提示詞

--image <url>

圖片 URL 或本地檔案(可重複)

--audio <url>

音頻 URL 或本地檔案(可重複)

--video <url>

視頻 URL 或本地檔案

--voice <voice>

輸出音色(可選:Chelsie、Cherry、Ethan、Serena、Tina)

Cherry

--audio-format <fmt>

音訊輸出格式

wav

--audio-out <path>

儲存音頻到檔案

自動產生

--text-only

僅輸出文本,不產生音頻

--max-tokens <n>

最大產生 token 數

--temperature <n>

採樣溫度 (0.0, 2.0]

映像產生與編輯

bl image generate 文字產生映像。
bl image generate --prompt <text> [flags]

參數

說明

預設值

--prompt <text>

映像描述

--model <model>

模型 ID

qwen-image-2.0

--size <W*H>

映像尺寸,支援比例(3:4, 16:9)或像素(2048*2048)

--n <count>

每次產生圖片數量(最多 6)

1

--seed <n>

隨機種子,用於複現結果

--negative-prompt <text>

反向提示詞,排除不需要的內容

--prompt-extend <bool>

是否啟用提示詞擴充

true(同步模式)

--watermark <bool>

是否添加浮水印

true

--no-wait

非同步模式,立即返回任務 ID

--out-dir <dir>

圖片儲存目錄

--out-prefix <prefix>

檔案名稱首碼

image

--poll-interval <seconds>

輪詢間隔

3

bl image edit 編輯已有映像,支援多圖合成。
bl image edit --image <url> --prompt <text> [flags]

參數

說明

預設值

--image <url>

源圖片 URL 或本地檔案(可重複,用於多圖合成)

--prompt <text>

編輯指令

--model <model>

模型 ID

qwen-image-2.0

--size <W*H>

輸出尺寸

--n <count>

產生數量(最多 6)

1

--seed <n>

隨機種子

--negative-prompt <text>

反向提示詞

--prompt-extend <bool>

是否啟用提示詞擴充

true

--watermark <bool>

是否添加浮水印

true

--out-dir <dir>

儲存目錄

--out-prefix <prefix>

檔案名稱首碼

edited

視頻產生與編輯

bl video generate 文字或圖片產生視頻。
bl video generate --prompt <text> [--image <url>] [flags]

參數

說明

預設值

--prompt <text>

視頻描述

--model <model>

模型 ID

happyhorse-1.1-t2v(有 --image 時為 i2v)

--image <url>

輸入圖片,啟用圖生視頻模式

--negative-prompt <text>

反向提示詞

--resolution <res>

解析度(如 1280*720)

--ratio <ratio>

寬高比(如 16:9, 1:1)

--duration <seconds>

視頻時間長度(秒)

5

--prompt-extend <bool>

是否啟用提示詞擴充

--watermark <bool>

是否添加浮水印

true

--seed <n>

隨機種子

--download <path>

完成後儲存到檔案

--async

立即返回任務 ID(非同步模式,適用於 Agent/CI)

--poll-interval <seconds>

輪詢間隔

5

bl video edit 編輯視頻,支援風格轉換、對象替換等。
bl video edit --video <url> --prompt <text> [flags]

參數

說明

預設值

--video <url>

輸入視頻 URL 或本地檔案(2-10 秒)

--prompt <text>

編輯指令

--model <model>

模型 ID

happyhorse-1.0-video-edit

--ref-image <url>

參考圖片(最多 4 張,逗號分隔)

--negative-prompt <text>

反向提示詞

--resolution <res>

解析度:720P 或 1080P

1080P

--ratio <ratio>

寬高比(16:9, 9:16, 1:1, 4:3, 3:4)

--duration <seconds>

輸出時間長度(2-10 秒)

--audio-setting <mode>

音頻處理:auto 或 origin(保留原聲)

auto

--prompt-extend <bool>

是否啟用提示詞擴充

--watermark <bool>

是否添加浮水印

true

--seed <n>

隨機種子

--download <path>

儲存到檔案

--no-wait

立即返回任務 ID

--poll-interval <seconds>

輪詢間隔

15

bl video ref 多圖參考產生視頻,支援多主體、多鏡頭、配音。
bl video ref --prompt <text> --image <url>... [flags]

參數

說明

預設值

--prompt <text>

視頻描述,使用標記引用素材(圖1、視頻1 等)

--model <model>

模型 ID

happyhorse-1.1-r2v

--image <url>

參考圖片(可重複,用於多主體)

--ref-video <url>

參考視頻(可重複)

--image-voice <url>

圖片對應的配音(按位置配對)

--video-voice <url>

視頻對應的配音(按位置配對)

--resolution <res>

解析度:720P 或 1080P

720P

--ratio <ratio>

寬高比(16:9, 9:16, 1:1)

--duration <seconds>

視頻時間長度(2-10 秒)

5

--prompt-extend <bool>

是否啟用提示詞擴充

--watermark <bool>

是否添加浮水印

true

--seed <n>

隨機種子

--download <path>

儲存到檔案

--no-wait

立即返回任務 ID

--poll-interval <seconds>

輪詢間隔

15

bl video task get 查詢非同步視頻任務的狀態。
bl video task get --task-id <id>

參數

說明

--task-id <id>

非同步任務 ID

bl video download 按任務 ID 下載已完成的視頻。
bl video download --task-id <id> --out <path>

參數

說明

--task-id <id>

任務 ID

--out <path>

輸出檔案路徑

視覺理解

bl vision describe 使用視覺模型描述圖片或視頻內容。
bl vision describe --image <path-or-url> [flags]

參數

說明

預設值

--image <path-or-url>

圖片路徑或 URL

--video <url>

視頻檔案路徑或 URL

--prompt <text>

關於內容的問題

自動檢測

--model <model>

視覺模型

qwen3-vl-plus

語音合成與識別

bl speech synthesize 文字轉語音(TTS)。
bl speech synthesize --text <text> [flags]

參數

說明

預設值

--text <text>

要合成的文本

--text-file <path>

從檔案讀取文本

--model <model>

模型 ID

cosyvoice-v3-flash

--voice <voice>

音色 ID(用 --list-voices 查看)

--list-voices

列出可用音色

--format <format>

音頻格式:mp3、pcm、wav、opus

mp3

--sample-rate <rate>

採樣率(Hz)

--volume <volume>

音量(0-100)

50

--rate <rate>

語速(0.5-2.0)

1.0

--pitch <pitch>

音調(0.5-2.0)

1.0

--seed <seed>

隨機種子(0-65535)

--language <lang>

語言提示(zh、en、ja、ko 等)

--instruction <text>

自然語言風格指令(如"請用溫柔的語調")

--enable-ssml

啟用 SSML 標記解析

--out <path>

儲存音頻到檔案

自動產生

--stream

流式輸出原始 PCM 音頻

bl speech recognize 語音轉文字(ASR)。
bl speech recognize --url <audio-url> [flags]

參數

說明

預設值

--url <url>

音頻檔案 URL 或本地路徑(可重複,最多 100 個)

--model <model>

模型 ID

fun-asr

--language <lang>

語言提示(zh、en、ja 等)

--diarization

啟用說話人分離

--speaker-count <n>

預期說話人數(需配合 --diarization)

--vocabulary-id <id>

熱詞表 ID,提高識別準確率

--channel-id <n>

音頻通道 ID

0

--out <path>

儲存完整識別結果到 JSON 檔案

--no-wait

立即返回任務 ID

--poll-interval <seconds>

輪詢間隔

2

連網搜尋

bl search web 連網搜尋。
bl search web --query <text> [flags]

參數

說明

預設值

--query <text>

搜尋關鍵詞

--count <n>

搜尋結果數量

10

--list-tools

列出可用的 MCP 搜尋工具

應用與資料

bl app call 調用百鍊應用(智能體或工作流程)。
bl app call --app-id <id> --prompt <text> [flags]

參數

說明

預設值

--app-id <id>

應用 ID(必填)

--prompt <text>

輸入提示

--image <url>

圖片 URL(可重複)

--file-id <id>

預上傳的檔案 ID(可重複)

--session-id <id>

會話 ID,用於多輪對話

--stream

流式輸出(TTY 下預設開啟)

--pipeline-ids <ids>

知識庫 Pipeline ID(逗號分隔)

--memory-id <id>

記憶 ID,啟用長期記憶

--biz-params <json>

業務參數 JSON(工作流程變數)

--has-thoughts

顯示 Agent 思考過程

bl app list 列出百鍊應用。
bl app list [flags]

參數

說明

預設值

--name <name>

按名稱搜尋

--page <n>

頁碼

1

--page-size <n>

每頁數量

30

--region <region>

API 地區

cn-beijing

bl memory add 添加記憶。
bl memory add --user-id <id> [flags]

參數

說明

--user-id <id>

使用者識別碼(必填)

--messages <json>

訊息 JSON 數組

--content <text>

自訂記憶內容

--profile-schema <id>

使用者畫像 Schema ID

--memory-library-id <id>

記憶庫 ID(隔離記憶空間)

bl memory search 搜尋記憶。
bl memory search --user-id <id> [flags]

參數

說明

預設值

--user-id <id>

使用者識別碼(必填)

--query <text>

搜尋關鍵詞

--messages <json>

訊息 JSON 數組,用於上下文搜尋

--top-k <n>

返回結果數量

10

--memory-library-id <id>

記憶庫 ID

bl memory list 列出記憶。
bl memory list --user-id <id> [flags]

參數

說明

預設值

--user-id <id>

使用者識別碼(必填)

--page-size <n>

每頁數量

10

--page <n>

頁碼

1

--memory-library-id <id>

記憶庫 ID

bl knowledge retrieve 從百鍊知識庫檢索(需要 AccessKey 認證)。
bl knowledge retrieve --index-id <id> --query <text> [flags]

參數

說明

預設值

--index-id <id>

知識庫索引 ID(必填)

--query <text>

搜尋關鍵詞(必填)

--workspace-id <id>

百鍊工作空間 ID

--top-k <n>

返回結果數量

10

--rerank

啟用重排序

--rerank-top-n <n>

重排序後保留數量

--access-key-id <key>

阿里雲 AccessKey ID

--access-key-secret <key>

阿里雲 AccessKey Secret

開發輔助

bl file upload 上傳本地檔案到 DashScope 臨時儲存(48 小時有效)。
bl file upload --file <path> --model <model>

參數

說明

--file <path>

本地檔案路徑

--model <model>

目標模型名稱(檔案綁定到此模型)

bl usage free 查詢模型免費額度。
bl usage free --model <model> [flags]

參數

說明

預設值

--model <model>

模型名稱

--region <region>

API 地區

cn-beijing

bl mcp list 列出已啟用的 MCP 服務。
bl mcp list [flags]

參數

說明

預設值

--name <text>

按名稱過濾

--type <type>

服務類型:OFFICIAL 或 PRIVATE

OFFICIAL

--page <n>

頁碼

1

--page-size <n>

每頁數量

30

--region <region>

API 地區

cn-beijing

bl pipeline run 運行流水線工作流程。
bl pipeline run <file> [flags]

參數

說明

預設值

--input <json>

運行時輸入(JSON)

--input-file <path>

從檔案讀取輸入

--concurrency <n>

最大並行步驟數

1

--events <format>

事件輸出格式:jsonl

--timeout <seconds>

步驟逾時時間

bl advisor recommend 根據需求推薦最佳模型。
bl advisor recommend <prompt> [flags]

參數

說明

--message <text>

描述您的需求

--dry-run

僅顯示意圖分析和候選列表,不進行排序

常見問題

Q:安裝失敗怎麼辦? 確認 Node.js 版本 ≥ 22.12.0 且使用 npm 安裝(不支援 pnpm/yarn):
node --version
npm install -g bailian-cli
npx skills add modelstudioai/cli --all -g
Q:提示認證失敗? 檢查 API Key 是否正確配置:
bl auth status
如需重新設定:
bl auth logout
bl auth login --api-key sk-xxx
# 或拉起瀏覽器登入
bl auth login --console
Q:本地檔案可以直接用嗎? 可以。直接把檔案路徑傳給 Agent 即可,CLI 會自動上傳到臨時儲存(48 小時有效):
幫我把 ./photo.png 改成水彩風格
幫我識別 ./meeting.wav 這段錄音
描述一下 ./demo.mp4 這個視頻的內容
Q:如何查看命令的完整參數? 告訴 Agent “看一下 bl image generate 有哪些參數”,或直接運行:
bl <> --help