
http4k AI is a lightweight AI integration toolkit which provides simplified adapters for connecting to popular LLM providers and AI services using http4k compatible APIs, along with comprehensive Fake implementations for deterministic testing. These are all underpinned by the uniform Server as a Function model powered by the HttpHandler
interface exposed by http4k Core, so you can:
- Build AI-powered applications using http4k’s proven functional design patterns.
- Test AI integrations completely offline with predictable, deterministic behavior.
- Access underlying HTTP clients for observability, metrics, and debugging.
- Run comprehensive Fake AI services locally without external dependencies or API costs.
- Avoid vendor lock-in through consistent, composable interfaces.
Although designed for http4k-based projects, http4k-ai libraries are usable from any JVM application.
Rationale
Most AI integration libraries are heavyweight, opinionated frameworks that hide HTTP details and make testing difficult. They often require real API calls during development, leading to unpredictable tests and mounting token costs. http4k-ai provides a lightweight alternative focused on:
- Testability First: Every AI service includes a full Fake implementation for deterministic testing
- Functional Design: Pure functions and immutable data structures throughout
- HTTP Transparency: Full access to underlying HTTP for debugging and observability
- Minimal Dependencies: Lightweight implementations covering essential use cases
- Vendor Neutrality: Consistent interfaces across different AI providers
Installation
dependencies {
// install the platform...
implementation(platform("org.http4k:http4k-bom:6.12.0.0"))
// ...then choose an AI provider
implementation("org.http4k:http4k-ai-openai")
// ...a fake for testing (essential)
testImplementation("org.http4k:http4k-ai-openai-fake")
}