docs: extract active tenant ID in the API quickstart
parent
0b463e459a
commit
9cab226853
|
|
@ -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}'
|
||||
# 之后所有请求改用:
|
||||
|
|
|
|||
Loading…
Reference in New Issue