Installation
Get LLM4S up and running in minutes.
Table of contents
- Prerequisites
- Add LLM4S to Your Project
- Quick Start with the Starter Kit
- Optional Dependencies
- API Keys Setup
- Verify Installation
- Troubleshooting
- Next Steps
- Additional Resources
Prerequisites
Before installing LLM4S, ensure you have:
- Java Development Kit (JDK) 21
- Scala 3.7.1
- SBT 1.10.6 or higher
- An API key from at least one LLM provider (OpenAI, Anthropic, Azure OpenAI, or Ollama)
Verify Prerequisites
1
2
3
4
5
6
7
8
# Check Java version
java -version # Should show 21
# Check Scala version
scala -version # 3.7.1
# Check SBT version
sbt version # 1.10.6 or higher
Add LLM4S to Your Project
Artifact coordinates changed in 0.4.0. Every published module now carries an
llm4s-prefix (core→llm4s-core,workspaceClient→llm4s-workspace-client, and so on). Releases up to and including0.3.4remain available under the old names. See the migration guide for the full old → new table.
SBT
Add LLM4S to your build.sbt:
1
2
3
// Scala 3
libraryDependencies += "org.llm4s" %% "llm4s-core" % "0.4.0"
ThisBuild / scalaVersion := "3.7.1"
Maven
1
2
3
4
5
6
7
<!-- For Scala 3 -->
<dependency>
<groupId>org.llm4s</groupId>
<artifactId>llm4s-core_3</artifactId>
<version>0.4.0</version>
</dependency>
Multi-Module Project
If you have a multi-module project:
1
2
3
4
5
6
7
8
lazy val myProject = (project in file("."))
.settings(
name := "my-llm-project",
scalaVersion := "3.7.1",
libraryDependencies ++= Seq(
"org.llm4s" %% "llm4s-core" % "0.4.0"
)
)
Snapshot Versions
To use the latest development snapshot:
1
2
resolvers += Resolver.sonatypeRepo("snapshots")
libraryDependencies += "org.llm4s" %% "llm4s-core" % "0.4.0-SNAPSHOT"
Quick Start with the Starter Kit
The fastest way to get started is using the llm4s.g8 template:
1
2
3
4
5
6
7
8
9
10
11
# Install the template
sbt new llm4s/llm4s.g8
# Follow the prompts
# name [My LLM Project]: my-awesome-agent
# organization [com.example]: com.mycompany
# scala_version [3.7.1]:
# llm4s_version [0.4.0]:
cd my-awesome-agent
sbt run
The starter kit includes:
- ✅ Pre-configured SBT build
- ✅ Example agent with tool calling
- ✅ Configuration templates
- ✅ Multi-provider setup
- ✅ Docker configuration for workspace
Optional Dependencies
Additional modules are published separately. The core library includes most functionality. Check Maven Central for available artifacts.
For RAG, vector stores, chunking, reranking and document extraction
Not yet published.
llm4s-ragexists in the build as of #1128 but ships in the next release; in0.4.1and earlier this code is still insidellm4s-core.
1
2
// same version as llm4s-core
libraryDependencies += "org.llm4s" %% "llm4s-rag" % llm4sVersion
Brings llm4s-knowledgegraph with it, along with Tika, POI, PDFBox, jsoup and the AWS S3
client — the document-extraction and loader dependencies that llm4s-core no longer carries.
Package names are unchanged, so existing org.llm4s.rag.* imports keep working; see the
migration note.
For agent memory
Not yet published.
llm4s-memoryandllm4s-memory-postgresexist in the build as of #1129 but ship in the next release; in0.4.1and earlier this code is still insidellm4s-core.
1
2
3
4
5
// same version as llm4s-core
libraryDependencies += "org.llm4s" %% "llm4s-memory" % llm4sVersion
// only if you store memories in Postgres/pgvector
libraryDependencies += "org.llm4s" %% "llm4s-memory-postgres" % llm4sVersion
llm4s-memory carries MemoryStore, the memory managers, and the in-memory and SQLite-backed
stores; it adds sqlite-jdbc to your classpath and nothing else. PostgresMemoryStore lives in
llm4s-memory-postgres, which brings HikariCP and the Postgres JDBC driver — the two
dependencies llm4s-core no longer carries. Package names are unchanged, so existing
org.llm4s.agent.memory.* imports keep working; see the
migration note.
For MCP (Model Context Protocol)
Not yet published.
llm4s-mcpexists in the build as of #1130 but ships in the next release; in0.4.1and earlier this code is still insidellm4s-core.
1
2
// same version as llm4s-core
libraryDependencies += "org.llm4s" %% "llm4s-mcp" % llm4sVersion
Carries the MCP client, server, transports (stdio, HTTP, SSE) and MCPToolRegistry. It adds no
third-party dependency of its own. Package names are unchanged, so existing org.llm4s.mcp.*
imports keep working; see the
migration note.
For speech (STT / TTS)
Not yet published.
llm4s-speechexists in the build as of #1130 but ships in the next release; in0.4.1and earlier this code is still insidellm4s-core.
1
2
// same version as llm4s-core
libraryDependencies += "org.llm4s" %% "llm4s-speech" % llm4sVersion
Carries speech-to-text (Vosk for offline recognition, Whisper), text-to-speech (Tacotron 2),
and the audio IO, conversion and validation helpers. This is the module that brings Vosk,
a 25 MB dependency that used to sit on every llm4s-core user’s classpath — which is much of
the point of the split. Package names are unchanged; see the
migration note.
For image generation and vision
Not yet published.
llm4s-imageexists in the build as of #1130 but ships in the next release; in0.4.1and earlier this code is still insidellm4s-core.
1
2
// same version as llm4s-core
libraryDependencies += "org.llm4s" %% "llm4s-image" % llm4sVersion
Carries image generation (org.llm4s.imagegeneration — Stable Diffusion, Stability AI,
Hugging Face, OpenAI) and image processing (org.llm4s.imageprocessing — the OpenAI and
Anthropic vision clients plus a local javax.imageio processor). It adds no third-party
dependency of its own, and brings llm4s-media with it.
Package names are unchanged, so existing org.llm4s.imagegeneration.* and
org.llm4s.imageprocessing.* imports keep working — but note that image formats did change,
in llm4s-media. See the migration note.
For media types (MediaType, MediaCategory)
Not yet published.
llm4s-mediaexists in the build as of #1130 but ships in the next release.
1
2
// same version as llm4s-core
libraryDependencies += "org.llm4s" %% "llm4s-media" % llm4sVersion
The shared vocabulary the multimodal modules speak: MediaType (MIME string, canonical
extension, category, and lookups by extension, path or MIME type) and MediaCategory. It has
no dependencies at all and does no I/O — deciding what a file is from its bytes needs Tika and
lives in llm4s-rag.
You will usually get it transitively, from llm4s-core or llm4s-rag; declare it directly
only if you name these types in your own signatures. It replaces three overlapping image-format
types that used to ship in llm4s-core, which is a source break — see the
migration note.
For Workspace (Containerized Execution)
1
libraryDependencies += "org.llm4s" %% "llm4s-workspace-client" % "0.4.0"
And install Docker:
1
2
3
4
5
6
7
8
# macOS
brew install docker
# Ubuntu/Debian
sudo apt-get install docker.io
# Verify
docker --version
API Keys Setup
LLM4S requires API keys for your chosen provider(s). You can configure these via:
- Environment variables (recommended)
- Configuration files (
application.conf) - System properties (
-Dflags)
Environment Variables
Create a .env file in your project root (add to .gitignore!):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Choose your provider
LLM_MODEL=openai/gpt-4o
# OpenAI
OPENAI_API_KEY=sk-proj-...
OPENAI_BASE_URL=https://api.openai.com/v1 # Optional
# Anthropic
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_BASE_URL=https://api.anthropic.com # Optional
# Azure OpenAI
AZURE_API_KEY=your-azure-key
AZURE_API_BASE=https://your-resource.openai.azure.com
AZURE_DEPLOYMENT_NAME=gpt-4o
# Ollama (local)
OLLAMA_BASE_URL=http://localhost:11434
# Cohere
COHERE_API_KEY=your-cohere-api-key
COHERE_BASE_URL=https://api.cohere.com # Optional
Load the .env file before running:
1
2
source .env
sbt run
Or use sbt-dotenv plugin:
1
2
// project/plugins.sbt
addSbtPlugin("au.com.onegeek" %% "sbt-dotenv" % "2.1.233")
Get API Keys
OpenAI
- Go to platform.openai.com
- Sign up or log in
- Navigate to API Keys
- Click Create new secret key
- Copy the key (starts with
sk-)
Anthropic
- Go to console.anthropic.com
- Sign up or log in
- Navigate to API Keys
- Click Create Key
- Copy the key (starts with
sk-ant-)
Azure OpenAI
- Create an Azure account
- Navigate to Azure OpenAI Service
- Create a resource
- Deploy a model (e.g., gpt-4o)
- Copy the API Key and Endpoint
Ollama (Local)
- Install Ollama: ollama.com
- Pull a model:
ollama pull llama2 - Start server:
ollama serve - No API key needed!
Verify Installation
Create a simple test file VerifyInstall.scala:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import org.llm4s.config.Llm4sConfig
import org.llm4s.llmconnect.LLMConnect
import org.llm4s.llmconnect.model.UserMessage
object VerifyInstall extends App {
println("Testing LLM4S installation...")
val result = for {
providerConfig <- Llm4sConfig.provider()
client <- LLMConnect.getClient(providerConfig)
response <- client.complete(
messages = List(UserMessage("Say 'LLM4S is working!'")),
model = None
)
} yield response
result match {
case Right(completion) =>
println("✅ Success!")
println(s"Response: ${completion.content}")
case Left(error) =>
println("❌ Error:")
println(error)
}
}
Run it:
1
sbt run
Expected output:
1
2
3
Testing LLM4S installation...
✅ Success!
Response: LLM4S is working!
Troubleshooting
“API key not found”
Problem: LLM4S can’t find your API key.
Solution:
- Verify
.envfile exists and is in project root - Check you’ve sourced it:
source .env - Verify variable name matches your provider (e.g.,
OPENAI_API_KEY) - Check for typos in the key
“Provider not supported”
Problem: Invalid LLM_MODEL format.
Solution: Use the correct format:
- OpenAI:
openai/gpt-4o - Anthropic:
anthropic/claude-sonnet-4-5-latest - Azure:
azure/gpt-4o - Ollama:
ollama/llama2
Compilation Errors
Problem: Scala version mismatch.
Solution:
1
2
3
# Clean and recompile
sbt clean
sbt compile
Dependency Resolution Issues
Problem: Can’t resolve LLM4S dependency.
Solution:
- For release versions, no additional resolver needed (uses Maven Central)
- For snapshots, add the resolver:
1
resolvers += Resolver.sonatypeRepo("snapshots")
Next Steps
Now that LLM4S is installed:
- Write your first program → - Create a simple LLM application
- Configure providers → - Set up multiple LLM providers
- Explore examples → - Browse 69 working examples
Additional Resources
- GitHub Repository: llm4s/llm4s
- Starter Kit: llm4s.g8
- Discord Community: Join us
- API Reference: Core API
Installation complete! Ready to write your first program →