shipwithjev

Catalog / Tools & apps

0492GitHub

typesafe-java

JDK 21+ client, modular by design, with a dedicated testkit module for unit testing callers.

dfa1/typesafe-javaREADME ↗
# typesafe-java

[](https://github.com/dfa1/typesafe-java/actions/workflows/ci.yml)
[](https://central.sonatype.com/artifact/io.github.dfa1.typesafe-java/typesafe-java-core)
[](https://sonarcloud.io/summary/new_code?id=dfa1_typesafe-java)
[](https://sonarcloud.io/summary/new_code?id=dfa1_typesafe-java)

Java 21 client for the [TypeSafe API](https://api.typesafe.ai). Send a state (any JSON value)
plus a set of `Noul`/`Choice`/`Score` questions, get back typed answers.

Save a token to `~/.typesafe.apitoken` first — either way below picks it up automatically.

## Quickstart

### As a Java library

```java
ApiKey token = ApiKey.fromDefaultFile(); // reads ~/.typesafe.apitoken
// or: ApiKey.fromEnv();                 // reads the TYPESAFE_API_KEY environment variable
TypeSafeClient client = TypeSafeClient.builder(token).build();

EvaluateRequest request = EvaluateRequest.of(
        State.text("Help! My payouts have been failing for 3 days."),
        Map.of("is_urgent", Question.noul("Does this convey urgency?")));

Answer.Noul answer = client.evaluate(request).nouls().get("is_urgent");
answer.noul(); // e.g. 0.92
```

See [Install](#install) below to add it as a dependency, or the [tutorial](docs/tutorial.md)
for the full walkthrough — including every way to provide the token, in
[how-to.md](docs/how-to.md#provide-your-api-token).

### From the command line

No Java coding required — the `cli` module builds a self-contained uber-jar, handy for wiring a
check into a Jenkins job, a shell script, or any other CI pipeline without writing a line of
Java. Download it from
[Maven Central](https://central.sonatype.com/artifact/io.github.dfa1.typesafe-java/typesafe-java-cli)
(under the `all` classifier — the plain artifact is just this module's own classes, not
runnable on its own

Also filed under Tools & apps