Jev API 教程:10 分钟发出第一次调用
你有 API Key,有十分钟——发第一次 Jev 调用真的只需要这些。因为模型的主演示渠道是 OpenRouter 的 OpenAI 兼容端点,请求结构和发给聊天模型的完全一样;变的是返回的东西。本教程给出 curl 和 Python 两个可直接复制的完整调用,逐字段解释,并列出几乎所有人第一次都会踩的三个坑。
TL;DR: 向
https://openrouter.ai/api/v1/chat/completions发 POST,带Authorization: Bearer <key>、Jev 模型 id,以及一个按判断题/选择题/打分题措辞的问题。答案以结构化 JSON——answer、confidence、rationale——出现在标准 OpenAI 兼容响应壳里。把 message content 按 JSON 解析后读字段即可。
请求逐字段解读
第一次调用用判断题——三种原语里最简单的一种:
# Confirm the exact model slug on the OpenRouter model page
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "typesafe/jev-1.13",
"messages": [
{
"role": "user",
"content": "Judgment question: does this comment contain spam? Comment: \"Great post, check my site for cheap meds\""
}
]
}'
每个部分的作用:
| 部分 | 值 | 作用 |
|---|---|---|
| URL | https://openrouter.ai/api/v1/chat/completions | OpenRouter 的 OpenAI 兼容端点 |
Authorization 头 | Bearer $OPENROUTER_API_KEY | 用环境变量里的 Key 鉴权 |
Content-Type | application/json | 标准 JSON 请求体 |
model | typesafe/jev-1.13 | Jev 模型 id——确切 slug 以 OpenRouter 模型页为准 |
messages[0].role | user | 单轮提问;Jev 不是聊天对象 |
messages[0].content | 你的问题 | 按判断/选择/打分措辞,并把待判内容嵌进去 |
注意不需要什么:没有特殊的”判断模式”参数,没有专用端点。题型由 content 的措辞承载。官方 TypeSafe AI 渠道的实际端点和字段,请到 typesafe.ai 官方文档确认。
响应解读
HTTP 响应是标准 OpenAI 兼容壳。里面的 message content 是结构化答案——示例数据(example fixture),正式字段名以官方文档为准:
{
"answer": "yes",
"confidence": 0.97,
"rationale": "The comment promotes an unrelated pharmaceutical site, a classic spam pattern."
}
字段怎么读:
answer——判断题取yes、no或unclear之一;选择题取你列出的选项之一;打分题是数字并附带来源scale。confidence——0 到 1 的分数,可以拿来做分支。低于阈值的就走人工复核。rationale——简短解释。务必记日志,排查问题措辞时省大量时间。
Python 版本
import json, os, requests
resp = requests.post(
"https://openrouter.ai/api/v1/chat/completions",
headers={
"Authorization": f"Bearer {os.environ['OPENROUTER_API_KEY']}",
"Content-Type": "application/json",
},
json={
# Confirm the exact model slug on the OpenRouter model page
"model": "typesafe/jev-1.13",
"messages": [{
"role": "user",
"content": "Judgment question: does this comment contain spam? Comment: \"Great post, check my site for cheap meds\"",
}],
},
timeout=30,
)
resp.raise_for_status()
result = json.loads(resp.json()["choices"][0]["message"]["content"])
print(result["answer"], result["confidence"])
外层 resp.json() 是标准响应壳;解析出的 result 是示例数据(example fixture)——响应形态为示例,正式字段名以官方文档为准。最容易漏的一行是对 message content 做 json.loads(...):它是 JSON 字符串,不是字典。
所有人第一次都会踩的三个坑
401 Unauthorized。 Key 不在环境里或读错了。在同一个 shell 里打印os.environ.get("OPENROUTER_API_KEY");如果是None,说明 export 没生效。404/ 未知模型。 slug 写错或过期。回 OpenRouter 模型页核对当前 id——这是第一天最常见的事故。TypeError: the JSON object must be str...跳过了对 message content 的json.loads,或该次调用的 content 不是合法 JSON。做防御性解析,载荷异常时先重试一次再告警。
超出这三个的报错看《Jev 常见报错排查》,选择题和打分题的请求写法在《Jev 三原语》里。想看这个调用在审核管线里的完整用法,读垃圾评论识别那个 case。
本文适用版本 Jev 1.13。