JEV API 快速开始
Jev API 教程:完成第一次类型化请求
使用 cURL 调用 TypeSafe Jev API,理解 state 与 questions 请求结构,读取 Choice、Score、Noul 结果,并加入安全兜底。
1. 获取密钥并仅保存在服务端
在 TypeSafe Console 创建 API Key,并保存到 TYPESAFE_API_KEY 环境变量。不要把密钥写进浏览器 JavaScript、公开仓库、截图或交给模型判断的 state。
export TYPESAFE_API_KEY="your-api-key" 2. 发送最小但完整的请求
请求需要 model、作为证据的 state,以及带名称的 questions。先用一个边界清晰的 Choice,这样输入契约和返回结果都容易核对。
curl -X POST https://api.typesafe.ai/v1/systemone -H "Authorization: Bearer $TYPESAFE_API_KEY" -H "Content-Type: application/json" -d @- <<'EOF'
{
"model": "jev-latest",
"state": {
"message": "Checkout returns HTTP 500 after payment."
},
"questions": {
"route": {
"type": "choice",
"instructions": "Which team should handle this request?",
"criteria": {
"billing": "Charges, invoices, or subscriptions",
"technical": "Bugs, APIs, or integrations",
"human": "Ambiguous or sensitive cases"
}
}
}
}
EOF 3. 读取类型化响应
答案位于你提供的问题 ID 下。Choice 返回胜出选项、每个选项的概率和 confidence;Score 返回有序量表上的位置;Noul 返回 P(true),没有单独的 confidence 字段。
{
"model": "jev-1.13.0",
"answers": {
"route": {
"type": "choice",
"choice": "technical",
"confidence": 0.78,
"probabilities": {
"technical": 0.85,
"billing": 0.10,
"human": 0.05
}
}
}
} 4. 把答案接入安全决策路径
进入业务分支前先校验响应结构与选项键。副作用继续由普通代码控制,高风险动作采用更严格的阈值,并区分网络失败与“模型给出了有效但不确定的结果”。
const allowed = new Set(['billing', 'technical', 'human']);
const route = response.answers?.route;
if (!route || !allowed.has(route.choice)) throw new Error('Invalid response');
if (route.confidence < REVIEW_THRESHOLD) return enqueueHumanReview(route);
return suggestRoute(route.choice); // keep irreversible actions behind confirmation 5. 增加问题但不要隐藏策略
针对同一 state 的多个问题可以一次发送,并且彼此独立评估。把复合判断拆成小问题,再用可见、可版本化的业务规则在代码中组合答案。