jev

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 30 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

jev

build status report card godocs

A Go client for the TypeSafe System One API and its model, Jev.

Jev does not write text. You send a state (a string, or JSON such as a ticket, a log, or the current state of a program) and one or more named questions. The call returns a typed answer and a probability for every question. Adding questions to the same call does not add a round trip. Since Jev 1.14 the state can also hold a picture, and a box question says where in it one thing is.

This module is not affiliated with TypeSafe AI. The official clients are the JavaScript SDK and the Python SDK. The HTTP contract is the System One API.

Install

Go 1.27 or newer. The only dependency is golang.org/x/time/rate.

go get github.com/kataras/jev

Please star this open source project to attract more developers so that together we can improve it even more!

Questions

Question You provide You get back
Noul A yes/no question Probability of yes, from 0 to 1
Choice Named options, up to 255 The picked option, a probability for each option, and a confidence
Score An ordered list of levels, up to 10 A position on that list (it can fall between levels), a probability for each level, and a confidence
Box What to find, and in which image One bounding box, as fractions of the image, and a confidence

Question names are yours. They come back as the answer keys. They are not part of the prompt.

jev-latest is the default model, and that alias moves. Jev 1.14.0 came out on 2026-10-14; jev-latest still points at jev-1.13.0 and moves about a week after a release, while jev-preview already points at jev-1.14.0. The constants jev.ModelLatest, jev.ModelPreview, jev.ModelJev114, and jev.ModelJev113 hold those names. Set WithModel(jev.ModelJev114) when a later run has to hit the same model. Box questions need Jev 1.14, so pass WithModel(jev.ModelPreview) for them until jev-latest catches up. The model field of every response is the versioned id that answered. See aliases.

Usage

client, err := jev.New() // reads TYPESAFE_API_KEY
resp, err := client.SystemOne(ctx, jev.Request{
    State: "I was charged twice. Please fix this ASAP.",
    Questions: jev.Questions{
        "billing": jev.Noul{Instructions: "Is this ticket about billing?"},
        "team": jev.Choice{
            Instructions: "Which team should handle this?",
            Criteria: map[string]any{
                "billing":   "Payments, invoices, refunds",
                "technical": nil, // null means the label has no description
            },
        },
        "urgency": jev.Score{
            Instructions: "How urgent is this ticket?",
            Criteria:     []string{"can wait", "this week", "today"},
        },
    },
})

billing, _ := resp.Noul("billing")
team, _ := resp.Choice("team")
urgency, _ := resp.Score("urgency")

SystemOneAs decodes the same JSON into a struct. It is a generic method, which is why this module requires Go 1.27. JSON names are case-sensitive.

type ticket struct {
    Model string `json:"model"`
    Answers struct {
        Billing struct {
            Noul float64 `json:"noul"`
        } `json:"billing"`
    } `json:"answers"`
}

out, err := client.SystemOneAs[ticket](ctx, req)

A full program lives in examples/quickstart.

One question

Noul, Choice, Score, and Box each send one question named answer through SystemOne. Classify is Choice with the question and the options as separate arguments. Rate is Score with the levels as a list. Box takes the instructions alone or a jev.Box. The As methods call SystemOneAs. In that JSON the question name is answer.

yes, err := client.Noul(ctx, ticket, "Is this about billing?")

team, err := client.Classify(ctx, ticket, "Which team?", map[string]any{
    "billing":   "Payments, invoices, refunds",
    "technical": nil,
})

urgency, err := client.Rate(ctx, ticket, "How urgent?", []string{"can wait", "this week", "today"})

box, err := client.Box(ctx, map[string]any{"photo": photo}, "the coffee mug in `photo`", jev.WithModel(jev.ModelPreview))

Several questions about the same state still belong in one SystemOne call.

List the models on the account with ListModels. The list includes the jev-latest and jev-preview aliases.

models, err := client.ListModels(ctx)

Images

Jev 1.13 and 1.14 both look at PNG and JPEG images. Wrap the file with ImageFile, ImageBytes, or ImageReader and put the *Image anywhere a string can go: a value in the state, a question's instructions, a Choice option, a struct field, or a slice element. The model reads a reference string in its place, such as img-3f9a1c2b7d4e6f80-kitchen, and the bytes travel with the request. Box finds one thing in an image. It needs Jev 1.14, so pass WithModel(jev.ModelPreview) until jev-latest moves there.

photo, err := jev.ImageFile("kitchen.jpg")
client, err := jev.New(jev.WithModel(jev.ModelPreview))
resp, err := client.SystemOne(ctx, jev.Request{
    State: map[string]any{"photo": photo},
    Questions: jev.Questions{
        "mug_visible": jev.Noul{Instructions: "Is there a coffee mug in `photo`?"},
        "mug":         jev.Box{Instructions: "the coffee mug in `photo`"},
    },
})

mug, ok := resp.Box("mug")
fmt.Println(mug.Confidence, mug.Rect(width, height))

BoxAnswer holds Top, Bottom, Left, and Right as fractions from 0 to 1, measured from the top-left corner, and a Confidence. Rect(width, height) turns the edges into a stdlib image.Rectangle for cropping. A box always comes back, even when the thing is not in the picture, so ask a Noul in the same call when it might be missing. Box has no criteria field.

To mention an image inside a sentence, build the text with TextOf. The image part becomes its reference:

jev.Noul{Instructions: jev.TextOf("Is the dog in `photo` the same dog as in this picture: ", poster, "?")}

The client reads the file signature and accepts PNG and JPEG only; convert GIF, WebP, and HEIC first. One image may be 16 MiB and the whole request 32 MiB, and both are checked before sending. The API also asks for 280 to 1568 pixels per side, which the client does not check. The same image used twice is uploaded once.

The header TypeSafe-Danger-Zone-Images: true is added whenever a request carries an image or a box question; without it the API answers 400. Three limits: a nil *Image encodes as JSON null, an image inside pre-encoded jsontext.Value state is not seen, and an image in Request.Extra is rejected. The rate limiter does not count image bytes as tokens. It reserves a flat 1,600 tokens per image before the call and settles with the real usage after it.

A program that draws a rectangle and asks where it is lives in examples/box.

Configuration

Explicit options win over environment variables. A blank environment value is ignored.

Option Environment Default
WithAPIKey TYPESAFE_API_KEY required
WithBaseURL TYPESAFE_BASE_URL https://api.typesafe.ai
WithModel TYPESAFE_DEFAULT_MODEL jev-latest
WithLongContext off
WithTimeout 10s per attempt
WithRetry 2 retries, 500ms to 5s backoff
WithRateLimit 1,200 requests/min, 250,000 tokens/s
WithRateLimiter the limiter WithRateLimit builds
WithLogger TYPESAFE_LOG_LEVEL no logging
WithHTTPClient a client that does not follow redirects
WithHeader

The same options can be passed to one call. They override the client for that call only. WithRateLimit is the exception: it belongs to New, because a limiter built for one call starts with a full budget and paces nothing. For one call, pass WithRateLimiter with a limiter you own, or nil to skip pacing.

WithRetry replaces the whole policy. Copy DefaultRetryPolicy() and edit the copy. A zero RetryPolicy retries nothing, because its status list is empty.

WithLongContext(true) raises the input limit from 64k tokens per request and 32k per question to 262k, by sending TypeSafe-Danger-Zone-Long-Context: true. The price per token is the same, but the API documents long context as slower and less accurate, so turn it on for the calls that need it. Jev 1.13 and 1.14 both support it. See context length.

yes, err := client.Noul(ctx, longContract, "Does the `state` include a termination clause?", jev.WithLongContext(true))

Rate limits

The API limits each account to 1,200 requests per minute and 250,000 input tokens per second. A request over either limit is a 429. Retrying after a 429 works, but it costs a round trip and a backoff wait each time. The client stays under the limit instead: every attempt, retries included, first waits on a token bucket built with golang.org/x/time/rate, the same way kataras/httpclient paces its requests.

Requests are spread across the minute, with a burst of one second's worth (20 at the default). Tokens are estimated from the body size before the call and settled with usage.input_tokens after it, so the estimate corrects itself. When the server does answer 429 or 529 with Retry-After, every caller on that limiter pauses until then, not only the call that saw it. The pause is capped by RetryPolicy.MaxRetryAfter, 60s by default.

The limits are per account, so clients on the same key should share one limiter:

shared := jev.NewLimiter(jev.DefaultRateLimit())
latest, err := jev.New(jev.WithRateLimiter(shared))
pinned, err := jev.New(jev.WithModel(jev.ModelJev114), jev.WithRateLimiter(shared))
// or join an existing client's budget:
third, err := jev.New(jev.WithRateLimiter(latest.Limiter()))

TypeSafe adjusts the limits without notice, and enterprise plans get higher ones. Set your own figures, or divide the account's budget between processes:

client, err := jev.New(jev.WithRateLimit(jev.RateLimit{
    RequestsPerMinute: 300,
    TokensPerSecond:   60_000,
}))

A zero field disables that axis. jev.WithRateLimit(jev.RateLimit{}) or jev.WithRateLimiter(nil) turns pacing off. A plain *rate.Limiter also satisfies jev.Limiter; it paces requests only.

The limiter waits are not retries. A wait that outlives your context returns that context's error, and no request is sent.

Errors

if errors.Is(err, context.Canceled) {
    // the caller cancelled; this is not retried
}
if errors.Is(err, jev.ErrUnauthorized) {
    // HTTP 401
}
if errors.Is(err, jev.ErrRateLimited) {
    // HTTP 429, after retries
}
if errors.Is(err, jev.ErrOverloaded) {
    // HTTP 529; this also matches jev.ErrServer
}
var api *jev.APIError
if errors.As(err, &api) {
    fmt.Println(api.Status, api.RequestID, api.Message)
}
Sentinel When
ErrConfig Missing key, bad URL, bad option
ErrRequest Rejected locally, before HTTP
ErrResponse 2xx body that does not match the contract
ErrTimeout The per-attempt timeout fired
ErrConnection DNS, TLS, or a dropped connection
ErrBadRequest HTTP 400
ErrUnauthorized HTTP 401
ErrForbidden HTTP 403
ErrNotFound HTTP 404
ErrUnprocessable HTTP 422
ErrRateLimited HTTP 429
ErrOverloaded HTTP 529
ErrServer HTTP 5xx, including 529

A deadline on the context you passed is returned as that context error. It does not match ErrTimeout. ErrTimeout means this client's own per-attempt limit.

Retries

The default policy matches the official JavaScript SDK. It retries HTTP 408, 429, and 500 through 599, including 529. The first wait is 500ms, doubled up to 5s, with up to 25% of the wait subtracted at random. Retry-After-Ms is preferred over Retry-After. A server delay longer than 60s falls back to that backoff. Retries are the second line; the rate limiter is the first.

There is no budget across attempts unless you set RetryPolicy.MaxElapsed. The context you pass always applies. Cancellation during a wait stops the call and is not retried.

POST is retried because a System One call only evaluates. Each attempt still spends input tokens.

Logging

TYPESAFE_LOG_LEVEL may be debug, info, warn, error, or off. Info logs one line per attempt. Debug also logs headers and bodies. Authorization, Cookie, and X-Api-Key are replaced with [redacted]. Bodies are logged as sent, and they contain your state. Image bytes are the exception: the JSON part of a multipart request is logged, the file parts are not.

Wire format

A few choices differ from other Go clients, on purpose:

  • JSON is encoded with encoding/json/v2, and <, >, and & are left as themselves. encoding/json rewrites them to \u003c, \u003e, and \u0026, so the text the model reads is not the text you passed.
  • Object keys are sorted. The same request produces the same bytes.
  • Request.Extra cannot replace state, model, questions, or assets.
  • A []byte state is sent as a JSON string. A plain byte slice would otherwise be base64.
  • Score criteria must be a JSON array. A map is rejected. That matches the official SDK change in v0.6.0 (15 Sep 2026).
  • Choice criteria must be a JSON object, with at most 255 options.
  • A request that carries an image goes out as multipart/form-data: first a part named request with the JSON, which gains a top-level assets map, then one file part per image, named by its reference, with Content-Type image/png or image/jpeg. Every other request is application/json.
  • Two headers are the client's job. TypeSafe-Danger-Zone-Images: true goes with any image or box question. TypeSafe-Danger-Zone-Long-Context: true goes with WithLongContext(true).

Live tests

TestLiveSystemOne, TestLiveBox, and TestLiveModels call the real API and spend tokens. TestLiveBox draws a red rectangle on a PNG and asks jev-preview where it is. go test skips all three when TYPESAFE_API_KEY is unset or blank, and always under go test -short. Every other test runs against an in-process server and needs no key.

For GitHub Actions, add a repository secret named TYPESAFE_API_KEY. The workflow runs the unit tests without the key, then runs -run '^TestLive' only when the secret is present. Pull requests from forks do not receive secrets, so there the live step prints a note and passes. Do not commit a key.

Agent skill

skills/jev/SKILL.md is an Agent Skill for this module. The signatures in it match the Go API above. Claude Code, Cursor, Codex, and Plexon all read that format.

Install it for every agent this machine already has, including Plexon (it adopts ~/.agents/skills):

npx skills add kataras/jev --skill jev -g -y

One project only: drop -g. The files land in .agents/skills/jev or .claude/skills/jev. Plexon reads both.

Pick agents by name when you do not want the full set:

npx skills add kataras/jev --skill jev -g -y -a claude-code -a cursor -a codex

Claude Code can install the same skill as a plugin. Inside a Claude Code session:

/plugin marketplace add kataras/jev
/plugin install jev@kataras-jev

License

MIT.

Documentation

Overview

Package jev is an HTTP client for the TypeSafe System One API.

Jev is TypeSafe's System One model. You send it a state (text or JSON) and one or more named questions. It answers every question in that call and returns a probability with each answer. It does not generate text. Since Jev 1.14 the state can also hold an image, and a box question returns where in that image one thing is. The HTTP contract is the API reference; the ideas behind it are under System One and primitives.

Create a client with New. The API key comes from WithAPIKey or from the TYPESAFE_API_KEY environment variable.

client, err := jev.New()
resp, err := client.SystemOne(ctx, jev.Request{
	State: "I was charged twice. Please fix this ASAP.",
	Questions: jev.Questions{
		"billing": jev.Noul{Instructions: "Is this ticket about billing?"},
		"team": jev.Choice{
			Instructions: "Which team should handle this?",
			Criteria: map[string]any{
				"billing":   "Payments, invoices, refunds",
				"technical": nil,
			},
		},
		"urgency": jev.Score{
			Instructions: "How urgent is this ticket?",
			Criteria:     []string{"can wait", "this week", "today"},
		},
	},
})
if billing, ok := resp.Noul("billing"); ok {
	fmt.Println(billing.Noul)
}

Client.SystemOneAs decodes that same JSON into a struct of your own. It is a generic method, so it needs Go 1.27.

One question at a time can use Client.Noul, Client.Choice, Client.Score, Client.Box, Client.Classify, or Client.Rate. Each calls SystemOne with the question named "answer". The As forms call SystemOneAs.

Images and boxes

A PNG or JPEG becomes an Image through ImageFile, ImageBytes, or ImageReader. Put the *Image anywhere a string can go: a value in the state, a question's Instructions, or a Choice option. The model reads a reference string in its place, the bytes travel with the request as multipart/form-data, and the client adds the TypeSafe-Danger-Zone-Images header; see images. TextOf mentions an image inside a sentence.

A Box question finds one thing in an image and answers with a BoxAnswer: four edges as fractions of the image and a confidence; see box. A box comes back even when the target is absent, so pair it with a Noul when that is possible. Box needs Jev 1.14, so pass WithModel(ModelPreview) until jev-latest moves there. Images themselves work on Jev 1.13 and 1.14.

photo, err := jev.ImageFile("kitchen.jpg")
resp, err := client.SystemOne(ctx, jev.Request{
	State: map[string]any{"photo": photo},
	Questions: jev.Questions{
		"mug_visible": jev.Noul{Instructions: "Is there a coffee mug in `photo`?"},
		"mug":         jev.Box{Instructions: "the coffee mug in `photo`"},
	},
}, jev.WithModel(jev.ModelPreview))
if mug, ok := resp.Box("mug"); ok {
	fmt.Println(mug.Confidence, mug.Rect(width, height))
}

Long context

WithLongContext raises the input limit from 64k tokens per request and 32k per question to 262k, by sending the TypeSafe-Danger-Zone-Long-Context header. The API documents it as slower and less accurate at the same price per token, so it is off by default and is meant as a per-call option; see context length.

Rate limits

The API limits each account to a number of requests per minute and input tokens per second; the current figures are under current models. The client paces itself under those figures by default, with a Limiter built from DefaultRateLimit, so a burst of calls queues instead of failing with 429. When the server does answer 429 or 529 with Retry-After, every caller on that limiter pauses until then. Set WithRateLimit to change the figures, or share one NewLimiter between clients on the same key with WithRateLimiter. See handling rate limits.

Retries and errors

The client retries 408, 429, and 5xx responses, including 529, with exponential backoff, as the API asks. Context cancellation is not retried. Failed responses are an *APIError and match a status sentinel such as ErrRateLimited through errors.Is; see errors. Credential headers are redacted from logs. Request and response bodies are not, except that image bytes are never logged.

Example
package main

import (
	"context"
	"fmt"

	"github.com/kataras/jev"
)

func main() {
	client, err := jev.New()
	if err != nil {
		fmt.Println(err)
		return
	}
	resp, err := client.SystemOne(context.Background(), jev.Request{
		State: "I was charged twice. Please fix this ASAP.",
		Questions: jev.Questions{
			"billing": jev.Noul{Instructions: "Is this ticket about billing?"},
			"team": jev.Choice{
				Instructions: "Which team should handle this?",
				Criteria: map[string]any{
					"billing":   "Payments, invoices, refunds",
					"technical": nil,
				},
			},
			"urgency": jev.Score{
				Instructions: "How urgent is this ticket?",
				Criteria:     []string{"can wait", "this week", "today"},
			},
		},
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	if billing, ok := resp.Noul("billing"); ok {
		fmt.Println(billing.Noul > 0.5)
	}
}

Index

Examples

Constants

View Source
const (
	ModelLatest  = "jev-latest"
	ModelPreview = "jev-preview"
	// ModelJev114 is Jev 1.14, released 2026-10-14. [Box] questions need it.
	ModelJev114 = "jev-1.14.0"
	// ModelJev113 is Jev 1.13.
	ModelJev113 = "jev-1.13.0"
)

Model names the API accepts in the model field. The aliases move with each release: jev-latest is the newest official release, and the default of the official SDKs and of this client; jev-preview is the newest release of any kind, and moves ahead of jev-latest while a preview build exists. Each response's Response.Model holds the versioned id that answered. See aliases and current models.

View Source
const (
	// DefaultRequestsPerMinute is the documented request limit per account.
	DefaultRequestsPerMinute = 1200
	// DefaultTokensPerSecond is the documented input-token limit per account.
	DefaultTokensPerSecond = 250_000
)

The documented limits for Jev 1.13 and 1.14. TypeSafe adjusts them without notice, and enterprise plans get higher ones, so they are a starting point and not a contract. See current models.

View Source
const AnswerKey = "answer"

AnswerKey is the question name used by the single-question methods (Client.Noul, Client.Choice, Client.Score, Client.Box, Client.Classify, Client.Rate). In a struct passed to the As methods, read it as answers.answer. The name is a key of the questions map in the request body; the API does not see it as part of the prompt.

View Source
const Version = "0.2.0"

Version is the client version sent in User-Agent and X-TypeSafe-SDK. The official SDKs send the same header from their own VERSION constant.

Variables

View Source
var (
	// ErrConfig is wrapped by errors from [New] and from invalid options.
	ErrConfig = errors.New("jev: invalid configuration")
	// ErrRequest is wrapped by errors for calls rejected before any HTTP attempt.
	ErrRequest = errors.New("jev: invalid request")
	// ErrResponse is wrapped when a 2xx body does not match the System One contract.
	ErrResponse = errors.New("jev: invalid response")
	// ErrBodyTooLarge is wrapped when a response body exceeds 16 MiB.
	// It is not retried.
	ErrBodyTooLarge = errors.New("jev: response body exceeds 16 MiB")
)

Configuration and request sentinels.

View Source
var (
	ErrBadRequest    = errors.New("jev: bad request")       // HTTP 400
	ErrUnauthorized  = errors.New("jev: unauthorized")      // HTTP 401
	ErrForbidden     = errors.New("jev: forbidden")         // HTTP 403
	ErrNotFound      = errors.New("jev: not found")         // HTTP 404
	ErrUnprocessable = errors.New("jev: unprocessable")     // HTTP 422
	ErrRateLimited   = errors.New("jev: rate limited")      // HTTP 429
	ErrOverloaded    = errors.New("jev: overloaded")        // HTTP 529
	ErrServer        = errors.New("jev: server error")      // HTTP 5xx, including 529
	ErrStatus        = errors.New("jev: unexpected status") // any other non-2xx
)

Status sentinels matched by *APIError through errors.Is. A 529 matches both ErrOverloaded and ErrServer. The statuses the API documents, and what each one means, are under errors. 429 and 529 ask for backoff, which the default RetryPolicy applies; see handling rate limits.

View Source
var (
	// ErrConnection matches every ConnectionError.
	ErrConnection = errors.New("jev: connection error")
	// ErrTimeout matches a ConnectionError caused by the per-attempt timeout.
	// A deadline on the caller's context is returned as that context error
	// and does not match ErrTimeout.
	ErrTimeout = errors.New("jev: request timed out")
)

Transport sentinels matched by *ConnectionError through errors.Is.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status    int
	Method    string
	URL       string
	Header    http.Header
	Body      []byte
	Message   string
	RequestID string
	Attempts  int
}

APIError is an unsuccessful HTTP response, returned after retries. Status is the HTTP status; the API's table of statuses is under errors. Message is pulled from the JSON body, including the field path for a 422. RequestID is the server's X-Typesafe-Request-Id, for support tickets.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Is

func (e *APIError) Is(target error) bool

Is reports whether target is the status sentinel for this response.

func (*APIError) RetryAfter

func (e *APIError) RetryAfter() (time.Duration, bool)

RetryAfter returns the delay from Retry-After-Ms or Retry-After. A 429 or 529 may carry one; see handling rate limits. The client already waited it out when it retried, and a Limiter from NewLimiter pauses every caller for it, so read it here for logging or to plan the next call.

type Answer

type Answer interface {
	Type() string
}

Answer is the result of one question: NoulAnswer, ChoiceAnswer, ScoreAnswer, BoxAnswer, or UnknownAnswer. Every answer carries a type matching its question; see answer types.

type Box added in v0.2.0

type Box struct {
	Instructions any
}

Box locates one thing in an image. The answer is one bounding box, as fractions of the image's width and height, with a confidence; see BoxAnswer. There is no criteria field: Instructions says what to find and in which image, such as "the coffee mug in `photo`". The request must carry an Image, and the model must be Jev 1.14, so pass ModelPreview or ModelJev114 until jev-latest moves there. The client adds the TypeSafe-Danger-Zone-Images header. See box.

A box always comes back, even when the target is absent. When it may be, ask a Noul in the same call whether the target is there.

type BoxAnswer added in v0.2.0

type BoxAnswer struct {
	Top        float64
	Bottom     float64
	Left       float64
	Right      float64
	Confidence float64
}

BoxAnswer is where the model found the target of a Box: four edges as fractions of the image, 0 at the top-left corner and 1 at the bottom-right, with Left < Right and Top < Bottom, and a confidence from 0 to 1. Multiply by the pixel width and height, or call BoxAnswer.Rect, to crop. A box comes back even when the target is absent. See box.

func (BoxAnswer) Rect added in v0.2.0

func (a BoxAnswer) Rect(width, height int) image.Rectangle

Rect converts the edges to pixels for an image of width by height, rounding each edge to the nearest pixel.

func (BoxAnswer) Type added in v0.2.0

func (BoxAnswer) Type() string

type Choice

type Choice struct {
	Instructions any
	Criteria     any
}

Choice picks one option from a set you define. Criteria is a JSON object: a map[string]any, a map[string]string, or a struct with json tags. A nil description leaves that option undescribed and is sent as null. At least one option is required, and more than 255 is rejected. The wire shape is under choice; structured choice options shows how a description can be an object rather than a string.

type ChoiceAnswer

type ChoiceAnswer struct {
	Choice        string
	Confidence    float64
	Probabilities map[string]float64
}

ChoiceAnswer is the selected option, a probability for every option, and a confidence derived from that distribution. See choice answer, and confidence for how confidence differs from the winning probability.

func (ChoiceAnswer) Type

func (ChoiceAnswer) Type() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the TypeSafe System One API. It is safe for concurrent use. Create it with New. The HTTP contract it speaks is the API reference.

func New

func New(opts ...Option) (*Client, error)

New returns a client. Options override environment variables, which override the defaults. The API key is required; get one from the quick start.

The precedence, the environment variable names, and the defaults match the official SDKs. See client config for the JavaScript SDK's version of the same table.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the API root without a trailing slash. The production root is https://api.typesafe.ai; see the evaluation endpoint.

func (*Client) Box added in v0.2.0

func (c *Client) Box(ctx context.Context, state any, question any, opts ...Option) (BoxAnswer, error)

Box asks where one thing is in an image and returns the box. question is a Box value, or the instructions alone, such as "the coffee mug in `photo`". state must hold an Image, and the model must be Jev 1.14: pass WithModel(ModelPreview) until jev-latest moves there. See box. The call is one Client.SystemOne request.

func (*Client) BoxAs added in v0.2.0

func (c *Client) BoxAs[T any](ctx context.Context, state any, question any, opts ...Option) (T, error)

BoxAs asks where one thing is in an image and decodes the response JSON into T. It calls Client.SystemOneAs. The question name in that JSON is AnswerKey. The shape to mirror is under box.

func (*Client) Choice

func (c *Client) Choice(ctx context.Context, state any, q Choice, opts ...Option) (ChoiceAnswer, error)

Choice asks one choice question. See choice and choice answer. The call is one Client.SystemOne request; several questions about one state belong in one SystemOne call, see ask more than one question per call.

func (*Client) ChoiceAs

func (c *Client) ChoiceAs[T any](ctx context.Context, state any, q Choice, opts ...Option) (T, error)

ChoiceAs asks one choice question and decodes the response JSON into T. It calls Client.SystemOneAs. The question name in that JSON is AnswerKey. The shape to mirror is under choice answer.

func (*Client) Classify

func (c *Client) Classify(ctx context.Context, state any, instructions any, criteria any, opts ...Option) (ChoiceAnswer, error)

Classify picks one option. instructions is the question. criteria maps each option to a description, or nil when the option needs none; see choice. It calls Client.Choice.

func (*Client) ClassifyAs

func (c *Client) ClassifyAs[T any](ctx context.Context, state any, instructions any, criteria any, opts ...Option) (T, error)

ClassifyAs picks one option and decodes the response JSON into T. It calls Client.ChoiceAs. The question name in that JSON is AnswerKey. The shape to mirror is under choice answer.

func (*Client) CloseIdleConnections

func (c *Client) CloseIdleConnections()

CloseIdleConnections closes idle connections on the underlying HTTP client. It does not cancel calls that are in flight.

func (*Client) Limiter

func (c *Client) Limiter() Limiter

Limiter returns the client-side rate limiter, or nil when pacing is off. Pass it to WithRateLimiter on another client so both share one budget, which is what the per-account limits under current models ask for.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context, opts ...Option) ([]ModelInfo, error)

ListModels returns the models available to the account with GET /v1/models. The list holds the aliases, such as ModelLatest and ModelPreview. Versioned IDs such as ModelJev114 are accepted by the model field whether or not they appear here. See listing models and aliases.

func (*Client) Model

func (c *Client) Model() string

Model returns the model used when a request does not name one. The names and aliases the API accepts are listed under models.

func (*Client) Noul

func (c *Client) Noul(ctx context.Context, state any, question any, opts ...Option) (NoulAnswer, error)

Noul asks one yes/no question and returns the probability of yes. question is a Noul value, or the instructions alone: a string, or any value that encodes as a JSON object or array. See noul and reading a noul.

The call is one Client.SystemOne request. For several questions about the same state, use SystemOne; see ask more than one question per call.

func (*Client) NoulAs

func (c *Client) NoulAs[T any](ctx context.Context, state any, question any, opts ...Option) (T, error)

NoulAs asks one yes/no question and decodes the response JSON into T. It calls Client.SystemOneAs. The question name in that JSON is AnswerKey. The shape to mirror is under noul answer.

func (*Client) Rate

func (c *Client) Rate(ctx context.Context, state any, instructions any, levels any, opts ...Option) (ScoreAnswer, error)

Rate places the state on an ordered rubric. levels is a JSON array, usually a []string, lowest level first; see score and writing good levels. It calls Client.Score.

func (*Client) RateAs

func (c *Client) RateAs[T any](ctx context.Context, state any, instructions any, levels any, opts ...Option) (T, error)

RateAs places the state on an ordered rubric and decodes the response JSON into T. It calls Client.ScoreAs. The question name in that JSON is AnswerKey. The shape to mirror is under score answer.

func (*Client) Score

func (c *Client) Score(ctx context.Context, state any, q Score, opts ...Option) (ScoreAnswer, error)

Score asks one score question. See score, levels, and score answer. The call is one Client.SystemOne request.

func (*Client) ScoreAs

func (c *Client) ScoreAs[T any](ctx context.Context, state any, q Score, opts ...Option) (T, error)

ScoreAs asks one score question and decodes the response JSON into T. It calls Client.SystemOneAs. The question name in that JSON is AnswerKey. The shape to mirror is under score answer.

func (*Client) SystemOne

func (c *Client) SystemOne(ctx context.Context, req Request, opts ...Option) (*Response, error)

SystemOne evaluates req.State against req.Questions with one POST to the evaluation endpoint. One answer comes back for each question, under the same name; see response body.

Several questions about one state belong in one call. The model reads the state once and answers them in parallel, so adding a question does not add a round trip; see ask multiple questions together.

func (*Client) SystemOneAs

func (c *Client) SystemOneAs[T any](ctx context.Context, req Request, opts ...Option) (T, error)

SystemOneAs evaluates the request and decodes the JSON response into T. Object names are case-sensitive. Members that T does not declare are ignored. The JSON shape to mirror in T is documented under response body and answer types.

type ConnectionError

type ConnectionError struct {
	Method    string
	URL       string
	Timeout   time.Duration
	Attempts  int
	RequestID string
	Err       error
}

ConnectionError is a request that failed without a usable HTTP response, returned after retries. It is the Go form of the official SDKs' connection errors: APIConnectionError, and APITimeoutError when Timeout is set.

func (*ConnectionError) Error

func (e *ConnectionError) Error() string

func (*ConnectionError) Is

func (e *ConnectionError) Is(target error) bool

Is reports whether target is ErrConnection or, for a timed-out attempt, ErrTimeout.

func (*ConnectionError) Unwrap

func (e *ConnectionError) Unwrap() error

Unwrap exposes the transport error. Attempt timeouts do not unwrap to context.DeadlineExceeded, so that sentinel stays reserved for the caller's own deadline.

type Image added in v0.2.0

type Image struct {
	// contains filtered or unexported fields
}

Image is a PNG or JPEG for the model to look at. Put the *Image anywhere a string can go: a value in Request.State, a question's Instructions, or a Choice option. The client replaces it with a reference string, uploads the bytes once as a multipart part under the request's assets, and sends the TypeSafe-Danger-Zone-Images header the API asks for. To mention an image inside a sentence, use TextOf. See images.

Jev 1.13 and 1.14 both accept images. The API limits each file to 16 MiB, each side to 280 to 1568 pixels, and the whole request to 32 MiB. The client checks the format and the byte sizes before sending, not the dimensions, since those limits are documented as subject to change.

Two things the client cannot see: a nil *Image encodes as JSON null, and an image inside pre-encoded state (a jsontext.Value) is sent as whatever that JSON holds. An image in Request.Extra is rejected.

func ImageBytes added in v0.2.0

func ImageBytes(data []byte) (*Image, error)

ImageBytes wraps PNG or JPEG data. It reads the file signature to tell the two apart and rejects anything else: convert GIF, WebP and HEIC first. The data is not copied; do not change it after the call. See uploading images.

func ImageFile added in v0.2.0

func ImageFile(path string) (*Image, error)

ImageFile reads the file at path and wraps it like ImageBytes. The file name, without its extension, becomes a readable suffix of Image.Ref.

Example

An image goes in the state, or in a question, like any other value. The client uploads it as a multipart part and sends the header the API asks for. Box questions need Jev 1.14, so this pins jev-preview until jev-latest moves there.

package main

import (
	"context"
	"fmt"

	"github.com/kataras/jev"
)

func main() {
	photo, err := jev.ImageFile("kitchen.jpg")
	if err != nil {
		fmt.Println(err)
		return
	}
	client, err := jev.New(jev.WithModel(jev.ModelPreview))
	if err != nil {
		fmt.Println(err)
		return
	}
	resp, err := client.SystemOne(context.Background(), jev.Request{
		State: map[string]any{"photo": photo},
		Questions: jev.Questions{
			"mug_visible": jev.Noul{Instructions: "Is there a coffee mug in `photo`?"},
			"mug":         jev.Box{Instructions: "the coffee mug in `photo`"},
		},
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	if mug, ok := resp.Box("mug"); ok {
		// Edges are fractions of the image; Rect turns them into pixels.
		fmt.Println(mug.Confidence, mug.Rect(1024, 768))
	}
}

func ImageReader added in v0.2.0

func ImageReader(r io.Reader) (*Image, error)

ImageReader reads r to the end and wraps it like ImageBytes.

func (*Image) MarshalJSONTo added in v0.2.0

func (img *Image) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo encodes the image as its reference. On its own that is only the string; the upload happens when the image is part of a Request.

func (*Image) Ref added in v0.2.0

func (img *Image) Ref() string

Ref returns the reference string the model reads in place of the image. Answers and logs repeat the reference, never the image.

type Limiter

type Limiter interface {
	Wait(ctx context.Context) error
}

A Limiter blocks until the next request may be sent, or until ctx ends.

*rate.Limiter from golang.org/x/time/rate satisfies this as written, and NewLimiter returns one that also paces input tokens. An implementation must be safe for concurrent use: the client waits on it from every goroutine that sends, and a Limiter shared between clients is waited on by all of them.

The API counts requests and tokens per account, so two clients on the same key share one budget. Hand them the same Limiter with WithRateLimiter. See handling rate limits.

func NewLimiter

func NewLimiter(limit RateLimit) Limiter

NewLimiter returns a Limiter for limit. Pass it to WithRateLimiter on every client that shares the account, so they share one budget:

shared := jev.NewLimiter(jev.DefaultRateLimit())
fast, _ := jev.New(jev.WithModel("jev-latest"), jev.WithRateLimiter(shared))
pinned, _ := jev.New(jev.WithModel("jev-1.13.0"), jev.WithRateLimiter(shared))

Besides pacing, the limiter honors Retry-After. When a response carries one, every goroutine waiting on this limiter pauses until that time. A 429 tells the whole account to slow down, not only the call that saw it. See handling rate limits.

A zero limit returns nil, which disables pacing. The result is the interface rather than a concrete type on purpose: a nil pointer inside a non-nil interface would pass a nil check and panic on the first Wait.

type ModelInfo

type ModelInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	ReleaseDate string `json:"release_date"`
}

ModelInfo is one model the account can call, as returned by listing models. ReleaseDate is whatever string the API returns. The docs describe a calendar date; the service currently returns a full timestamp.

type Noul

type Noul struct {
	// Instructions is the question: a string, or any value that encodes as a
	// JSON object or array. Nil omits the field. See [structured instructions].
	//
	// [structured instructions]: https://docs.typesafe.ai/primitives/advanced#structured-instructions
	Instructions any
	// Criteria optionally describes what a yes and a no mean.
	Criteria *NoulCriteria
}

Noul asks a yes-or-no question. The answer is the probability that the answer is yes, from 0 to 1. The wire shape is under noul, and writing a noul question has advice on phrasing.

type NoulAnswer

type NoulAnswer struct {
	Noul float64
}

NoulAnswer is the probability that a yes/no question is yes, from 0 (no) to 1 (yes). See noul answer and reading a noul.

func (NoulAnswer) Type

func (NoulAnswer) Type() string

type NoulCriteria

type NoulCriteria struct {
	True  any `json:"true,omitzero"`
	False any `json:"false,omitzero"`
}

NoulCriteria describes the two outcomes of a Noul: what a value near 1 means, and what a value near 0 means. Nil fields are omitted. See noul and structured noul criteria.

type Option

type Option func(*config) error

Option configures a Client. Pass options to New, or to a single call. A call option overrides the client for that call only. An empty string means "not set" and leaves the current value in place.

The settings, their environment variables, and their defaults are the ones the official SDKs use; see client config.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the bearer token sent as Authorization: Bearer <key>. The default is the TYPESAFE_API_KEY environment variable, the same variable the official SDKs read; see API_KEY_ENV. Blank and whitespace-only values are ignored.

A missing or invalid key is a 401, returned as ErrUnauthorized; see errors.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the API root, for a proxy or a mock. It must be an http or https URL without credentials, a query, or a fragment. The default is TYPESAFE_BASE_URL, then https://api.typesafe.ai, the host of the evaluation endpoint. See BASE_URL_ENV.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient uses client for requests. Per-attempt deadlines are set on the request context, so a Timeout on client is a second, shorter limit. Nil is ignored. The client is not closed.

This is the place for a proxy, a custom TLS setup, or an in-process transport in tests. It plays the role of fetch in the JavaScript SDK.

func WithHeader

func WithHeader(key, value string) Option

WithHeader sets a header sent on every request, like defaultHeaders in the JavaScript SDK. Authorization, Accept, Content-Type, User-Agent, and the X-TypeSafe-* headers are reserved.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger. Info records one line per attempt. Debug adds headers and bodies. Authorization and cookie headers are redacted. Bodies are logged as sent, which includes your state. For a request with images, the JSON part is logged and the image bytes are not. Nil is ignored. Without a logger, TYPESAFE_LOG_LEVEL selects one on stderr, and an unset or "off" level logs nothing. The levels and the redaction rule follow the official SDKs; see logLevel and LOG_LEVEL_ENV.

func WithLongContext added in v0.2.0

func WithLongContext(enabled bool) Option

WithLongContext raises the input limits of a request from 64k tokens per request and 32k per question to 262k, by sending the TypeSafe-Danger-Zone-Long-Context header. It is off by default: the API documents long context as slower and less accurate, at the same price per token, so turn it on for the calls that need it, as a call option. Jev 1.13 and 1.14 both support it. See context length.

Example

Long context raises the input limits from 64k tokens per request and 32k per question to 262k. It is slower and less accurate, so turn it on for the calls that need it rather than for the whole client.

package main

import (
	"context"
	"fmt"

	"github.com/kataras/jev"
)

func main() {
	client, err := jev.New()
	if err != nil {
		fmt.Println(err)
		return
	}
	contract := "<a long contract, transcript, or record>"
	answer, err := client.Noul(context.Background(), contract,
		"Does the `state` include a clause that lets either party end the agreement early?",
		jev.WithLongContext(true))
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(answer.Noul > 0.5)
}

func WithModel

func WithModel(model string) Option

WithModel sets the model used when Request.Model is empty. The default is TYPESAFE_DEFAULT_MODEL, then ModelLatest; see DEFAULT_MODEL_ENV.

jev-latest is an alias and it moves with each release. Pin a version such as ModelJev114 when two runs must hit the same model, for example after tuning confidence thresholds. ModelPreview is the newest build of any kind; Box questions need it until jev-latest reaches Jev 1.14. See aliases and current models.

func WithRateLimit

func WithRateLimit(limit RateLimit) Option

WithRateLimit paces requests and input tokens to limit, on top of retries. The default is DefaultRateLimit, the documented account limit, so a client stays under it instead of finding it through 429 responses.

Pass the zero RateLimit to disable pacing. Pass it to New only: a limiter built for one call would start with a full budget and pace nothing. For one call, use WithRateLimiter with a limiter you own, or nil to skip pacing.

The limit is per account. Several clients on the same key should share one limiter through NewLimiter and WithRateLimiter. See current models.

Example

A plan with other limits, or one process out of several on the same key.

package main

import (
	"fmt"

	"github.com/kataras/jev"
)

func main() {
	client, err := jev.New(jev.WithRateLimit(jev.RateLimit{
		RequestsPerMinute: 300,
		TokensPerSecond:   60_000,
	}))
	if err != nil {
		fmt.Println(err)
		return
	}
	_ = client
}

func WithRateLimiter

func WithRateLimiter(l Limiter) Option

WithRateLimiter uses a Limiter you own, in place of the one WithRateLimit builds. Clients given the same Limiter share one budget, which is what an account-wide quota asks for. Nil disables pacing.

A plain *rate.Limiter paces requests only. The Limiter from NewLimiter also paces tokens and honors Retry-After. See handling rate limits.

As a call option it replaces the client's limiter for that call.

Example

The API limits are per account. Two clients on the same key share one limiter, so together they stay under the limit.

package main

import (
	"fmt"

	"github.com/kataras/jev"
)

func main() {
	shared := jev.NewLimiter(jev.DefaultRateLimit())

	latest, err := jev.New(jev.WithRateLimiter(shared))
	if err != nil {
		fmt.Println(err)
		return
	}
	pinned, err := jev.New(jev.WithModel("jev-1.13.0"), jev.WithRateLimiter(latest.Limiter()))
	if err != nil {
		fmt.Println(err)
		return
	}
	_, _ = latest, pinned
}

func WithRetry

func WithRetry(policy RetryPolicy) Option

WithRetry replaces the retry policy. Copy DefaultRetryPolicy and edit it. The zero RetryPolicy retries nothing.

The API asks clients to retry 429 and 529 with exponential backoff; see handling rate limits. The default policy does that, and WithRateLimit keeps the client under the limit in the first place.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the limit for one HTTP attempt, including reading the body. The default is 10 seconds, the same as the official SDKs; see timeout. There is no budget across retries unless RetryPolicy.MaxElapsed is set. The context you pass to the call also applies.

type Question

type Question interface {
	// contains filtered or unexported methods
}

Question is a Noul, Choice, Score, Box, or Raw. The kinds and how to pick one are described under question types and choose a question type.

type Questions

type Questions map[string]Question

Questions maps the name you choose to a question. It is the questions member of the request body. Answers come back under the same names. Names are not part of the prompt. On the wire, names are sorted so two equal requests encode to the same bytes.

type RateLimit

type RateLimit struct {
	// RequestsPerMinute caps how many requests this limiter lets through.
	// Requests are spread across the minute: the burst is one second's worth,
	// so a quiet client can send about RequestsPerMinute/60 at once.
	RequestsPerMinute int
	// TokensPerSecond caps input tokens. The body size is not known in tokens
	// before the call, so the limiter estimates from the body length, then
	// corrects itself with usage.input_tokens from each response.
	// The burst is one second's worth; a request larger than that waits for
	// a full second's budget.
	TokensPerSecond int
}

RateLimit is the client-side pacing for one account. Start from DefaultRateLimit and change the fields you care about. A zero field disables that axis; the zero RateLimit paces nothing.

The numbers to match are on the models page. They are per account, so if several processes share a key, divide the budget between them.

func DefaultRateLimit

func DefaultRateLimit() RateLimit

DefaultRateLimit is the documented limit for Jev 1.13 and 1.14: 1,200 requests per minute and 250,000 input tokens per second. See current models.

func (RateLimit) IsZero

func (l RateLimit) IsZero() bool

IsZero reports whether the limit paces nothing.

type Raw

type Raw map[string]any

Raw is a question object sent as-is, for a kind this version does not model. It must include a non-empty string field named type. Known kinds are validated the same way as Noul, Choice, Score, and Box. The current kinds are listed under question types.

type Request

type Request struct {
	// State is the content every question reads. A string, a map, a slice, or
	// a struct with json tags. A []byte is sent as text, not as base64.
	// Nil is sent as JSON null. An *[Image] anywhere inside is uploaded and
	// replaced by its reference. What to put in it, and how to point a
	// question at a nested field, is under [state].
	//
	// [state]: https://docs.typesafe.ai/concepts/state
	State any
	// Questions is the non-empty set of named questions.
	Questions Questions
	// Model overrides the client default when non-empty. See [models].
	//
	// [models]: https://docs.typesafe.ai/models#current-models
	Model string
	// Extra adds top-level JSON fields this version does not model.
	// Keys state, model, questions, and assets are reserved and rejected.
	// An [Image] in Extra is rejected too; put it in State or in a question.
	Extra map[string]any
}

Request is the input to Client.SystemOne: the request body of one POST to /v1/systemone.

type Response

type Response struct {
	Model     string
	Answers   map[string]Answer
	Usage     Usage
	RequestID string
	Attempts  int
	// contains filtered or unexported fields
}

Response is a successful System One result: the response body of one call. Model is the versioned ID that answered, even when the request named an alias. Attempts counts HTTP attempts including retries.

func (*Response) As

func (r *Response) As[T any]() (T, error)

As decodes the response JSON into T. JSON object names are case-sensitive. Unknown object members are ignored. The names to mirror in T are under response body and answer types.

func (*Response) Box added in v0.2.0

func (r *Response) Box(name string) (BoxAnswer, bool)

Box returns the box answer named name. See box.

func (*Response) Choice

func (r *Response) Choice(name string) (ChoiceAnswer, bool)

Choice returns the choice answer named name. See choice answer.

func (*Response) Noul

func (r *Response) Noul(name string) (NoulAnswer, bool)

Noul returns the yes/no answer named name. See noul answer.

func (*Response) Raw

func (r *Response) Raw() []byte

Raw returns a copy of the response JSON, in the shape of the response body.

func (*Response) Score

func (r *Response) Score(name string) (ScoreAnswer, bool)

Score returns the score answer named name. See score answer.

type ResponseError

type ResponseError struct {
	Method    string
	URL       string
	RequestID string
	Field     string
	Body      []byte
	Err       error
}

ResponseError is a 2xx body that failed validation, or a body over the size limit. Field is the JSON path that failed, such as answers.team.choice. The contract it checks is the response body and its answer types; the official SDKs raise the same thing as response validation errors.

func (*ResponseError) Error

func (e *ResponseError) Error() string

func (*ResponseError) Is

func (e *ResponseError) Is(target error) bool

func (*ResponseError) Unwrap

func (e *ResponseError) Unwrap() error

type RetryPolicy

type RetryPolicy struct {
	// MaxRetries is how many retries follow the first attempt. 0 disables retries.
	// SDK name: maxRetries.
	MaxRetries int
	// InitialBackoff is the first backoff delay, doubled on each retry up to MaxBackoff.
	// SDK name: backoffInitialMs.
	InitialBackoff time.Duration
	// MaxBackoff caps the computed backoff. SDK name: backoffMaxMs.
	MaxBackoff time.Duration
	// Jitter is the fraction of each backoff delay that may be subtracted, from 0 to 1.
	// SDK name: backoffJitter.
	Jitter float64
	// Statuses are the HTTP status codes that are retried. SDK name: httpStatuses.
	Statuses []int
	// RespectRetryAfter honors Retry-After-Ms and Retry-After when the delay
	// is within MaxRetryAfter. A longer server delay falls back to backoff.
	// SDK name: respectRetryAfter.
	RespectRetryAfter bool
	// MaxRetryAfter is the longest server-requested delay that is honored,
	// by retries and by the pause a [Limiter] from [NewLimiter] applies to
	// every caller. SDK name: maxRetryAfterMs.
	MaxRetryAfter time.Duration
	// RetryConnection retries connection failures. SDK name: apiConnectionError.
	RetryConnection bool
	// RetryTimeout retries an attempt that hit the per-attempt timeout.
	// SDK name: apiTimeoutError.
	RetryTimeout bool
	// MaxElapsed is a budget for the whole call, including waits between attempts.
	// Zero means there is no budget. The caller's context always applies.
	MaxElapsed time.Duration
	// contains filtered or unexported fields
}

RetryPolicy controls retries after the first attempt. Start from DefaultRetryPolicy and change the fields you care about. A policy built from the zero value retries nothing, because Statuses is empty.

The fields mirror the official SDKs' RetryPolicy, with Go names and durations. The API's own advice on what to retry is under handling rate limits.

func DefaultRetryPolicy

func DefaultRetryPolicy() RetryPolicy

DefaultRetryPolicy matches the official JavaScript SDK: 2 retries, 500ms backoff doubling to 5s, 25% jitter, and retries on 408, 429, and 500-599. Retry-After is honored up to 60s. There is no total time budget unless you set MaxElapsed. The defaults are listed field by field under RetryPolicy.

type Score

type Score struct {
	Instructions any
	Criteria     any
}

Score rates the state against an ordered rubric. Criteria is a JSON array of level descriptions, lowest first, such as a []string or []any. The API schema requires at least one level. The public docs cap a score at 10 levels, and this client enforces that cap. A map is rejected: since SDK 0.6.0, score criteria are a list, not an object. The wire shape is under score; writing good levels has advice on the rubric.

type ScoreAnswer

type ScoreAnswer struct {
	Score         float64
	Confidence    float64
	Legend        map[string]any
	Probabilities map[string]float64
}

ScoreAnswer is a probability-weighted position along the rubric. Score can fall between levels. Legend maps the level index, as a string, back to the description you sent. Probabilities uses those same string keys. See score answer and reading a score.

func (ScoreAnswer) Type

func (ScoreAnswer) Type() string

type Text added in v0.2.0

type Text []any

Text is a string assembled from parts, where an *Image part becomes its reference. It is how an image is mentioned inside a sentence:

jev.Noul{Instructions: jev.TextOf("Is the dog in `photo` the same dog as in this picture: ", poster, "?")}

Other parts are formatted as fmt.Sprint formats them. See images.

func TextOf added in v0.2.0

func TextOf(parts ...any) Text

TextOf returns a Text made of parts.

func (Text) MarshalJSONTo added in v0.2.0

func (t Text) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo encodes the text as one JSON string.

type UnknownAnswer

type UnknownAnswer struct {
	Kind string
	Raw  []byte
}

UnknownAnswer is a question kind this version does not model. Raw is the JSON object for that answer. The kinds this version knows are listed under answer types.

func (UnknownAnswer) Type

func (a UnknownAnswer) Type() string

type Usage

type Usage struct {
	InputTokens  int
	OutputTokens int
}

Usage counts tokens for one call. Input tokens are billed and count toward the token rate limit; output tokens are free. See usage and current models.

Directories

Path Synopsis
examples
box command
Command box draws a red rectangle on a white PNG and asks Jev where it is.
Command box draws a red rectangle on a white PNG and asks Jev where it is.
quickstart command
Command quickstart calls System One with one of each question type.
Command quickstart calls System One with one of each question type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL