Quick Start
Ax gives Java one typed contract for LLM programs: signatures for data shape, ai() for model access, ax() for structured generation, agent() for tool-using runtime loops, and AxGEPA for improving programs with examples.
Install
// Gradle (build.gradle):
implementation 'dev.axllm:ax:24.0.15'
// Maven (pom.xml):
<dependency>
<groupId>dev.axllm</groupId>
<artifactId>ax</artifactId>
<version>24.0.15</version>
</dependency>Set Your API Key
The first program uses OpenAI. Export the key in the same terminal where you will run it.
export OPENAI_API_KEY="sk-..."
mvn dependency:copy -Dartifact=dev.axllm:ax:24.0.15 -DoutputDirectory=.First Program
Start with a small typed task. The signature declares the fields the model receives and the fields Ax must parse back out. Save this as QuickStart.java.
import dev.axllm.ax.Ax;
import java.util.Map;
public class QuickStart {
public static void main(String[] args) throws Exception {
var llm = Ax.ai("openai", Map.of("apiKey", System.getenv("OPENAI_API_KEY")));
var classify = Ax.ax("review:string -> sentiment:class \"positive, negative, neutral\"");
var result = classify.forward(llm, Map.of(
"review", "Useful and boring in the best way."
));
System.out.println("sentiment: " + result.get("sentiment"));
}
}That is the core loop:
- create a provider client
- declare the input and output contract
- run the program with typed inputs
- read typed outputs instead of scraping prose
flowchart LR A["ai() client"] --> C["forward() with typed inputs"] B["Signature"] --> C C --> D["Validate + retry"] D --> E["Typed output"]
Run It
javac -cp ax-24.0.15.jar QuickStart.java
java -cp ".:ax-24.0.15.jar" QuickStartYou should see:
sentiment: positiveThe model’s wording can vary, but the declared class shape is guaranteed.
The rest of the site keeps the same concepts but swaps install commands, imports, examples, and API names for Java.
Where To Go Next
Use Examples when you want runnable files. Use Concepts when you want the mental model. Use Subsystems when you know which surface you are trying to use and want the practical call shape.