Calling a large language model from Java used to mean writing HTTP clients, parsing JSON by hand and wiring retries yourself. LangChain4j removes most of that plumbing. In this article we build the smallest useful program: a Java 21 application that creates a Claude chat model with LangChain4j and sends a single prompt. The code is small on purpose, so every line has a clear job, and the structure is the same one you will reuse for tools, memory, retrieval and agents later.
The complete source is in github.com/josesaid/01-chatmodel-anthropic , and a project page with the diagrams is available at josesaid.github.io/01-chatmodel-anthropic .
What you will build
The application does four things:
Reads the Anthropic API key from an environment variable.
Builds an AnthropicChatModel with the builder pattern.
Sends one question with chat(String) .
Prints the question and the answer.
The flow looks like this:
Your Java app -> AnthropicChatModel (LangChain4j) -> Claude API chat(prompt) HTTPS request answer…