跳转到正文
文档导航: 决策模型 / 决策记录

决策记录

RightNow AI决策模型决策记录 更新于

本页内容

使用创建决策的 API 密钥读取已存储的决策或其追踪记录。 查询接受以 rnsk_ 开头的密钥,而不是 API keys 页面上的密钥。

已发布的 SDK 0.5.1 在 TypeScript 中提供 client.getDecision(id, options?) 和 client.getDecisionTrace(id, options?)。Python 提供 client.get_decision(id) 和 client.get_decision_trace(id),以及 get_decision_with_response 和 get_decision_trace_with_response。

lookup.ts
import { RightNowClient } from '@rightnowai/rightnow';

const key = process.env.RIGHTNOW_API_KEY;
const id = process.env.DECISION_ID;
if (!key || !id) {
  throw new Error("Set RIGHTNOW_API_KEY and DECISION_ID first.");
}

// Use the API key that created the decision.
const client = new RightNowClient({ apiKey: key, baseURL: 'https://api.rightnowai.co/v1' });

// The stored decision, then its trace.
const stored = await client.getDecision(id);
const trace = await client.getDecisionTrace(id);
console.log(JSON.stringify(stored, null, 2));
console.log(JSON.stringify(trace, null, 2));

查询决策

GET /v1/decision-model/decisions/{id}
已存储的决策。
GET /v1/decision-model/decisions/{id}/trace
关于同一决策的元数据,不含答案内容。

发送创建该决策的有效 API 密钥。同一工作区中的其他密钥无法读取它。

使用 decide 回复中的 id:szd_ 后接 32 个小写十六进制字符。其他任何 id 都会返回 404 decision_not_found。

找到的决策会返回其已存储的状态和回复,与首次返回时完全相同。 旧版回复保留其已存储的答案形式。不要将旧版的 confidence 当作决策概率。

HEAD 返回相同的状态和响应头,但不含正文。两种读取都不接受请求正文或查询参数。没有列表端点。

读取追踪记录

在 /v1/decision-model/ 上,追踪记录的 object 为 decision_model.decision_trace。在旧路径 /v1/system-zero/ 上,它为 system_zero.decision_trace。SDK 的 DecisionTrace 类型描述一个 JSON 对象。 它从已存储的决策中读取以下字段。

id
决策的 ID。
created
决策做出的时间,以 Unix 秒表示。
model
已存储回复中指明的模型。
model_version
已存储回复的 served_by。
route
已存储回复的 context.route。
usage_units
七个用量计数,每个为整数或 null。
refusal_codes
决策中不重复的问题拒绝代码,已排序。
refusal_code
恰好只有一个拒绝代码时为该代码,否则为 null。

在此版本中,以下字段为 null:request_id、render_id、attachments、timings.queue_ms、timings.node_ms、timings.settle_ms、usage_units.cached_media_tokens、idempotency、stream_id和state_version。

缺失的用量计数为 null,绝不是零。追踪记录不包含问题名称、答案值、概率、消息或请求内容。

trace.json
JSON
{
  "object": "decision_model.decision_trace",
  "id": "szd_7c41f0a9b2d84e6c9a1f3b5d7e9c0a2b",
  "request_id": null,
  "created": 1791100800,
  "model": "rightnow-decision-3.0.0",
  "model_version": "rightnow-decision-3.0.0",
  "render_id": null,
  "route": "direct",
  "attachments": null,
  "timings": {
    "queue_ms": null,
    "node_ms": null,
    "settle_ms": null
  },
  "usage_units": {
    "input_tokens": 214,
    "cached_input_tokens": 0,
    "media_tokens": 0,
    "cached_media_tokens": null,
    "long_input_tokens": 0,
    "media_items": 0,
    "thought_tokens": 0
  },
  "refusal_code": null,
  "refusal_codes": [],
  "idempotency": null,
  "stream_id": null,
  "state_version": null
}

可用性与保留期限

发送 decide 时带上 Idempotency-Key。查询只能找到以 Idempotency-Key 存储的决策;请参阅幂等性。

无键的决策、没有查询索引的较早决策以及超出存储限制的回复均不可用。

已存储的决策最多保留 24 小时,其答案或索引可能更早被删除。读取它绝不会延长这段时间。

查询不会运行新的决策,也不收费。但它仍计入你的每分钟请求数。查询索引不保留请求或答案内容的任何副本。

决策 id 不是永久存档。请将你需要的答案保存在自己的存储中。

错误与响应头

两种读取都可能返回以下拒绝。

未知、无键、属于其他密钥或已过期的 id 会在 SDK 中引发 DecisionNotFoundError (404 decision_not_found)。

400 invalid_trace_header
X-Client-Request-Id 为空、不是可打印的 ASCII 或超过 512 个字符。
401 invalid_api_key
密钥缺失、格式错误或未知。
403 auth_error
密钥已被撤销。
403 account_suspended
工作区已被暂停或正在等待访问权限。
404 decision_not_found
id 无效,或者对于此 API 密钥,没有与之匹配的已存储决策。
405 method_not_allowed
方法不是 GET、HEAD 或 OPTIONS。
429 rate_limit_exceeded
来自此密钥、工作区或地址的请求过多。当工作区在一个 UTC 日内回读的已保留答案超过 500 MB 时,也会返回此错误。
503 service_unavailable
查询所读取的某个存储目前无法响应。
503 limiter_unavailable
速率限制目前无法响应。
decision-not-found.json
JSON
{
  "error": {
    "message": "The requested decision is not available.",
    "type": "not_found_error",
    "param": null,
    "code": "decision_not_found",
    "retryable": false
  },
  "request_id": "request-id-from-response"
}

decision_not_found 的 error.retryable 为 false。它不会说明决策是从未存储、已过期、已被删除,还是属于其他密钥。

仅当 error.retryable 为 true 时才重试。等待 Retry-After-Ms(毫秒)或 Retry-After(秒)指定的时间;优先使用 Retry-After-Ms。请参阅错误。

查询与 decide 使用相同的每分钟请求数。其 X-RateLimit-Limit、X-RateLimit-Remaining 和 X-RateLimit-Reset 响应头会报告这些数值;请参阅速率限制。

X-Request-Id 标识的是查询,而不是原始决策。你发送的有效 X-Client-Request-Id 会被原样返回。

查询从不设置 X-RightNow-Idempotent-Replay。每个响应都会发送 Cache-Control: no-store。405 会列出 Allow: GET, HEAD, OPTIONS。