kscli installation, authentication, shared conventions, and common workflows
kscli (Knowledge Studio CLI) is the command-line tool for Knowledge Bases. Its 34 commands span Knowledge Base setup, content maintenance, retrieval service management, and retrieval/chat. It fits local debugging, scripting, and CI/CD pipelines.
Installation
Requires Node.js 20 or later.
Initial configuration
Write the API Key and default workspace ID to the config file so later commands do not need to repeat them:
Core concepts
Commands are organized around three resource layers. Understanding the hierarchy helps you pick the right command:
| Layer | Resources | Description | Command groups |
|---|---|---|---|
| Data | Collection / Category / File | File storage and organization. Files enter the data center first, then get imported into Knowledge Bases, and one file can be referenced by several Knowledge Bases | collection, category, file |
| Index | Knowledge Base / Document / Chunk | Documents are parsed into chunks and indexed. Index settings are immutable after creation | kb, doc, chunk |
| Service | Retrieval service | The retrieval entry point for Knowledge Bases, holding model, policy, and rerank settings, with a beta draft and published versions | service |
doc upload / doc import-oss) → Knowledge Base (kb create / doc upload --index-id) → retrieval service (service create --index-id) → retrieval or chat (search / chat).
Shared conventions
Authentication
All commands authenticate with an API Key, resolved in this order:
- The
--api-key <key>flag - The
DASHSCOPE_API_KEYenvironment variable api_keyin the config file
Workspace ID
Knowledge Base resources belong to a workspace, so every command except retrieve needs a workspace ID, resolved in this order:
- The
--workspace-id <id>flag - The
BAILIAN_WORKSPACE_IDenvironment variable workspace_idin the config file
Workspace ID is required.. Examples in this document and the command manuals assume the workspace ID is already set in the config file, so --workspace-id is omitted.
Global flags
These flags apply to every command and are not repeated in the per-command parameter tables:
| Flag | Type | Description |
|---|---|---|
--output <format> | string | Output format, text (default) or json |
--api-key <key> | string | API Key |
--workspace-id <id> | string | Workspace ID |
--base-url <url> | string | API base URL, rarely needed |
--timeout <seconds> | number | Request timeout in seconds |
--quiet | switch | Quiet mode, prints only the essential result |
--verbose | switch | Verbose mode, prints request details to stderr |
--dry-run | switch | Dry-run mode, previews the operation without submitting it |
--config <name> | string | Run with the named config profile |
Output formats
text(default): structured text for terminal reading.json(--output json): the full JSON result, for scripting and programmatic parsing.quiet(--quiet): the most compact output, usually just IDs, for piping.
Confirmation prompts
These commands prompt for confirmation before executing: kb delete, doc delete, chunk delete, file delete, category delete, service delete, service deploy. Pass --yes to skip the prompt in automated scripts.
Dry-run mode
--dry-run previews the operation without submitting any change. Some commands still run local validation in dry-run mode — for example, doc upload checks file formats and lists the files it would skip, which helps catch problems early:
Common workflows
Build a Knowledge Base from scratch and retrieve
Bulk import a directory into an existing Knowledge Base
Create and tune a Q&A service
Correct Knowledge Base content
Reuse an existing service config
Bulk import from OSS
Command groups
Knowledge Bases
The
kb group, 6 commands. Create, inspect, update, and delete Knowledge Bases; query storage and QPS metrics.Documents
The
doc group, 6 commands. Upload local files, import from OSS, track parse status, delete, and tag.Chunks
The
chunk group, 4 commands. Add, list, update, and delete chunks in a Knowledge Base.Retrieval services
The
service group, 7 commands. Create, configure, publish, copy, and delete retrieval and Q&A services.Retrieval and chat
The
search, chat, and retrieve commands. Consume Knowledge Bases through a retrieval service.Data center collections
The
collection and category groups, 5 commands. Manage data center containers and category hierarchies.Data center files
The
file group, 3 commands. Inspect and delete source files in the data center.Command reference table
| Command | Purpose | Key flags |
|---|---|---|
kscli kb list | List Knowledge Bases | --name |
kscli kb info | Knowledge Base details | --index-id |
kscli kb create | Create a Knowledge Base | --name, --doc-id / --category-id |
kscli kb update | Update a Knowledge Base | --index-id, --name / --description / --rerank-min-score |
kscli kb delete | Delete a Knowledge Base | --index-id, --yes |
kscli kb stats | Storage and QPS metrics | --index-id, --start / --end |
kscli doc list | List documents | --index-id |
kscli doc status | Import job status | --index-id, --job-id, --wait |
kscli doc upload | Upload files | --file, --index-id, --wait |
kscli doc delete | Delete documents | --index-id, --doc-id |
kscli doc tag | Tag files | --doc-id, --tag, --mode |
kscli doc import-oss | Import from OSS | --bucket, --region, --oss-key |
kscli chunk add | Add a chunk | --index-id, --content / --field |
kscli chunk list | List chunks | --index-id, --doc-id |
kscli chunk update | Update a chunk | --index-id, --chunk-id, --doc-id |
kscli chunk delete | Delete chunks | --index-id, --chunk-id, --yes |
kscli service list | List services | --scene |
kscli service get | Service details | --agent-id |
kscli service create | Create a service | --name, --scene, --index-id |
kscli service update | Update a service | --agent-id plus config flags |
kscli service deploy | Publish a service | --agent-id, --yes |
kscli service delete | Delete a service | --agent-id, --yes |
kscli service copy | Copy a service | --agent-id |
kscli search | Semantic retrieval | --query, --agent-id |
kscli chat | RAG conversation | --message, --agent-id |
kscli retrieve | Direct retrieval (deprecated) | --index-id, --query |
kscli file list | List files | --category-id |
kscli file get | File details | --file-id |
kscli file delete | Delete a file | --file-id, --yes |
kscli collection create | Create a collection | --name, --description |
kscli collection get | Collection details | --collection-id / --name |
kscli category list | List categories | --collection-id, --parent-id |
kscli category add | Create a category | --name, --parent-id |
kscli category delete | Delete a category | --category-id, --yes |
Troubleshooting
Workspace ID is required
Knowledge Base resources belong to a workspace, and commands need the workspace ID to locate them. Provide it in any of these ways:
Knowledge base not found
The --index-id you passed does not exist in the current workspace. Run kscli kb list to confirm the ID, and check that the configured workspace is correct.
Import job query returns SystemError
This usually means the --job-id does not exist, or the Knowledge Base has no import job. Take the job ID from the output of kscli doc upload or kscli kb create.
Deleting a document reports it does not exist
A document's doc_id inside a Knowledge Base is not necessarily the same as the file ID returned at upload time — it depends on the import path. Run kscli doc list --quiet to get the authoritative doc_id before deleting.
retrieve prints a deprecation warning
retrieve is deprecated; use search instead. search drives retrieval strategy through --agent-id and supports multiple Knowledge Bases, routing, and reranking. retrieve operates on a single Knowledge Base ID, is limited in capability, and is no longer developed.
OSS import returns a permission error
The target bucket is not authorized for the platform service. In the RAM console, confirm the AliyunServiceRoleForBailian service-linked role is correctly authorized for that bucket.
chat returns Chat API error
Check that --agent-id exists, the service has been published, and the API Key is valid. The error code and message are returned verbatim by the server — follow what they say.
file list returns an empty list
--category-id must be a real category ID; the literal default is not accepted. Get the real ID from kscli category list or the category field in kscli file get output.