Jev.HTTP (Jev v0.1.0)

Copy Markdown View Source

The transport: one POST to /v1/systemone per call.

This is the seam between the pure modules and the network. Jev.Server calls it from a task; scripts and evaluation harnesses call it directly.

Configuration

config :jev,
  api_key: System.get_env("TYPESAFE_API_KEY"),  # or the TYPESAFE_API_KEY env var
  base_url: "https://api.typesafe.ai",
  model: "jev-latest",
  max_retries: 3,
  receive_timeout: 30_000,
  usd_per_million_input: 0.042,
  req_options: []                                 # merged into Req.new/1, e.g. a test plug

Every option except usd_per_million_input and req_options can also be passed per call. Requests that fail with 429 or 529 are retried with backoff, honouring Retry-After, as the API documentation asks.

Telemetry

[:jev, :request, :start | :stop | :exception] wrap each call with :telemetry.span/3. Stop measurements carry input_tokens, output_tokens, and cost; metadata carries model, questions (name to type), state_hash, tag, status, request_id, and confidence.

[:jev, :answer] fires once per question after a successful call with confidence and probability measurements and name, type, answer, model, state_hash, and tag metadata. A histogram of confidence by name is a calibration monitor.

The state itself is never put in metadata, only its hash.

Summary

Functions

Evaluates questions against state.

Types

option()

@type option() ::
  {:model, String.t()}
  | {:api_key, String.t()}
  | {:base_url, String.t()}
  | {:max_retries, non_neg_integer()}
  | {:receive_timeout, timeout()}
  | {:tag, term()}

Functions

post(state, questions, opts \\ [])

@spec post(
  Jev.entry(),
  keyword(Jev.shorthand()) | %{required(atom()) => Jev.shorthand()},
  [option()]
) ::
  {:ok, Jev.reply()} | {:error, Jev.Error.t() | Exception.t()}

Evaluates questions against state.

Returns {:ok, reply} with the map described in Jev, or {:error, error} where error is a Jev.Error for a non-2xx response or the transport exception. Raises ArgumentError for malformed questions or a missing API key.