01 - ChatModel with Anthropic (Claude)
Basic LangChain4j example: create a Claude chat model and send one prompt.
What it demonstrates
- Building an
AnthropicChatModelwith the builder (API key, model name, temperature, max tokens). - Calling
model.chat(String)and reading the text answer. - Reading the API key from the
ANTHROPIC_API_KEYenvironment variable.
Stack
| Component | Version / detail |
|---|---|
| Java | 21 |
| LangChain4j (Anthropic module) | 1.24.1 |
| Model | claude-haiku-5-5 |
| Build | Maven, exec-maven-plugin 3.5.0 |
Diagrams
English
EspaƱol
Run
export ANTHROPIC_API_KEY=your-key-here mvn -q compile exec:java