跑通第一个 Jev 请求:两条路都能走
只做文字判断,官方接口和 OpenRouter 都行;要看图只能走官方接口。
先给结论
只做文字判断,官方接口和 OpenRouter 都能跑通,效果一致。看图只能走官方接口,那条路另写一篇。
官方接口三字段搞定
接口地址 POST https://api.typesafe.ai/v1/systemone,请求头带 Authorization: Bearer <key>。key 在 https://console.typesafe.ai/keys 申请。
请求体三个字段:
model:写"jev-latest"拿最新版本。state(上下文状态):要判断的内容,可以是字符串、JSON 对象或数组。questions:题目表,键名自己起,答案按同样的键名返回。
用下面这段 curl 试一下,题目里一道 Noul(是非题)、一道 Choice(选择题):
curl https://api.typesafe.ai/v1/systemone \
-H "Authorization: Bearer $TYPESAFE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "jev-latest",
"state": "这个订单能今天发货吗?我明天一早出差。",
"questions": {
"is_urging": {
"type": "noul",
"instructions": "Is the customer asking us to ship faster?"
},
"department": {
"type": "choice",
"instructions": "Which team should handle this message?",
"criteria": {
"shipping": "Delivery status, delays, shipping speed",
"returns": "Exchanges, wrong or damaged items",
"billing": "Charges, invoices, payment problems"
}
}
}
}'返回长这样,是官方文档里的样例:
{
"model": "jev-1.13.0",
"answers": {
"department": {
"type": "choice",
"choice": "returns",
"confidence": 1.0,
"probabilities": { "shipping": 0.0, "returns": 1.0, "billing": 0.0 }
}
},
"usage": { "input_tokens": 328, "output_tokens": 34 }
}几个关键字段:choice 是选中的项,probabilities 是每个选项的概率,confidence 是置信度(概率分布有多集中),usage 是 token 用量。
Python 用 SDK 跑一次
先装包:pip install typesafe-sdk。SDK 自动读环境变量 TYPESAFE_API_KEY,代码里不用写 key。
from typesafe_sdk import Choice, TypeSafeClient
with TypeSafeClient() as client:
response = client.system_one(
state="这个订单能今天发货吗?我明天一早出差。",
questions={
"department": Choice(
instructions="Which team should handle this message?",
criteria={
"shipping": "Delivery status, delays, shipping speed",
"returns": "Exchanges, wrong or damaged items",
"billing": "Charges, invoices, payment problems",
},
)
},
)
print(response)OpenRouter 同样能跑通
地址换一下:POST https://openrouter.ai/api/alpha/decisions。用 OpenRouter 的 key,模型名写 typesafe/jev-1.14,也可以用别名 ~typesafe/jev-latest。请求体和官方一样。
返回会多两个字段:usage.cost(这次花了多少美元)和 provider(值固定是 TypeSafe)。
我 9 月用 OpenRouter 实测:一次约 1000 个输入 token,花费约 0.00004 美元,耗时 890 到 1040 毫秒。
价格、长度、限流心里有数
输入 0.042 美元 / 百万 token,输出不收钱。
单次请求上下文 64k、单题 32k。需要更长就加请求头 TypeSafe-Danger-Zone-Long-Context: true,可以到 262k,但会更慢、准确率也低一些。限流按组织设置,在开发者控制台查看。
报错码对号入座就行
401 是 key 不对。422 是请求体格式不对,按报错信息修字段名或结构。429 是限流,529 是服务繁忙,这两个按指数退避重试就行。