ikc-open-platform-sdk
ikc-open-platform 第三方开发者 SDK(导入包 ikc_open_platform_sdk)。
- 认证:应用 API Key(
Authorization: Bearer <api-key>,由管理面/admin/apps/{appId}/keys创建)。 - 管理认证:独立入口
OpenPlatformAdminClient只发送Authorization: Bearer <admin-token>与X-Request-Id,不发送应用 API Key 语义的额外头。 - 协议:统一响应壳
errCode/errMsg/data/traceId/reqId解包;业务模型一律复用ikc-sdk-lib(本 SDK 不自定义业务模型)。 - 追踪:每请求注入 23 位纯数字
X-Request-Id;reqId可显式传入,缺省 SDK 生成req_前缀值并随壳回显。 - 能力面(四类业务域 + 解析文档索引任务 + 知识库子资源域 Wiki / 图谱 + 记忆域 Flash Knowledge):
client.knowledge_bases:create / update / query / getclient.documents:ingest / ingest_and_parse / upload / getclient.parse:parse / parse_direct / query_result / issue_download_ticket / downloadclient.indexer:submit / task / cancel(IDX-01~IDX-03)+ 9 个任务便利方法 (store_parsed_document / reparse_document / patch_parsed_document / patch_chunk / delete_document / reindex_document / embed_chunks / replace_indexed_chunks / build_segment_index);仅接受kbMode=text知识库,平台校验归属后直连 TMclient.search:universal_search(V1)/ universal_search_v2(V2)/ deep_search / query(兼容别名)client.wiki:tree / page / stat / export / build / job(W-01/W-02/W-04/W-05 只读 + W-06/W-07 构建)- 人工修正(W-08~W-19 写面):page_patch / page_create / page_move / page_merge / page_split / page_retire / page_restore / sources_patch / links_patch / corrections_apply / revisions / revision / revision_revert / submit_review / reviews / review_action
client.graph:stat / nodes / edges / export / build / job(G-01/G-02/G-03/G-05 只读 + G-06/G-07 构建)- 检索 / 结构(G-04,2026-10-06 起 core 读自己的库并开放北向):neighbors(1/2 跳邻域)/
paths(两实体最短路径)/ search(图内词法检索;
ikc-sdk-lib尚无响应模型,返回原始datadict)
- 检索 / 结构(G-04,2026-10-06 起 core 读自己的库并开放北向):neighbors(1/2 跳邻域)/
paths(两实体最短路径)/ search(图内词法检索;
client.flash:observe / write / recall / query / get / update / delete / consolidate / job / jobs / policy(记忆域 M-01~M-11;面向 agent 的短期 / 长期记忆)
client.workspaces:Workspace query/create/get/update/select 与成员 query/add/update/remove。client.workspace_model_configs:query_providers / query / create / get / update / copy / available / delete / retry_sync / usages / test_draft / test_changes / test_connection / resolve / get_kb_models / set_kb_models;使用 shared 0.31.0 typed 契约,测试不接受任意输入,resolve 仅返回模型别名和能力。OpenPlatformAdminClient(独立管理面客户端,ikc_sdk.open_platform0.31.0 typed 契约):admin.tenants:create / query / get / update / update_status / list_entitlements / get_entitlement / upsert_entitlement / list_app_bindings / upsert_app_binding;admin.tenant_bootstraps:create / query / get / issue_account_grant / retry;- 与
OpenPlatformClient资源完全隔离,默认不重试写请求,data.reason通过OpenPlatformAPIError.data原样保留,异常文本不包含管理令牌。
- 错误模型:
OpenPlatformAPIError(errCode/errMsg/traceId/reqId)、OpenPlatformConnectionError、OpenPlatformTimeoutError、OpenPlatformProtocolError。 - 响应校验:W/G 域按
ikc_sdk.core.api.{wiki,graph}.*、记忆域按ikc_sdk.flash.api模型校验;实例侧字段漂移时记 warning 并回落原始dict, 不因契约模型过严打断调用。模型本身的缺陷回ikc-sdk-lib修(先例:W-02page.unitId实测为null,ikc-sdk-lib0.9.2 已把WikiPageView.unitId放宽为str | None——不在此处改契约)。
安装
0.16.0 增加解析文档索引资源 client.indexer(IDX-01~IDX-03),并同步 CLI indexer-submit / indexer-task / indexer-cancel
与 MCP indexer_submit / indexer_task / indexer_cancel;SDK 精确依赖 ikc-sdk-lib==0.39.0。
索引任务只面向 kbMode=text 知识库,body 与 Celery 载荷同形(snake_case),由平台复用同一份契约校验后直连 TM。
0.14.0 增加独立管理客户端 OpenPlatformAdminClient(Tenant 开户治理):只装配 tenants 与 tenant_bootstraps,复用 ikc_sdk.open_platform 0.30.0 契约;管理令牌与第三方应用 API Key 认证隔离,默认不重试任何写请求。SDK 依赖 ikc-sdk-lib==0.30.0。
0.13.0 对齐 Workspace 模型配置 API:16 条路径覆盖查询、CRUD、删除/重试/引用、三类固定连接探针、resolve 和知识库模型选择;Core reason 通过 OpenPlatformAPIError.data 保留,并保留 trace_id/req_id。SDK 依赖 ikc-sdk-lib==0.29.0。0.10.0 增加 Workspace 成员管理 API;同时提供 client.workspaces.query/create/get/update/select(payload) 与 client.knowledge_bases.query_workspace(workspace_id, payload)。
pip install ikc-open-platform-sdk==0.16.0 # 依赖 ikc-sdk-lib 0.39.0
pip install sdk/python/ # 或本地源码
快速开始
from ikc_open_platform_sdk import OpenPlatformClient
from ikc_sdk.core.api.search.universal import SearchQueryRequest
with OpenPlatformClient("http://localhost:18000", api_key="<app-api-key>") as client:
result = client.search.universal_search(SearchQueryRequest(query="IKC 平台"))
for hit in result.hits:
print(hit)
client.wiki.stat("kb_10001") # W-04
client.graph.stat("kb_10001") # G-01
client.flash.policy() # M-10(记忆域加工策略快照)
client.indexer.task("kb_10001", "idxt_xxx") # IDX-02(索引任务状态)
管理面客户端(Tenant 开户治理)
OpenPlatformAdminClient 与第三方应用客户端完全隔离:只装 tenants / tenant_bootstraps,只发管理令牌与
X-Request-Id,默认不重试写请求。请求与响应直接使用 ikc_sdk.open_platform 0.30.0 契约。
from ikc_open_platform_sdk import OpenPlatformAdminClient
from ikc_sdk.open_platform import (
AppTenantBindingUpsertRequest,
TenantBootstrapCreateRequest,
TenantCreateRequest,
TenantQueryRequest,
TenantStatusUpdateRequest,
)
with OpenPlatformAdminClient("http://localhost:18000", admin_token="<admin-token>") as admin:
tenant = admin.tenants.create(TenantCreateRequest(
idempotencyKey="open-acme-001",
tenantCode="acme",
tenantName="Acme",
))
page = admin.tenants.query(TenantQueryRequest(keyword="acme", limit=20))
tenant_id = tenant.tenantId
admin.tenants.update_status(tenant_id, TenantStatusUpdateRequest(
tenantId=tenant_id,
status="active",
expectedRowVersion=tenant.rowVersion,
))
admin.tenants.upsert_app_binding(tenant_id, "app_1", AppTenantBindingUpsertRequest(
tenantId=tenant_id, appId="app_1",
status="active", bindingSource="manual_approval", expectedRowVersion=0,
))
task = admin.tenant_bootstraps.create(TenantBootstrapCreateRequest(
bootstrapId="bootstrap-acme-001",
tenant={"tenantCode": "acme", "tenantName": "Acme"},
entitlement={"serviceCode": "standard_kb", "source": "manual"},
appBinding={"appId": "app_1"},
requestedByType="admin_token",
requestedById="ops-1",
))
检索 V2(universal_search_v2,D-03)
V2 把文档 / Wiki / 图谱 / 事实收进同一个召回面;V1(universal_search)行为不变、两版并存:
from ikc_sdk.core.api.search.universal_v2 import UniversalSearchV2Request
resp = client.search.universal_search_v2(UniversalSearchV2Request(
query="设备支持的最大并发数是多少?",
kbIds=["kb_10001"], # 必填,1~20 个且不重复
topK=10,
include={"wikiPage": True, "graphEntities": True, "graphRelations": True},
))
resp.strategy # 如 lexical@search-v2.1
resp.partial # true = 某一路降级,原因见 warnings[](如 vector_unavailable)
resp.nextCursor # 不透明签名游标:原样回填 cursor,不得解析、不得跨查询复用
for hit in resp.hits:
print(hit.retrievalId, hit.representationKind, hit.score, hit.snippet)
模型是 extra="forbid":tenantId / principalIds / authorizedOrgPaths / queryVector / index / routing
等安全字段由平台按调用方身份注入,调用方不发送也不构造。filters.currentVersionOnly 缺省 true(只召回当前版本)。
解析文档索引(IDX-01~IDX-03)
client.indexer 把 9 个 indexer.* Celery 任务封装为知识库子资源;平台校验 kbMode=text
和 app_id + kb_id 归属后直连 Task Manager,不把索引 HTTP 请求转发给实例 core:
receipt = client.indexer.submit(
"kb_1",
"store_parsed_document",
{"parsed_file_id": "up_xxx", "source_file_id": "asset_xxx"},
task_id="caller-task-001", # 可选;TM 幂等键
task_strategy={"priority": 3, "dedupeKey": "up_xxx"},
)
view = client.indexer.task("kb_1", receipt.taskId) # TM 台账/子账视图 + 平台归属元数据
client.indexer.cancel("kb_1", receipt.taskId, reason="误投")
# 9 个便利方法与 Celery 任务同名,body 与 Celery 载荷同形
client.indexer.patch_chunk("kb_1", {"doc_id": "doc_1", "chunk_index": 3,
"patch": {"content": "修订正文"}})
提交回执只表示 TM 已受理;业务结果看 task() 的 overallStatus / subLedgers,
不要只看 Celery state。store_parsed_document 遇到不同解析文件返回 280016,必须改投
reparse_document;查询/取消按平台归属表收口,跨应用访问返回 100404。
错误码:200021 受理失败、200022 取消失败、200023 索引任务面未启用、
509002 TM 不可达/回执超时;280001~280017 与 509102 来自 indexer worker。
Wiki / 图谱(知识库子资源)
Wiki(W 域)与图谱(G 域)是知识库子资源,路径挂在 /api/v1/knowledge-bases/{kbId} 下,共用知识库读写门禁:
from ikc_sdk.core.api.wiki.build import WikiBuildRequest
client.wiki.tree("kb_1", page=1, page_size=20) # W-01 页面树(根节点分页)
client.wiki.page("kb_1", stable_key="部署手册") # W-02 页面详情(stableKey / pageId 二选一)
client.wiki.export("kb_1", format="jsonl") # W-05 导出(只导出可见页)
client.wiki.build("kb_1", WikiBuildRequest( # W-06 同步:返回落地计数
docId="doc_1", markdown="# 标题\n正文",
))
job = client.wiki.build("kb_1", {"docId": "doc_1", "markdown": "# 标题", "async": True}) # W-06 异步
job = client.wiki.job("kb_1", job.jobId) # W-07 轮询至 status 终态
# W-08~W-19 人工修正(写接口):乐观锁 If-Match / 幂等 Idempotency-Key 可按关键字传入
client.wiki.page_patch("kb_1", "wiki_1", {"title": "新标题", "reason": "标题被截断"},
if_match="12") # W-08 字段级 patch
client.wiki.page_retire("kb_1", "wiki_1", "同名重复页") # W-13 软删(retired)
client.wiki.corrections_apply("kb_1", {"corrections": [ # W-16 修正包(dryRun 回 diff)
{"op": "page.retire", "target": "wiki_2", "reason": "垃圾页"},
], "dryRun": True})
client.wiki.revisions("kb_1", page=1, page_size=20) # W-17 修订列表
client.wiki.revision_revert("kb_1", "wrev_1", "误操作回退") # W-18 回滚
client.wiki.submit_review("kb_1", "wiki_1", comment="请审核") # W-19 提交发布审核
client.wiki.review_action("kb_1", "flow_1", "approve", comment="通过") # W-19 审核动作
client.graph.nodes("kb_1", page=1, page_size=20, entity_type="ORG") # G-02 实体
client.graph.edges("kb_1", relation_type="WORKS_AT") # G-03 关系
client.graph.export("kb_1", format="json") # G-05 导出(北向只有 json / jsonl)
client.graph.search("kb_1", query="中国电信", top_k=3) # G-04c 图内检索(先找实体 id)
client.graph.neighbors("kb_1", entity_id="ent_1", depth=1) # G-04a 1 跳邻域
client.graph.paths("kb_1", source_entity_id="ent_1", # G-04b 两实体最短路径
target_entity_id="ent_2", max_depth=3)
命令行(CLI)
安装后可用 ikc-op(或 python -m ikc_open_platform_sdk.cli):
export OPEN_PLATFORM_BASE_URL=http://localhost:18000
export OPEN_PLATFORM_API_KEY=<app-api-key>
ikc-op kb-query --page 1 --page-size 20
ikc-op kb-get kb_10001
ikc-op search-query --query "IKC 平台" --kb-id kb_10001 --top-k 5
ikc-op search-v2 --query "IKC 平台" --kb-ids '["kb_10001"]' --top-k 10 # Search V2(D-03)
ikc-op indexer-submit --kb-id kb_10001 --task store_parsed_document --body '{"parsed_file_id":"up_xxx"}'
ikc-op indexer-task --kb-id kb_10001 --task-id idxt_xxx
ikc-op indexer-cancel --kb-id kb_10001 --task-id idxt_xxx --reason '误投'
ikc-op wiki-stat --kb-id kb_10001
ikc-op wiki-build --kb-id kb_10001 --doc-id doc_1 --markdown-file ./doc.md --async
ikc-op wiki-page-patch --kb-id kb_10001 --page-id wiki_1 --payload '{"title":"新标题","reason":"标题被截断"}' --if-match 12
ikc-op wiki-page-retire --kb-id kb_10001 --page-id wiki_1 --reason '同名重复页'
ikc-op wiki-corrections-apply --kb-id kb_10001 --payload '{"corrections":[{"op":"page.retire","target":"wiki_2","reason":"垃圾页"}],"dryRun":true}'
ikc-op wiki-revisions --kb-id kb_10001 --page 1 --page-size 20
ikc-op wiki-review-action --kb-id kb_10001 --flow-id flow_1 --action approve --comment '通过'
ikc-op graph-nodes --kb-id kb_10001 --type ORG --page-size 50
ikc-op sys-catalog # 免认证系统路由
退出码:0 成功;1 业务错误;2 未认证(100401);3 无权限(100403);5 占位未实现(501001);6 传输层错误。
环境变量与全局选项:OPEN_PLATFORM_BASE_URL / --base-url、OPEN_PLATFORM_API_KEY / --api-key、
--timeout、OPEN_PLATFORM_EXTRA_HEADERS / --extra-headers(JSON 对象)。平台 AUTH_MODE=static /
gateway_header 时业务接口要求身份头,靠 --extra-headers 发
{"X-User-Id":"u_1","X-Tenant-Id":"t_1"}(经平台自带 HAProxy 时同发 X-Auth-User-Id / X-Auth-Tenant-Id),
实例路由头 X-Ikc-Instance-Id 也走这里;缺身份头会回 100401。
MCP Server(stdio)
安装后可用 ikc-op-mcp(或 python -m ikc_open_platform_sdk.mcp --transport stdio),向 MCP 客户端暴露
85 个工具(kb_* / doc_* / parse_* / indexer_* / search_* / wiki_【含 W-08~W-19 写面】/
graph_ / flash_* / sys_*)。索引任务入口为 indexer_submit / indexer_task / indexer_cancel;
仅需 Python 标准库(NDJSON JSON-RPC 2.0)。
测试
python -m pytest sdk/python/tests -q
2026-10-31 本地构建
0.16.0 精确依赖 ikc-sdk-lib==0.39.0;普通应用 SDK 不提供模型管理权限,管理员使用平台
/admin/model-configs。本次构建 wheel/sdist,产物在 sdk/python/dist/。
OpenPlatformServiceClient 使用应用 API Key 调用 grant introspection 与 account result;不会自动重试写请求。
Metadata
Release files for ikc-open-platform-sdk 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ikc_open_platform_sdk-0.16.0.tar.gz | 66.8 kB | Without provenance | Details for ikc_open_platform_sdk-0.16.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ikc_open_platform_sdk-0.16.0-py3-none-any.whl | Python 3 | none | any | Details for ikc_open_platform_sdk-0.16.0-py3-none-any.whl |
Total release size: 122.8 kB
Release files / ikc_open_platform_sdk-0.16.0.tar.gz
| Download URL | ikc_open_platform_sdk-0.16.0.tar.gz |
|---|---|
| Size | 66.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7956d17ba7a906656837b49dffbe2e5cf6d40ebba61047c7f048f64002ca9e8
|
|
BLAKE2b-256 checksum How to use checksums |
3d0174fa038085fd6446cb56d828580808c527321221910a1cf78e19eb6510a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / ikc_open_platform_sdk-0.16.0-py3-none-any.whl
| Download URL | ikc_open_platform_sdk-0.16.0-py3-none-any.whl |
|---|---|
| Size | 56.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ebe13bbcb2770fb04541f84ed949c4a760de50211c47750e646b5761c2f8f25
|
|
BLAKE2b-256 checksum How to use checksums |
ee2f4f2862986ec921081607de4a5aae71a862c8da6b2e6b23a68943ece1e1a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for ikc-open-platform-sdk 0.16.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.