Getting Started
Get up and running with LLM4S in minutes.
Nothing to install: the playground runs the samples in your browser against a small local model.
This section will guide you through:
- Installation - Set up LLM4S in your project
- First Example - Write your first LLM-powered program
- Configuration - Configure providers and API keys
- Next Steps - Choose your learning path
- Ollama Quick Start - Local LLM development (no API keys needed)
- Gradle Integration - Use LLM4S from a Gradle (Java or Kotlin) build
- Scala CLI Quick Start - A first LLM call from a single file, with no sbt project
- Maven Quick Start - A complete
pom.xmlthat runs a first call from Java withllm4s-java-api - JBang Quick Start - A first LLM call from one Java file, with no build tool
- Mill Quick Start - A
build.millproject with a first call and a test that needs no API key - From Java, Spring Boot or Kotlin - the Java guide, the Spring Boot starter
and Kotlin coroutines (
llm4s-kotlin-api0.5.1 is not on Maven Central yet; that section says how to build it) - First-Run Troubleshooting - Symptoms, causes and fixes for the problems a first run most often hits
- Using LLM4S from Scala 2.13 - Call LLM4S from a Scala 2.13 project through the TASTy reader
- Playground (Codespaces) - Try LLM4S in the browser: a GitHub Codespace with a local model, no install and no API key
- Try llm4s in the REPL -
ask,extractandchat()behind one import, in the Scala CLI REPL, a worksheet or a script
The current release is 0.5.1, for Scala 3.7.x on JDK 21.
Quick Start
The fastest way to get started:
1
2
3
4
5
6
7
8
# 1. Use the starter template, on the current release
sbt new llm4s/llm4s.g8 --llm4s_version=0.5.1
# 2. Set the API key - llm4s-openai reads it for the template's openai-main section
export OPENAI_API_KEY=sk-...
# 3. Run your first program
sbt run
Check that the generated build.sbt lists a provider module (such as llm4s-openai) next to llm4s-core: since
0.5.0 llm4s-core ships none. The template update for 0.5.x (llm4s.g8#6)
adds llm4s-ollama and llm4s-openai and defaults to a local Ollama section (choose OpenAI with
LLM4S_PROVIDER=openai-main); an older template lists llm4s-core only, so add the provider yourself
(Installation shows how).
llm4s reads providers from named sections in application.conf, not from variables of its own;
see Configuration to add or switch providers.
What You’ll Learn
By the end of this section, you’ll:
- ✅ Have LLM4S installed and configured
- ✅ Understand Result-based error handling
- ✅ Know how to make basic LLM calls
- ✅ Be able to configure multiple providers
- ✅ Know where to go next based on your goals
Prerequisites
Before starting, you should have:
- JDK 21
- Scala 3.7.x (llm4s is built with 3.7.1)
- sbt 1.10.6+
- An API key from OpenAI, Anthropic, Azure OpenAI or another provider, or Ollama installed
Time to Complete
- Quick Start: ~5 minutes (with starter kit)
- Full Tutorial: ~30 minutes
Need Help?
If you get stuck:
- Check the troubleshooting guides
- Ask in Discord
- Browse examples
Ready? Start with installation →