java-ai-cookbook logo

java-ai-cookbook

Free

Runnable, minimal LLM examples for Java - Spring AI & LangChain4j. RAG, agents, MCP servers, tool calling, structured output, evals.

Visit Website
Related by shared tags and keywordsllm-engineering-programiloveAgentsSCHOLARAGENT
generative-aiaiai-agentsanthropiccookbookai assistantautomation

Overview

The java-ai-cookbook is a repository of runnable, minimal LLM examples for Java, covering both Spring AI and LangChain4j. It includes recipes for RAG, agents, MCP servers, tool calling, structured output, and evals. Each example is isolated, has its own build, and runs in under a minute. The repository aims to fill the gap between a single hello-world and a full demo app with many dependencies, showing one pattern per recipe in one file where possible, with no framework magic hidden. The same pattern is implemented in both Spring AI and LangChain4j for comparison, and works with OpenAI, Anthropic, and local models via Ollama, switchable with an environment variable. Every recipe has a test to prevent silent rot. The repository contains 20 recipes, each with a README following the same shape: What / Run / Where to look / Gotchas. Configuration uses environment variables such as OPENAI_API_KEY, ANTHROPIC_API_KEY, OLLAMA_BASE_URL, AI_PROVIDER, and EMBEDDING_PROVIDER. Requirements include Java 21+, Docker for certain recipes, and one of an OpenAI key, Anthropic key, or local Ollama. The project is MIT licensed.

Pricing

Free

Detailed plans have not been confirmed in our catalog. Check the official website for current limits and billing terms.

Visit Website

Prices and limits may change. Confirm the currency, billing period, seat minimum and usage caps on the official website.

Use Cases

  • Developers use the cookbook to learn chat basics with ChatClient or ChatModel, system prompts, and model switching.
  • Teams use the cookbook to implement streaming of tokens to console and SSE endpoints.
  • Developers use the cookbook to enforce structured output from LLMs into Java records with schema enforcement and retries.
  • Teams use the cookbook to expose Java methods as tools for LLM tool calling and multi-step calls.
  • Developers use the cookbook to build RAG pipelines from loading and splitting to embedding, retrieval, and answering.
  • Teams use the cookbook to implement a ReAct agent loop with planning, tool selection, and stopping conditions.
  • Developers use the cookbook to consume tools from an MCP server or expose a Java service as an MCP server.
  • Teams use the cookbook to set up observability with tracing, token/cost metrics, and Micrometer.

Features

Runnable Java LLM examples

Spring AI example projects

LangChain4j example projects

Retrieval augmented generation examples

Agent and tool calling examples

MCP server examples

Structured output examples

LLM evaluation examples

Reviews

No reviews yet. Be the first to share your experience!