jev-cli 0.4.1__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jev-cli
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Small dependency-free CLI for TypeSafe Jev
5
5
  Keywords: typesafe,jev,cli,ai
6
6
  License-Expression: MIT
@@ -36,19 +36,17 @@ The `jev` command is useful when application code needs a fast classification or
36
36
 
37
37
  ## Requirements
38
38
 
39
- - Python 3.13 or later
40
39
  - [uv](https://docs.astral.sh/uv/)
41
- - GNU Make
42
- - A TypeSafe API key
40
+ - An API key for the provider you use. The official TypeSafe API is the default.
41
+
42
+ `uv` installs a compatible Python 3.13 or later interpreter when needed.
43
43
 
44
44
  ## Install
45
45
 
46
- Clone the repository and install the command with `uv tool` through the Makefile. This installs `jev` into uv's executable directory and verifies the installed version.
46
+ Install `jev-cli` from PyPI with `uv tool`. This keeps the command in an isolated environment and makes `jev` available on your `PATH`.
47
47
 
48
48
  ```bash
49
- git clone https://github.com/tumf/jev-cli.git
50
- cd jev-cli
51
- make install
49
+ uv tool install jev-cli
52
50
  ```
53
51
 
54
52
  Verify that the command is available:
@@ -60,12 +58,12 @@ jev --version
60
58
  Expected output:
61
59
 
62
60
  ```text
63
- jev 0.4.1
61
+ jev 0.5.0
64
62
  ```
65
63
 
66
64
  ## Authentication
67
65
 
68
- The recommended approach for automation is the `TYPESAFE_API_KEY` environment variable. It takes precedence over the credential file.
66
+ The official TypeSafe API is the default provider. The recommended approach for automation is the `TYPESAFE_API_KEY` environment variable. It takes precedence over the credential file.
69
67
 
70
68
  ```bash
71
69
  export TYPESAFE_API_KEY='your-api-key'
@@ -80,6 +78,50 @@ jev auth status
80
78
  jev auth test
81
79
  ```
82
80
 
81
+ Jev is also available through Vercel AI Gateway and OpenRouter. Select a provider per command with `--provider`, or set `JEV_PROVIDER` for the process. Each provider uses its own API key and default model.
82
+
83
+ | Provider | Option | API key environment variable | Default model |
84
+ |---|---|---|---|
85
+ | TypeSafe official | `official` | `TYPESAFE_API_KEY` | `jev-latest` |
86
+ | Vercel AI Gateway | `vercel` | `AI_GATEWAY_API_KEY` | `typesafe-ai/jev` |
87
+ | OpenRouter | `openrouter` | `OPENROUTER_API_KEY` | `typesafe/jev-1.13` |
88
+ | Jev-compatible proxy | `custom` | `JEV_API_KEY` | `JEV_MODEL` or `jev-latest` |
89
+
90
+ Store and test a provider-specific key without exposing it in shell history:
91
+
92
+ ```bash
93
+ jev auth set --provider vercel
94
+ jev auth test --provider vercel
95
+
96
+ jev auth set --provider openrouter
97
+ jev auth test --provider openrouter
98
+ ```
99
+
100
+ Run the same judgment through another provider:
101
+
102
+ ```bash
103
+ jev noul \
104
+ --provider openrouter \
105
+ --question 'Does this message express urgency?' \
106
+ --state 'Please restore service today.' \
107
+ --value
108
+ ```
109
+
110
+ Omitting `--provider` continues to use the official TypeSafe API. `--model` can override the provider's default model.
111
+
112
+ For a proxy that implements the native Jev request and response contract, select `custom` and configure its endpoint separately. This keeps proxy credentials isolated from the built-in providers.
113
+
114
+ ```bash
115
+ export JEV_PROVIDER=custom
116
+ export JEV_ENDPOINT='https://proxy.example.com/v1/systemone'
117
+ export JEV_API_KEY='your-proxy-api-key'
118
+ export JEV_MODEL='jev-latest' # optional
119
+
120
+ jev noul -q 'Is this urgent?' -s 'Restore service today.' --value
121
+ ```
122
+
123
+ `--endpoint` can replace `JEV_ENDPOINT` for one command. The CLI sends `JEV_API_KEY` to that endpoint as a bearer token, so use only a trusted HTTPS endpoint.
124
+
83
125
  For non-interactive automation, piping the key to `jev auth set` remains supported.
84
126
 
85
127
  `auth status` reports only whether a key is available. `auth test` sends a minimal request to Jev and verifies that the key is accepted. Neither command prints the key.
@@ -295,7 +337,7 @@ An error is emitted as JSON on stderr:
295
337
 
296
338
  The `jev` command is a thin client for focused System One judgments. It does not generate prose, perform arithmetic, compare dates, or replace application-level validation. Keep deterministic work in code and use Jev for semantic judgments.
297
339
 
298
- The CLI sends the supplied state and questions to the TypeSafe API. Do not submit data that your organization is not permitted to send to that service.
340
+ The CLI sends the supplied state and questions to the selected provider. Do not submit data that your organization is not permitted to send to that service.
299
341
 
300
342
  ## License
301
343
 
@@ -18,19 +18,17 @@ The `jev` command is useful when application code needs a fast classification or
18
18
 
19
19
  ## Requirements
20
20
 
21
- - Python 3.13 or later
22
21
  - [uv](https://docs.astral.sh/uv/)
23
- - GNU Make
24
- - A TypeSafe API key
22
+ - An API key for the provider you use. The official TypeSafe API is the default.
23
+
24
+ `uv` installs a compatible Python 3.13 or later interpreter when needed.
25
25
 
26
26
  ## Install
27
27
 
28
- Clone the repository and install the command with `uv tool` through the Makefile. This installs `jev` into uv's executable directory and verifies the installed version.
28
+ Install `jev-cli` from PyPI with `uv tool`. This keeps the command in an isolated environment and makes `jev` available on your `PATH`.
29
29
 
30
30
  ```bash
31
- git clone https://github.com/tumf/jev-cli.git
32
- cd jev-cli
33
- make install
31
+ uv tool install jev-cli
34
32
  ```
35
33
 
36
34
  Verify that the command is available:
@@ -42,12 +40,12 @@ jev --version
42
40
  Expected output:
43
41
 
44
42
  ```text
45
- jev 0.4.1
43
+ jev 0.5.0
46
44
  ```
47
45
 
48
46
  ## Authentication
49
47
 
50
- The recommended approach for automation is the `TYPESAFE_API_KEY` environment variable. It takes precedence over the credential file.
48
+ The official TypeSafe API is the default provider. The recommended approach for automation is the `TYPESAFE_API_KEY` environment variable. It takes precedence over the credential file.
51
49
 
52
50
  ```bash
53
51
  export TYPESAFE_API_KEY='your-api-key'
@@ -62,6 +60,50 @@ jev auth status
62
60
  jev auth test
63
61
  ```
64
62
 
63
+ Jev is also available through Vercel AI Gateway and OpenRouter. Select a provider per command with `--provider`, or set `JEV_PROVIDER` for the process. Each provider uses its own API key and default model.
64
+
65
+ | Provider | Option | API key environment variable | Default model |
66
+ |---|---|---|---|
67
+ | TypeSafe official | `official` | `TYPESAFE_API_KEY` | `jev-latest` |
68
+ | Vercel AI Gateway | `vercel` | `AI_GATEWAY_API_KEY` | `typesafe-ai/jev` |
69
+ | OpenRouter | `openrouter` | `OPENROUTER_API_KEY` | `typesafe/jev-1.13` |
70
+ | Jev-compatible proxy | `custom` | `JEV_API_KEY` | `JEV_MODEL` or `jev-latest` |
71
+
72
+ Store and test a provider-specific key without exposing it in shell history:
73
+
74
+ ```bash
75
+ jev auth set --provider vercel
76
+ jev auth test --provider vercel
77
+
78
+ jev auth set --provider openrouter
79
+ jev auth test --provider openrouter
80
+ ```
81
+
82
+ Run the same judgment through another provider:
83
+
84
+ ```bash
85
+ jev noul \
86
+ --provider openrouter \
87
+ --question 'Does this message express urgency?' \
88
+ --state 'Please restore service today.' \
89
+ --value
90
+ ```
91
+
92
+ Omitting `--provider` continues to use the official TypeSafe API. `--model` can override the provider's default model.
93
+
94
+ For a proxy that implements the native Jev request and response contract, select `custom` and configure its endpoint separately. This keeps proxy credentials isolated from the built-in providers.
95
+
96
+ ```bash
97
+ export JEV_PROVIDER=custom
98
+ export JEV_ENDPOINT='https://proxy.example.com/v1/systemone'
99
+ export JEV_API_KEY='your-proxy-api-key'
100
+ export JEV_MODEL='jev-latest' # optional
101
+
102
+ jev noul -q 'Is this urgent?' -s 'Restore service today.' --value
103
+ ```
104
+
105
+ `--endpoint` can replace `JEV_ENDPOINT` for one command. The CLI sends `JEV_API_KEY` to that endpoint as a bearer token, so use only a trusted HTTPS endpoint.
106
+
65
107
  For non-interactive automation, piping the key to `jev auth set` remains supported.
66
108
 
67
109
  `auth status` reports only whether a key is available. `auth test` sends a minimal request to Jev and verifies that the key is accepted. Neither command prints the key.
@@ -277,7 +319,7 @@ An error is emitted as JSON on stderr:
277
319
 
278
320
  The `jev` command is a thin client for focused System One judgments. It does not generate prose, perform arithmetic, compare dates, or replace application-level validation. Keep deterministic work in code and use Jev for semantic judgments.
279
321
 
280
- The CLI sends the supplied state and questions to the TypeSafe API. Do not submit data that your organization is not permitted to send to that service.
322
+ The CLI sends the supplied state and questions to the selected provider. Do not submit data that your organization is not permitted to send to that service.
281
323
 
282
324
  ## License
283
325
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "jev-cli"
3
- version = "0.4.1"
3
+ version = "0.5.0"
4
4
  description = "Small dependency-free CLI for TypeSafe Jev"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -23,13 +23,13 @@ Install this bundled skill with `jev install-skills`. Add `--global` for the use
23
23
  ## Workflow
24
24
 
25
25
  1. Confirm the command is installed with `jev --version`. If it is missing, install from the repository root with `make install`. Completion: `jev --version` exits successfully.
26
- 2. Confirm key availability with `jev auth status`, then use `jev auth test` when API validity must be verified. If absent or invalid, ask the user to configure a TypeSafe API key; never print, infer, or commit it. Completion: the selected command returns `ok: true`.
26
+ 2. Confirm key availability with `jev auth status`, then use `jev auth test` when API validity must be verified. If absent or invalid, ask the user to configure the selected provider's API key; never print, infer, or commit it. Completion: the selected command returns `ok: true`.
27
27
  3. Choose the narrowest question type:
28
28
  - `noul` for a yes/no probability.
29
29
  - `choice` for one key from explicit options.
30
30
  - `score` for an ordered numeric level.
31
31
  - `run` for a complete request object or multiple questions.
32
- 4. Send only the state needed for the judgment. TypeSafe receives the submitted state and questions, so do not send secrets or private data without explicit authorization.
32
+ 4. Send only the state needed for the judgment. The selected provider receives the submitted state and questions, so do not send secrets or private data without explicit authorization.
33
33
  5. Use default JSON output for automation. Use `--value` only when a scalar is sufficient. Completion: parse the result and account for the exit code before acting on it.
34
34
 
35
35
  Read [references/cli.md](references/cli.md) for copy-paste command forms, inputs, output controls, and exit codes.
@@ -40,7 +40,8 @@ Read [references/cli.md](references/cli.md) for copy-paste command forms, inputs
40
40
  - Give `score` levels in ascending order; the returned number may be fractional.
41
41
  - Use `--json-state` only when the state must retain JSON structure.
42
42
  - Use `@file` or stdin for long input instead of embedding it in shell arguments.
43
- - Set `TYPESAFE_API_KEY` only for process-level overrides. The normal credential store remains under the user's config directory.
43
+ - The official TypeSafe API is the default. Use `--provider vercel`, `--provider openrouter`, or `--provider custom` only when the caller selects another provider.
44
+ - Use the provider-specific environment variable only for process-level overrides: `TYPESAFE_API_KEY`, `AI_GATEWAY_API_KEY`, `OPENROUTER_API_KEY`, or `JEV_API_KEY`. A custom provider also requires `JEV_ENDPOINT`; `JEV_MODEL` is optional. The normal credential store remains under the user's config directory.
44
45
  - Treat model output as a structured judgment, not verified fact. Keep consequential actions behind the caller's own validation and authorization rules.
45
46
 
46
47
  ## Common pitfalls
@@ -28,10 +28,35 @@ printf '%s' "$TYPESAFE_API_KEY" | jev auth set
28
28
 
29
29
  Resolution order:
30
30
 
31
- 1. `TYPESAFE_API_KEY`
31
+ 1. The selected provider's environment variable: `TYPESAFE_API_KEY`, `AI_GATEWAY_API_KEY`, `OPENROUTER_API_KEY`, or `JEV_API_KEY`
32
32
  2. `$XDG_CONFIG_HOME/jev-cli/credentials.json`
33
33
  3. `~/.config/jev-cli/credentials.json`
34
34
 
35
+ The official TypeSafe API is selected by default. Vercel AI Gateway and OpenRouter can be selected per command:
36
+
37
+ ```bash
38
+ jev auth set --provider vercel
39
+ jev auth test --provider vercel
40
+ jev noul --provider vercel -q 'Is this urgent?' -s 'Restore service today.' --value
41
+
42
+ jev auth set --provider openrouter
43
+ jev auth test --provider openrouter
44
+ jev noul --provider openrouter -q 'Is this urgent?' -s 'Restore service today.' --value
45
+ ```
46
+
47
+ `JEV_PROVIDER` changes the default for evaluation commands. Authentication commands require an explicit `--provider` so credentials are not accidentally stored or tested against the wrong service.
48
+
49
+ For a proxy implementing the native Jev contract:
50
+
51
+ ```bash
52
+ JEV_PROVIDER=custom \
53
+ JEV_ENDPOINT='https://proxy.example.com/v1/systemone' \
54
+ JEV_API_KEY='your-proxy-api-key' \
55
+ jev noul -q 'Is this urgent?' -s 'Restore service today.' --value
56
+ ```
57
+
58
+ Set `JEV_MODEL` or pass `--model` when the proxy requires a different model name. Use only a trusted HTTPS endpoint because the custom bearer key is sent to it.
59
+
35
60
  ## Typed questions
36
61
 
37
62
  Use `-q` for `--question` and `-s` for `--state` when a shorter command is useful. `--value` has no short form.
@@ -15,7 +15,29 @@ import urllib.request
15
15
  from pathlib import Path
16
16
  from typing import Any
17
17
 
18
- API_URL = "https://api.typesafe.ai/v1/systemone"
18
+ PROVIDERS = {
19
+ "official": {
20
+ "endpoint": "https://api.typesafe.ai/v1/systemone",
21
+ "key_env": "TYPESAFE_API_KEY",
22
+ "model": "jev-latest",
23
+ },
24
+ "vercel": {
25
+ "endpoint": "https://ai-gateway.vercel.sh/v4/ai/evaluation-model",
26
+ "key_env": "AI_GATEWAY_API_KEY",
27
+ "model": "typesafe-ai/jev",
28
+ },
29
+ "openrouter": {
30
+ "endpoint": "https://openrouter.ai/api/alpha/decisions",
31
+ "key_env": "OPENROUTER_API_KEY",
32
+ "model": "typesafe/jev-1.13",
33
+ },
34
+ "custom": {
35
+ "endpoint": None,
36
+ "key_env": "JEV_API_KEY",
37
+ "model": "jev-latest",
38
+ },
39
+ }
40
+ API_URL = PROVIDERS["official"]["endpoint"]
19
41
  CREDENTIALS_FILE = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "jev-cli" / "credentials.json"
20
42
  BUNDLED_SKILLS = Path(__file__).with_name("bundled_skills")
21
43
  INSTALL_MARKER = ".jev-cli-managed"
@@ -27,31 +49,52 @@ class CliError(Exception):
27
49
  self.exit_code = exit_code
28
50
 
29
51
 
30
- def api_key() -> str:
31
- if value := os.environ.get("TYPESAFE_API_KEY"):
52
+ def api_key(provider: str = "official") -> str:
53
+ config = PROVIDERS[provider]
54
+ if value := os.environ.get(config["key_env"]):
32
55
  return value
33
56
  try:
34
57
  data = json.loads(CREDENTIALS_FILE.read_text())
35
- value = data["api_key"]
58
+ providers = data.get("providers", {})
59
+ if not isinstance(providers, dict):
60
+ raise TypeError("providers must be an object")
61
+ value = providers.get(provider)
62
+ if value is None and provider == "official":
63
+ value = data["api_key"]
36
64
  except (OSError, json.JSONDecodeError, KeyError, TypeError) as exc:
37
65
  raise CliError(
38
- "TypeSafe API key is not stored; run: jev auth set",
66
+ f"{provider} API key is not stored; run: jev auth set --provider {provider}",
39
67
  3,
40
68
  ) from exc
41
69
  if not isinstance(value, str) or not value:
42
- raise CliError("stored TypeSafe API key is empty", 3)
70
+ raise CliError(f"stored {provider} API key is empty", 3)
43
71
  return value
44
72
 
45
73
 
46
- def set_api_key() -> None:
47
- value = getpass.getpass("TypeSafe API key: ").strip() if sys.stdin.isatty() else sys.stdin.read().strip()
74
+ def set_api_key(provider: str = "official") -> None:
75
+ label = "TypeSafe" if provider == "official" else provider
76
+ value = getpass.getpass(f"{label} API key: ").strip() if sys.stdin.isatty() else sys.stdin.read().strip()
48
77
  if not value:
49
78
  raise CliError("API key is empty")
50
79
  CREDENTIALS_FILE.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
80
+ try:
81
+ data = json.loads(CREDENTIALS_FILE.read_text())
82
+ except FileNotFoundError:
83
+ data = {}
84
+ except (OSError, json.JSONDecodeError) as exc:
85
+ raise CliError("stored credential file is invalid; refusing to overwrite it", 3) from exc
86
+ if not isinstance(data, dict):
87
+ raise CliError("stored credential file must contain an object", 3)
88
+ providers = data.setdefault("providers", {})
89
+ if not isinstance(providers, dict):
90
+ raise CliError("stored credential file has an invalid providers object", 3)
91
+ if old_key := data.pop("api_key", None):
92
+ providers.setdefault("official", old_key)
93
+ providers[provider] = value
51
94
  try:
52
95
  fd, temporary = tempfile.mkstemp(dir=CREDENTIALS_FILE.parent)
53
96
  with os.fdopen(fd, "w") as file:
54
- json.dump({"api_key": value}, file)
97
+ json.dump(data, file)
55
98
  file.write("\n")
56
99
  os.chmod(temporary, 0o600)
57
100
  os.replace(temporary, CREDENTIALS_FILE)
@@ -137,14 +180,69 @@ def load_request(path: str) -> dict[str, Any]:
137
180
  return payload
138
181
 
139
182
 
140
- def call(payload: dict[str, Any], endpoint: str) -> dict[str, Any]:
183
+ def provider_request(payload: dict[str, Any], provider: str) -> tuple[dict[str, Any], dict[str, str]]:
184
+ payload = dict(payload)
185
+ headers: dict[str, str] = {}
186
+ if provider == "vercel":
187
+ payload["questions"] = {
188
+ name: {**question, "type": "boolean" if question.get("type") == "noul" else question.get("type")}
189
+ for name, question in payload["questions"].items()
190
+ }
191
+ headers = {
192
+ "ai-gateway-protocol-version": "0.0.1",
193
+ "ai-gateway-auth-method": "api-key",
194
+ "ai-evaluation-model-specification-version": "4",
195
+ "ai-model-id": payload.pop("model"),
196
+ }
197
+ return payload, headers
198
+
199
+
200
+ def normalize_response(result: dict[str, Any], provider: str) -> dict[str, Any]:
201
+ if provider != "vercel":
202
+ return result
203
+ result = dict(result)
204
+ result["answers"] = {
205
+ name: (
206
+ {"noul": answer["probability"], **{k: v for k, v in answer.items() if k not in ("type", "probability")}}
207
+ if answer.get("type") == "boolean"
208
+ else {k: v for k, v in answer.items() if k != "type"}
209
+ )
210
+ for name, answer in result["answers"].items()
211
+ }
212
+ return result
213
+
214
+
215
+ def provider_endpoint(provider: str, override: str | None = None) -> str:
216
+ if override:
217
+ return override
218
+ if provider == "custom":
219
+ if endpoint := os.environ.get("JEV_ENDPOINT"):
220
+ return endpoint
221
+ raise CliError("custom provider requires JEV_ENDPOINT or --endpoint", 2)
222
+ if provider == "official" and (legacy := os.environ.get("TYPESAFE_API_URL")):
223
+ return legacy
224
+ endpoint = PROVIDERS[provider]["endpoint"]
225
+ if not isinstance(endpoint, str):
226
+ raise CliError(f"{provider} provider endpoint is not configured", 2)
227
+ return endpoint
228
+
229
+
230
+ def provider_model(provider: str) -> str:
231
+ if provider == "custom":
232
+ return os.environ.get("JEV_MODEL", PROVIDERS[provider]["model"])
233
+ return PROVIDERS[provider]["model"]
234
+
235
+
236
+ def call(payload: dict[str, Any], endpoint: str, provider: str = "official") -> dict[str, Any]:
237
+ payload, provider_headers = provider_request(payload, provider)
141
238
  request = urllib.request.Request(
142
239
  endpoint,
143
240
  data=json.dumps(payload, ensure_ascii=False).encode(),
144
241
  headers={
145
- "Authorization": f"Bearer {api_key()}",
242
+ "Authorization": f"Bearer {api_key(provider)}",
146
243
  "Content-Type": "application/json",
147
- "User-Agent": "jev-cli/0.4.1",
244
+ "User-Agent": "jev-cli/0.5.0",
245
+ **provider_headers,
148
246
  },
149
247
  method="POST",
150
248
  )
@@ -163,16 +261,23 @@ def call(payload: dict[str, Any], endpoint: str) -> dict[str, Any]:
163
261
  raise CliError(f"API connection failed: {exc}", 4) from exc
164
262
  if not isinstance(result, dict):
165
263
  raise CliError("API returned a non-object response", 1)
166
- return result
264
+ return normalize_response(result, provider)
167
265
 
168
266
 
169
267
  def common_parser() -> argparse.ArgumentParser:
170
268
  parser = argparse.ArgumentParser(add_help=False)
171
- parser.add_argument("--model", default="jev-latest", help="model name (default: jev-latest)")
269
+ default_provider = os.environ.get("JEV_PROVIDER", "official")
270
+ parser.add_argument(
271
+ "--provider",
272
+ choices=PROVIDERS,
273
+ default=default_provider,
274
+ help="API provider (default: official)",
275
+ )
276
+ parser.add_argument("--model", help="model name (default depends on provider)")
172
277
  parser.add_argument("--json-state", action="store_true", help="parse state as JSON")
173
278
  parser.add_argument("--pretty", action="store_true", help="pretty-print JSON")
174
279
  parser.add_argument("--value", action="store_true", help="print only the primary answer value")
175
- parser.add_argument("--endpoint", default=os.environ.get("TYPESAFE_API_URL", API_URL), help=argparse.SUPPRESS)
280
+ parser.add_argument("--endpoint", help=argparse.SUPPRESS)
176
281
  return parser
177
282
 
178
283
 
@@ -181,15 +286,19 @@ def parser() -> argparse.ArgumentParser:
181
286
  prog="jev",
182
287
  description="Evaluate text or JSON with TypeSafe Jev. Uses its own local credential store.",
183
288
  )
184
- root.add_argument("--version", action="version", version="jev 0.4.1")
289
+ root.add_argument("--version", action="version", version="jev 0.5.0")
185
290
  sub = root.add_subparsers(dest="command", required=True)
186
291
  common = common_parser()
187
292
 
188
293
  auth = sub.add_parser("auth", help="manage the API key in the Jev credential store")
189
294
  auth_sub = auth.add_subparsers(dest="auth_command", required=True)
190
- auth_sub.add_parser("set", help="store an API key from a hidden prompt or stdin")
191
- auth_sub.add_parser("status", help="check whether an API key is stored")
192
- auth_sub.add_parser("test", help="connect to Jev and verify the API key")
295
+ for name, help_text in (
296
+ ("set", "store an API key from a hidden prompt or stdin"),
297
+ ("status", "check whether an API key is stored"),
298
+ ("test", "connect to Jev and verify the API key"),
299
+ ):
300
+ auth_command = auth_sub.add_parser(name, help=help_text)
301
+ auth_command.add_argument("--provider", choices=PROVIDERS, default="official")
193
302
 
194
303
  skills = sub.add_parser("install-skills", help="install bundled agent skills")
195
304
  skills.add_argument("-g", "--global", dest="global_install", action="store_true", help="install in the user home")
@@ -217,7 +326,7 @@ def parser() -> argparse.ArgumentParser:
217
326
  def request_for(args: argparse.Namespace) -> tuple[dict[str, Any], str | None]:
218
327
  if args.command == "run":
219
328
  payload = load_request(args.request)
220
- payload.setdefault("model", args.model)
329
+ payload.setdefault("model", args.model or provider_model(args.provider))
221
330
  return payload, None
222
331
 
223
332
  question: dict[str, Any] = {"type": args.command, "instructions": args.question}
@@ -227,7 +336,7 @@ def request_for(args: argparse.Namespace) -> tuple[dict[str, Any], str | None]:
227
336
  question["criteria"] = args.level
228
337
  payload = {
229
338
  "state": state_value(args.state, args.json_state),
230
- "model": args.model,
339
+ "model": args.model or provider_model(args.provider),
231
340
  "questions": {"answer": question},
232
341
  }
233
342
  return payload, args.command
@@ -245,13 +354,13 @@ def main() -> int:
245
354
  args = parser().parse_args()
246
355
  if args.command == "auth":
247
356
  if args.auth_command == "set":
248
- set_api_key()
357
+ set_api_key(args.provider)
249
358
  print(json.dumps({"ok": True, "stored": True, "store": str(CREDENTIALS_FILE)}))
250
359
  elif args.auth_command == "test":
251
360
  result = call(
252
361
  {
253
362
  "state": "authentication test",
254
- "model": "jev-latest",
363
+ "model": provider_model(args.provider),
255
364
  "questions": {
256
365
  "answer": {
257
366
  "type": "noul",
@@ -259,18 +368,21 @@ def main() -> int:
259
368
  }
260
369
  },
261
370
  },
262
- API_URL,
371
+ provider_endpoint(args.provider),
372
+ args.provider,
263
373
  )
264
374
  print(json.dumps({"ok": True, "valid": True, "model": result.get("model")}))
265
375
  else:
266
- api_key()
376
+ api_key(args.provider)
267
377
  print(json.dumps({"ok": True, "stored": True, "store": str(CREDENTIALS_FILE)}))
268
378
  return 0
269
379
  if args.command == "install-skills":
270
380
  print(json.dumps(install_skills(global_install=args.global_install, claude=args.claude)))
271
381
  return 0
382
+ if args.provider not in PROVIDERS:
383
+ raise CliError(f"invalid JEV_PROVIDER: {args.provider}")
272
384
  payload, kind = request_for(args)
273
- result = call(payload, args.endpoint)
385
+ result = call(payload, provider_endpoint(args.provider, args.endpoint), args.provider)
274
386
  if args.value:
275
387
  print(primary_value(result, kind))
276
388
  else:
@@ -23,13 +23,13 @@ Install this bundled skill with `jev install-skills`. Add `--global` for the use
23
23
  ## Workflow
24
24
 
25
25
  1. Confirm the command is installed with `jev --version`. If it is missing, install from the repository root with `make install`. Completion: `jev --version` exits successfully.
26
- 2. Confirm key availability with `jev auth status`, then use `jev auth test` when API validity must be verified. If absent or invalid, ask the user to configure a TypeSafe API key; never print, infer, or commit it. Completion: the selected command returns `ok: true`.
26
+ 2. Confirm key availability with `jev auth status`, then use `jev auth test` when API validity must be verified. If absent or invalid, ask the user to configure the selected provider's API key; never print, infer, or commit it. Completion: the selected command returns `ok: true`.
27
27
  3. Choose the narrowest question type:
28
28
  - `noul` for a yes/no probability.
29
29
  - `choice` for one key from explicit options.
30
30
  - `score` for an ordered numeric level.
31
31
  - `run` for a complete request object or multiple questions.
32
- 4. Send only the state needed for the judgment. TypeSafe receives the submitted state and questions, so do not send secrets or private data without explicit authorization.
32
+ 4. Send only the state needed for the judgment. The selected provider receives the submitted state and questions, so do not send secrets or private data without explicit authorization.
33
33
  5. Use default JSON output for automation. Use `--value` only when a scalar is sufficient. Completion: parse the result and account for the exit code before acting on it.
34
34
 
35
35
  Read [references/cli.md](references/cli.md) for copy-paste command forms, inputs, output controls, and exit codes.
@@ -40,7 +40,8 @@ Read [references/cli.md](references/cli.md) for copy-paste command forms, inputs
40
40
  - Give `score` levels in ascending order; the returned number may be fractional.
41
41
  - Use `--json-state` only when the state must retain JSON structure.
42
42
  - Use `@file` or stdin for long input instead of embedding it in shell arguments.
43
- - Set `TYPESAFE_API_KEY` only for process-level overrides. The normal credential store remains under the user's config directory.
43
+ - The official TypeSafe API is the default. Use `--provider vercel`, `--provider openrouter`, or `--provider custom` only when the caller selects another provider.
44
+ - Use the provider-specific environment variable only for process-level overrides: `TYPESAFE_API_KEY`, `AI_GATEWAY_API_KEY`, `OPENROUTER_API_KEY`, or `JEV_API_KEY`. A custom provider also requires `JEV_ENDPOINT`; `JEV_MODEL` is optional. The normal credential store remains under the user's config directory.
44
45
  - Treat model output as a structured judgment, not verified fact. Keep consequential actions behind the caller's own validation and authorization rules.
45
46
 
46
47
  ## Common pitfalls
@@ -28,10 +28,35 @@ printf '%s' "$TYPESAFE_API_KEY" | jev auth set
28
28
 
29
29
  Resolution order:
30
30
 
31
- 1. `TYPESAFE_API_KEY`
31
+ 1. The selected provider's environment variable: `TYPESAFE_API_KEY`, `AI_GATEWAY_API_KEY`, `OPENROUTER_API_KEY`, or `JEV_API_KEY`
32
32
  2. `$XDG_CONFIG_HOME/jev-cli/credentials.json`
33
33
  3. `~/.config/jev-cli/credentials.json`
34
34
 
35
+ The official TypeSafe API is selected by default. Vercel AI Gateway and OpenRouter can be selected per command:
36
+
37
+ ```bash
38
+ jev auth set --provider vercel
39
+ jev auth test --provider vercel
40
+ jev noul --provider vercel -q 'Is this urgent?' -s 'Restore service today.' --value
41
+
42
+ jev auth set --provider openrouter
43
+ jev auth test --provider openrouter
44
+ jev noul --provider openrouter -q 'Is this urgent?' -s 'Restore service today.' --value
45
+ ```
46
+
47
+ `JEV_PROVIDER` changes the default for evaluation commands. Authentication commands require an explicit `--provider` so credentials are not accidentally stored or tested against the wrong service.
48
+
49
+ For a proxy implementing the native Jev contract:
50
+
51
+ ```bash
52
+ JEV_PROVIDER=custom \
53
+ JEV_ENDPOINT='https://proxy.example.com/v1/systemone' \
54
+ JEV_API_KEY='your-proxy-api-key' \
55
+ jev noul -q 'Is this urgent?' -s 'Restore service today.' --value
56
+ ```
57
+
58
+ Set `JEV_MODEL` or pass `--model` when the proxy requires a different model name. Use only a trusted HTTPS endpoint because the custom bearer key is sent to it.
59
+
35
60
  ## Typed questions
36
61
 
37
62
  Use `-q` for `--question` and `-s` for `--state` when a shorter command is useful. `--value` has no short form.
@@ -18,8 +18,9 @@ class JevTest(unittest.TestCase):
18
18
  "sys.stdout", new_callable=io.StringIO
19
19
  ) as stdout:
20
20
  self.assertEqual(jev.main(), 0)
21
- payload, endpoint = call.call_args.args
21
+ payload, endpoint, provider = call.call_args.args
22
22
  self.assertEqual(endpoint, jev.API_URL)
23
+ self.assertEqual(provider, "official")
23
24
  self.assertEqual(payload["questions"]["answer"]["type"], "noul")
24
25
  self.assertEqual(
25
26
  json.loads(stdout.getvalue()),
@@ -152,6 +153,172 @@ class JevTest(unittest.TestCase):
152
153
  prompt.assert_called_once_with("TypeSafe API key: ")
153
154
  self.assertEqual(jev.api_key(), "prompted-key")
154
155
 
156
+ def test_provider_defaults_and_models(self):
157
+ cases = {
158
+ "official": "jev-latest",
159
+ "vercel": "typesafe-ai/jev",
160
+ "openrouter": "typesafe/jev-1.13",
161
+ "custom": "jev-latest",
162
+ }
163
+ for provider, model in cases.items():
164
+ args = jev.parser().parse_args(
165
+ ["noul", "--provider", provider, "-q", "Urgent?", "-s", "today"]
166
+ )
167
+ payload, _ = jev.request_for(args)
168
+ self.assertEqual(payload["model"], model)
169
+
170
+ def test_custom_provider_uses_its_own_configuration(self):
171
+ environment = {
172
+ "JEV_ENDPOINT": "https://proxy.example.test/v1/systemone",
173
+ "JEV_API_KEY": "proxy-key",
174
+ "JEV_MODEL": "proxy-jev",
175
+ }
176
+ with patch.dict(os.environ, environment, clear=True):
177
+ args = jev.parser().parse_args(
178
+ ["noul", "--provider", "custom", "-q", "Urgent?", "-s", "today"]
179
+ )
180
+ payload, _ = jev.request_for(args)
181
+ self.assertEqual(jev.provider_endpoint("custom"), environment["JEV_ENDPOINT"])
182
+ self.assertEqual(jev.api_key("custom"), environment["JEV_API_KEY"])
183
+ self.assertEqual(payload["model"], environment["JEV_MODEL"])
184
+
185
+ def test_custom_provider_requires_an_endpoint(self):
186
+ with patch.dict(os.environ, {}, clear=True):
187
+ with self.assertRaisesRegex(jev.CliError, "JEV_ENDPOINT") as raised:
188
+ jev.provider_endpoint("custom")
189
+ self.assertEqual(raised.exception.exit_code, 2)
190
+
191
+ def test_legacy_official_endpoint_override_is_preserved(self):
192
+ with patch.dict(os.environ, {"TYPESAFE_API_URL": "https://example.test/systemone"}, clear=True):
193
+ self.assertEqual(jev.provider_endpoint("official"), "https://example.test/systemone")
194
+ self.assertEqual(jev.provider_endpoint("openrouter"), jev.PROVIDERS["openrouter"]["endpoint"])
195
+ self.assertEqual(jev.provider_endpoint("official", "https://override.test"), "https://override.test")
196
+
197
+ def test_invalid_provider_environment_is_structured_error(self):
198
+ with patch.dict(os.environ, {"JEV_PROVIDER": "unknown"}, clear=True), patch(
199
+ "sys.argv", ["jev", "noul", "-q", "Urgent?", "-s", "today"]
200
+ ), patch("sys.stderr", new_callable=io.StringIO) as stderr:
201
+ self.assertEqual(jev.main(), 2)
202
+ self.assertIn("invalid JEV_PROVIDER", json.loads(stderr.getvalue())["error"])
203
+
204
+ def test_vercel_request_and_response_translation(self):
205
+ payload = {
206
+ "model": "typesafe-ai/jev",
207
+ "state": "today",
208
+ "questions": {"answer": {"type": "noul", "instructions": "Urgent?"}},
209
+ }
210
+ translated, headers = jev.provider_request(payload, "vercel")
211
+ self.assertNotIn("model", translated)
212
+ self.assertEqual(translated["questions"]["answer"]["type"], "boolean")
213
+ self.assertEqual(headers["ai-model-id"], "typesafe-ai/jev")
214
+ self.assertEqual(headers["ai-gateway-protocol-version"], "0.0.1")
215
+ self.assertEqual(headers["ai-gateway-auth-method"], "api-key")
216
+ result = jev.normalize_response(
217
+ {"answers": {"answer": {"type": "boolean", "probability": 0.9}}}, "vercel"
218
+ )
219
+ self.assertEqual(result["answers"]["answer"], {"noul": 0.9})
220
+
221
+ def test_provider_api_keys_are_separate(self):
222
+ import tempfile
223
+
224
+ with tempfile.TemporaryDirectory() as directory, patch.object(
225
+ jev, "CREDENTIALS_FILE", Path(directory) / "jev-cli" / "credentials.json"
226
+ ), patch.dict(os.environ, {}, clear=True):
227
+ for provider in jev.PROVIDERS:
228
+ with patch("sys.stdin", io.StringIO(f"{provider}-key\n")):
229
+ jev.set_api_key(provider)
230
+ for provider in jev.PROVIDERS:
231
+ self.assertEqual(jev.api_key(provider), f"{provider}-key")
232
+
233
+ def test_setting_provider_key_migrates_legacy_official_key(self):
234
+ import tempfile
235
+
236
+ with tempfile.TemporaryDirectory() as directory, patch.object(
237
+ jev, "CREDENTIALS_FILE", Path(directory) / "jev-cli" / "credentials.json"
238
+ ), patch.dict(os.environ, {}, clear=True):
239
+ jev.CREDENTIALS_FILE.parent.mkdir(parents=True)
240
+ jev.CREDENTIALS_FILE.write_text('{"api_key":"legacy-key"}')
241
+ with patch("sys.stdin", io.StringIO("openrouter-key\n")):
242
+ jev.set_api_key("openrouter")
243
+ self.assertEqual(jev.api_key("official"), "legacy-key")
244
+ self.assertEqual(jev.api_key("openrouter"), "openrouter-key")
245
+
246
+ def test_malformed_provider_credentials_are_structured_error(self):
247
+ with patch.dict(os.environ, {}, clear=True), patch.object(jev, "CREDENTIALS_FILE") as path:
248
+ path.read_text.return_value = '{"providers":"invalid"}'
249
+ with self.assertRaises(jev.CliError) as raised:
250
+ jev.api_key("openrouter")
251
+ self.assertEqual(raised.exception.exit_code, 3)
252
+
253
+ def test_set_api_key_refuses_to_overwrite_invalid_credentials(self):
254
+ import tempfile
255
+
256
+ with tempfile.TemporaryDirectory() as directory, patch.object(
257
+ jev, "CREDENTIALS_FILE", Path(directory) / "jev-cli" / "credentials.json"
258
+ ), patch("sys.stdin", io.StringIO("new-key\n")), patch.dict(os.environ, {}, clear=True):
259
+ jev.CREDENTIALS_FILE.parent.mkdir(parents=True)
260
+ jev.CREDENTIALS_FILE.write_text("not-json")
261
+ with self.assertRaisesRegex(jev.CliError, "refusing to overwrite") as raised:
262
+ jev.set_api_key("openrouter")
263
+ self.assertEqual(raised.exception.exit_code, 3)
264
+ self.assertEqual(jev.CREDENTIALS_FILE.read_text(), "not-json")
265
+
266
+ def test_provider_http_contracts(self):
267
+ class Response(io.BytesIO):
268
+ def __enter__(self):
269
+ return self
270
+
271
+ def __exit__(self, *args):
272
+ self.close()
273
+
274
+ payload = {
275
+ "model": "custom-model",
276
+ "state": "today",
277
+ "questions": {
278
+ "urgent": {"type": "noul", "instructions": "Urgent?"},
279
+ "route": {"type": "choice", "instructions": "Route?", "criteria": {"a": "A", "b": "B"}},
280
+ "quality": {"type": "score", "instructions": "Quality?", "criteria": ["low", "high"]},
281
+ },
282
+ }
283
+ results = {
284
+ "official": {"answers": {}},
285
+ "openrouter": {"answers": {}},
286
+ "custom": {"answers": {}},
287
+ "vercel": {
288
+ "answers": {
289
+ "urgent": {"type": "boolean", "probability": 0.9},
290
+ "route": {"type": "choice", "choice": "a", "probabilities": {"a": 0.8, "b": 0.2}},
291
+ "quality": {"type": "score", "score": 1.0, "probabilities": {"0": 0.0, "1": 1.0}},
292
+ }
293
+ },
294
+ }
295
+ for provider, config in jev.PROVIDERS.items():
296
+ captured = []
297
+ endpoint = config["endpoint"] or "https://proxy.example.test/v1/systemone"
298
+
299
+ def open_url(request, timeout):
300
+ captured.append((request, timeout))
301
+ return Response(json.dumps(results[provider]).encode())
302
+
303
+ with patch.object(jev, "api_key", return_value=f"{provider}-key"), patch(
304
+ "urllib.request.urlopen", side_effect=open_url
305
+ ):
306
+ result = jev.call(payload, endpoint, provider)
307
+ request, timeout = captured[0]
308
+ body = json.loads(request.data)
309
+ self.assertEqual(request.full_url, endpoint)
310
+ self.assertEqual(request.headers["Authorization"], f"Bearer {provider}-key")
311
+ self.assertEqual(timeout, 60)
312
+ if provider == "vercel":
313
+ self.assertNotIn("model", body)
314
+ self.assertEqual(request.headers["Ai-model-id"], "custom-model")
315
+ self.assertEqual(body["questions"]["urgent"]["type"], "boolean")
316
+ self.assertEqual(result["answers"]["urgent"], {"noul": 0.9})
317
+ self.assertEqual(result["answers"]["route"]["choice"], "a")
318
+ self.assertEqual(result["answers"]["quality"]["score"], 1.0)
319
+ else:
320
+ self.assertEqual(body, payload)
321
+
155
322
  def test_primary_values(self):
156
323
  result = {"answers": {"answer": {"noul": 0.9, "choice": "a", "score": 1.5}}}
157
324
  self.assertEqual(jev.primary_value(result, "noul"), 0.9)
File without changes
File without changes
File without changes
File without changes