Welcome to LiteLLM Clojure! This guide will help you get up and running quickly.
Add to your deps.edn:
{:deps {tech.unravel/litellm-clj {:mvn/version "0.2.0"}}}
Add to your project.clj:
[tech.unravel/litellm-clj "0.2.0"]
LiteLLM provides two API styles: Router API (recommended for most use cases) and Core API (for direct provider calls).
The Router API uses named configurations, making it easy to switch between models:
(require '[litellm.router :as router])
;; Quick setup from environment variables
(router/quick-setup!)
;; Or register specific configurations
(router/register! :fast
{:provider :openai
:model "gpt-4o-mini"
:config {:api-key (System/getenv "OPENAI_API_KEY")}})
;; Use the configuration
(def response (router/completion :fast
{:messages [{:role :user :content "Hello!"}]}))
(println (router/extract-content response))
;; => "Hello! How can I assist you today?"
The Core API provides direct access to providers:
(require '[litellm.core :as core])
;; Direct provider call
(def response (core/completion :openai "gpt-4o-mini"
{:messages [{:role :user :content "Hello!"}]
:api-key (System/getenv "OPENAI_API_KEY")}))
(println (core/extract-content response))
;; => "Hello! How can I assist you today?"
Set environment variables for your providers:
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GEMINI_API_KEY="..."
export MISTRAL_API_KEY="..."
export OPENROUTER_API_KEY="sk-or-..."
Then use quick-setup!:
(router/quick-setup!)
;; Automatically sets up all providers with available API keys
(router/setup-openai! :api-key "sk-..." :model "gpt-4")
(router/setup-anthropic! :api-key "sk-ant-..." :model "claude-3-sonnet-20240229")
(router/setup-gemini! :api-key "..." :model "gemini-pro")
(require '[litellm.router :as router])
(router/quick-setup!)
;; Simple question
(def response (router/chat :openai "What is the capital of France?"))
(println (router/extract-content response))
;; => "The capital of France is Paris."
(def response (router/chat :openai
"Explain quantum entanglement"
:system-prompt "You are a physics professor."))
(def response (router/completion :openai
{:messages [{:role :system :content "You are a helpful assistant."}
{:role :user :content "What is 2+2?"}
{:role :assistant :content "4"}
{:role :user :content "What about 3+3?"}]}))
| Provider | Status | Models |
|---|---|---|
| OpenAI | ✅ | GPT-3.5-Turbo, GPT-4, GPT-4o |
| Anthropic | ✅ | Claude 3 (Opus, Sonnet, Haiku) |
| Google Gemini | ✅ | Gemini Pro, Ultra |
| Mistral | ✅ | Mistral Small/Medium/Large |
| OpenRouter | ✅ | All OpenRouter models |
| Ollama | ✅ | Local models |
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |