LLM configuration management.
Provides a single make-config for creating validated config maps.
No DI, no global state. Config is a plain immutable map.
Environment variables (used as fallback for :api-key and :base-url):
Usage: (def config (make-config {:api-key "sk-..." :base-url "https://api.openai.com/v1" :model "gpt-4o"})) (ask! {:config config :spec my-spec :messages [(system "...") (user "...")]})
LLM configuration management.
Provides a single `make-config` for creating validated config maps.
No DI, no global state. Config is a plain immutable map.
Environment variables (used as fallback for :api-key and :base-url):
- BLOCKETHER_OPENAI_API_KEY (checked first)
- BLOCKETHER_OPENAI_BASE_URL (checked first)
- OPENAI_API_KEY
- OPENAI_BASE_URL
Usage:
(def config (make-config {:api-key "sk-..."
:base-url "https://api.openai.com/v1"
:model "gpt-4o"}))
(ask! {:config config :spec my-spec :messages [(system "...") (user "...")]})Default LLM model when not specified.
Default LLM model when not specified.
Default retry policy for transient HTTP errors.
Default retry policy for transient HTTP errors.
Default HTTP request timeout in milliseconds (3 minutes).
Default HTTP request timeout in milliseconds (3 minutes).
(make-config)(make-config {:keys [api-key base-url model network tokens]})Creates an LLM configuration map with defaults and env var fallback.
Params:
opts - Map with keys:
Returns: Validated config map with all defaults applied.
Throws: ExceptionInfo if no API key available from any source.
Example: (make-config {:api-key "sk-..." :base-url "https://api.openai.com/v1"}) (make-config {:api-key "sk-..." :model "gpt-4o-mini" :network {:timeout-ms 300000}}) (make-config {}) ;; uses env vars for api-key/base-url
Creates an LLM configuration map with defaults and env var fallback.
Params:
`opts` - Map with keys:
- :api-key - String, optional. Falls back to BLOCKETHER_OPENAI_API_KEY,
then OPENAI_API_KEY env var.
- :base-url - String, optional. Falls back to BLOCKETHER_OPENAI_BASE_URL,
then OPENAI_BASE_URL env var, then DEFAULT_BASE_URL.
- :model - String, optional. Default model for all calls (default: "gpt-4o").
- :network - Map, optional. Network settings (merged over defaults):
- :timeout-ms - Integer. HTTP request timeout (default: 180000).
- :max-retries - Integer. Maximum retry attempts (default: 5).
- :initial-delay-ms - Integer. First retry delay (default: 1000).
- :max-delay-ms - Integer. Maximum retry delay (default: 60000).
- :multiplier - Double. Backoff multiplier (default: 2.0).
- :tokens - Map, optional. Token-related settings:
- :check-context? - Boolean. Pre-flight context limit check (default: true).
- :pricing - Map. Per-model pricing overrides, merged over built-in defaults.
Keys are model name strings, values are {:input price-per-1M :output price-per-1M}.
- :context-limits - Map. Per-model context window overrides, merged over built-in defaults.
Keys are model name strings, values are integer token counts.
- :output-reserve - Integer. Tokens reserved for output in pre-flight context check.
Defaults to model's max output tokens (model-aware). Set to 0 to disable.
Returns:
Validated config map with all defaults applied.
Throws:
ExceptionInfo if no API key available from any source.
Example:
(make-config {:api-key "sk-..." :base-url "https://api.openai.com/v1"})
(make-config {:api-key "sk-..." :model "gpt-4o-mini"
:network {:timeout-ms 300000}})
(make-config {}) ;; uses env vars for api-key/base-urlcljdoc 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 |