Quick Start Install Ax and run a typed LLM program. rust quick-start quick-start website/content-src/templates/quick-start.md quick-start Quick Start

Quick Start

Ax gives Rust 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

Shell
cargo add axllm

Set Your API Key

The first program uses OpenAI. Export the key in the same terminal where you will run it.

Shell
export OPENAI_API_KEY="sk-..."
cargo new quickstart && cd quickstart && cargo add axllm serde_json

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 src/main.rs.

Rust
use axllm::{ai, ax, AxResult};
use serde_json::json;

fn main() -> AxResult<()> {
    let mut llm = ai("openai", json!({"apiKey": std::env::var("OPENAI_API_KEY")?}))?;
    let mut classify = ax("review:string -> sentiment:class \"positive, negative, neutral\"")?;
    let result = classify.forward(&mut llm, json!({
        "review": "Useful and boring in the best way."
    }))?;

    println!("sentiment: {}", result["sentiment"].as_str().unwrap_or_default());
    Ok(())
}

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

Shell
cargo run

You should see:

text
sentiment: positive

The 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 Rust.

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.

Docs