Jev API 教程:10 分钟发出第一次调用

更新于 适用版本 Jev 1.13

你有 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\""
      }
    ]
  }'

每个部分的作用:

部分作用
URLhttps://openrouter.ai/api/v1/chat/completionsOpenRouter 的 OpenAI 兼容端点
AuthorizationBearer $OPENROUTER_API_KEY用环境变量里的 Key 鉴权
Content-Typeapplication/json标准 JSON 请求体
modeltypesafe/jev-1.13Jev 模型 id——确切 slug 以 OpenRouter 模型页为准
messages[0].roleuser单轮提问;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."
}

字段怎么读:

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 字符串,不是字典。

所有人第一次都会踩的三个坑

  1. 401 Unauthorized Key 不在环境里或读错了。在同一个 shell 里打印 os.environ.get("OPENROUTER_API_KEY");如果是 None,说明 export 没生效。
  2. 404 / 未知模型。 slug 写错或过期。回 OpenRouter 模型页核对当前 id——这是第一天最常见的事故。
  3. TypeError: the JSON object must be str... 跳过了对 message content 的 json.loads,或该次调用的 content 不是合法 JSON。做防御性解析,载荷异常时先重试一次再告警。

超出这三个的报错看《Jev 常见报错排查》,选择题和打分题的请求写法在《Jev 三原语》里。想看这个调用在审核管线里的完整用法,读垃圾评论识别那个 case。

本文适用版本 Jev 1.13。

常见问题

第一次调用 Jev 用哪个端点?

主演示渠道是 OpenRouter 的 OpenAI 兼容 chat completions 端点。官方 TypeSafe AI 端点以 typesafe.ai 官方文档为准,不要凭空猜。

model id 传什么?

本教程用 typesafe/jev-1.13,但 slug 会随版本变化——请务必到 OpenRouter 模型页确认确切的 model slug。

为什么第一次调用会报 JSON 错误?

通常是 message content 没有先做 JSON 解析就直接当对象用,或者模型 id 不对。先用 JSON 加载器解析 content,再核对 slug。

继续阅读