From 9cab2268531477f6cd879acfd975189973d099cd Mon Sep 17 00:00:00 2001 From: kwsYegar <331533331+kwsYegar@users.noreply.github.com> Date: Fri, 25 Sep 2026 22:26:04 +0800 Subject: [PATCH] docs: extract active tenant ID in the API quickstart --- website-docs/01-getting-started/03-quickstart.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/website-docs/01-getting-started/03-quickstart.md b/website-docs/01-getting-started/03-quickstart.md index 0f80bd2c..73211b9d 100644 --- a/website-docs/01-getting-started/03-quickstart.md +++ b/website-docs/01-getting-started/03-quickstart.md @@ -90,7 +90,7 @@ ## 通过 API 完成首次问答 {#_7-用-api-走通同样的链路} -以下示例按注册、登录、建库、模型初始化、上传和问答顺序调用 API。路径统一使用 `/api/v1` 前缀。 +以下示例按注册、登录、建库、模型初始化、上传和问答顺序调用 API。路径统一使用 `/api/v1` 前缀,需要 Bash、curl 和 jq。登录账号须已加入工作空间;若登录响应没有 `active_tenant`,请先创建或加入空间,再重新登录。 ```bash BASE=http://localhost:8080/api/v1 @@ -99,9 +99,11 @@ BASE=http://localhost:8080/api/v1 curl -s -X POST $BASE/auth/register -H "Content-Type: application/json" \ -d '{"username":"admin","email":"admin@example.com","password":"pass123456"}' -# 2) 登录,取 JWT -TOKEN=$(curl -s -X POST $BASE/auth/login -H "Content-Type: application/json" \ - -d '{"email":"admin@example.com","password":"pass123456"}' | jq -r '.token') +# 2) 登录,保存 JWT 与当前工作空间 ID(后续创建 API Key 时使用) +LOGIN_RESPONSE=$(curl -s -X POST $BASE/auth/login -H "Content-Type: application/json" \ + -d '{"email":"admin@example.com","password":"pass123456"}') +TOKEN=$(printf '%s\n' "$LOGIN_RESPONSE" | jq -r '.token') +TENANT_ID=$(printf '%s\n' "$LOGIN_RESPONSE" | jq -r '.active_tenant.id') AUTH="Authorization: Bearer $TOKEN" # 3) 创建知识库 @@ -153,7 +155,7 @@ curl -s -X POST $BASE/knowledge-search -H "$AUTH" -H "Content-Type: application/ 服务端集成建议用 API Key 而不是 JWT: ```bash -# 以 Owner 身份创建 API Key(TENANT_ID 来自登录响应) +# 以当前工作空间 Owner 身份创建 API Key(TENANT_ID 已在登录步骤提取) curl -s -X POST $BASE/tenants/$TENANT_ID/api-keys -H "$AUTH" -H "Content-Type: application/json" \ -d '{"name":"ci-bot","full_access":true}' # 之后所有请求改用: