Getting Started

Get up and running with LLM4S in minutes.

Open in GitHub Codespaces Nothing to install: the playground runs the samples in your browser against a small local model.

This section will guide you through:

  1. Installation - Set up LLM4S in your project
  2. First Example - Write your first LLM-powered program
  3. Configuration - Configure providers and API keys
  4. Next Steps - Choose your learning path
  5. Ollama Quick Start - Local LLM development (no API keys needed)
  6. Gradle Integration - Use LLM4S from a Gradle (Java or Kotlin) build
  7. Scala CLI Quick Start - A first LLM call from a single file, with no sbt project
  8. Maven Quick Start - A complete pom.xml that runs a first call from Java with llm4s-java-api
  9. JBang Quick Start - A first LLM call from one Java file, with no build tool
  10. Mill Quick Start - A build.mill project with a first call and a test that needs no API key
  11. From Java, Spring Boot or Kotlin - the Java guide, the Spring Boot starter and Kotlin coroutines (llm4s-kotlin-api 0.5.1 is not on Maven Central yet; that section says how to build it)
  12. First-Run Troubleshooting - Symptoms, causes and fixes for the problems a first run most often hits
  13. Using LLM4S from Scala 2.13 - Call LLM4S from a Scala 2.13 project through the TASTy reader
  14. Playground (Codespaces) - Try LLM4S in the browser: a GitHub Codespace with a local model, no install and no API key
  15. Try llm4s in the REPL - ask, extract and chat() 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:


Ready? Start with installation →


Table of contents