Core
What every LLM4S application uses, whatever else it builds on top: a client for a provider, a call, its Result, and
the options around it.
Calling a model
- Basic Usage - Get started with LLM calls, client creation, and error handling
- Providers - Overview of supported providers and how to configure them
- Error Handling - Work with
Result[A]andLLMError: pattern matching, for-comprehensions, every error type, recovery and testing - Reliable LLM Calling -
ReliableClient: retry policies, a circuit breaker, deadlines and local rate limiting around any client - Cost Controls - Thinking and reasoning effort per provider, provider-side prompt caching and service tiers
- Caching - Cache embeddings (exact) and model responses (semantic): configuration, keys, TTL, eviction and what the cache reports
- Your HTTP Client -
llm4s-sttpsends the provider clients’ requests through the sttp backend your service already has
Prompts and typed replies
- Typed Prompts -
prompt"..."andsystem"...": values rendered by a type class checked at compile time, and untrusted input fenced - Structured Output -
completeStructured: typed replies from a schema, which providers enforce it, and what a bad reply looks like - Derived Schemas - Write the type once:
llm4s-schema-derivationbuilds thecompleteStructuredschema from a case class withderives - JSON Libraries - Use circe, play-json, zio-json or jsoniter-scala with LLM4S: converting at the boundary, structured output and tools
Images, speech and decisions
- Multimodal Content - Send images and documents in a user message or a tool result, and check before the request whether the provider takes them
- Media Types -
llm4s-media: theMediaType,MediaCategoryandMediaSourcevocabulary that multimodal messages, image generation and RAG extraction share - Capability-Typed Clients - Check once that a model can see images or call tools, and let the compiler refuse an unchecked client (experimental)
- Image Generation - Generate images with OpenAI GPT Image, Stability AI, Hugging Face or a Stable Diffusion server
- Speech - Speech-to-text (STT) and text-to-speech (TTS), local and cloud
- STT Domain Model -
STTOptions,WordTimestamp,Transcriptionand theSTTErrorcases - Jev decision model - Ask TypeSafe’s Jev typed questions (Noul, Choice, Score) and get typed answers: a decision client, not a chat model
Testing and extending
- Testing with the Testkit - Script an
LLMClientin your tests: canned replies, tool calls, injected errors, recorded requests - Writing a Provider - Publish your own provider module against the
llm4s-coreSPI
Table of contents
- Basic Usage
- Providers
- Error Handling
- Reliable LLM Calling
- Typed Prompts
- Structured Output
- Derived Schemas
- Multimodal content
- Media Types
- Capability-Typed Clients
- Cost controls
- Caching
- Your HTTP Client
- Testing with the Testkit
- JSON Libraries
- Writing a Provider
- Image Generation
- Speech (STT/TTS)
- STT Domain Model
- Jev decision model