Presets for OpenAI-compatible APIs, built on hot.dev/openai.
Each preset knows a provider's base URL, routing prefix, ctx key name
and request quirks. The ctx-reading functions (ollama(), groq(),
openrouter(), ...) return an ::openai::compatible/CompatibleProvider;
provider(...) turns that into an ::ai::chat/ProviderRegistration
for ::ai::chat/run-loop, using OpenAI's chat-tools adapter. Each
registration's variant is Provider.Compat({name}) (see
::openai::compatible), so every preset keeps its identity.
Per-call credentials. Every named preset takes an opts Map, resolved
by resolve: opts first, then the preset's ctx variables, then its
defaults.
api-key: overrides the preset's key. Present but null or blank is an Err, never a fallback to ctx.base-url: overrides the URL. On a hosted preset it needsapi-keyinoptstoo: the ctx key is never sent to a per-call URL. On a server that needs no key (Ollama, vLLM, LM Studio,custom) it sends none.model-prefix,name,headers,max-tokens,extra-body: as inconfigure.
The functions in ::openai-compatible::chat, ::models and ::embeddings
also take a trailing opts over a built provider, and so does the run
loop through ChatOptions.provider-opts. A key from opts is masked in
the run's call records, and nothing is written to ctx.
Example
::oc ::openai-compatible
registry ::ai::chat/with-providers([
::oc/provider(::oc/ollama()),
::oc/provider(::oc/groq())
])
opts ::ai::chat/ChatOptions({model: "groq/llama-3.3-70b-versatile", providers: registry})
::ai::chat/run-loop(opts, "Hello!")
Values
DEFAULT_MAX_TOKENS
DEFAULT_MAX_TOKENS: Int 4096
PRESETS
PRESETS: Vec [
OLLAMA,
VLLM,
LM_STUDIO,
GROQ,
OPENROUTER,
DEEPSEEK,
TOGETHER,
FIREWORKS,
MISTRAL,
CEREBRAS,
PERPLEXITY
]
Every built-in preset.
Functions
cerebras
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Cerebras with the cerebras.api.key ctx key.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/cerebras(), "llama-3.3-70b", "Say hi")
// Another tenant's key, for one call
::oc/cerebras({api-key: ::hot::ctx/get("tenant.cerebras.key")})
cerebras.api.key
chat-fn
fn (p: ::openai::compatible/CompatibleProvider): Fn
The ::ai::chat/run-loop chat function bound to p (for
ChatOptions.chat-fn).
Example
::oc ::openai-compatible
opts ::ai::chat/ChatOptions({model: "llama3.2", chat-fn: ::oc/chat-fn(::oc/ollama())})
::ai::chat/run-loop(opts, "Hello!")
chat-opts-fn
fn (p: ::openai::compatible/CompatibleProvider): Fn
The ::ai::chat/run-loop chat function bound to p that also takes
ChatOptions.provider-opts (for ChatOptions.chat-opts-fn).
Example
::oc ::openai-compatible
opts ::ai::chat/ChatOptions({
model: "llama-3.3-70b-versatile",
chat-opts-fn: ::oc/chat-opts-fn(::oc/groq()),
provider-opts: {api-key: ::hot::ctx/get("tenant.groq.key")}
})
::ai::chat/run-loop(opts, "Hello!")
chat-stream-fn
fn (p: ::openai::compatible/CompatibleProvider): Fn
The ::ai::chat/run-loop-stream chat function bound to p (for
ChatOptions.chat-stream-fn).
Example
::oc ::openai-compatible
opts ::ai::chat/ChatOptions({model: "llama3.2", chat-stream-fn: ::oc/chat-stream-fn(::oc/ollama())})
::ai::chat/run-loop-stream(opts, "Hello!", (delta) { print(delta) })
chat-stream-opts-fn
fn (p: ::openai::compatible/CompatibleProvider): Fn
The ::ai::chat/run-loop-stream chat function bound to p that also
takes ChatOptions.provider-opts (for
ChatOptions.chat-stream-opts-fn).
Example
::oc ::openai-compatible
opts ::ai::chat/ChatOptions({
model: "llama-3.3-70b-versatile",
chat-stream-opts-fn: ::oc/chat-stream-opts-fn(::oc/groq()),
provider-opts: {api-key: ::hot::ctx/get("tenant.groq.key")}
})
::ai::chat/run-loop-stream(opts, "Hello!", (delta) { print(delta) })
configure
fn (preset: Preset, api-key: Str?): ::openai::compatible/CompatibleProvider
fn (preset: Preset, api-key: Str?, overrides: Map): ::openai::compatible/CompatibleProvider
Turn a Preset into an ::openai::compatible/CompatibleProvider with
an explicit key (null for keyless servers). Reads no ctx.
overrides may set base-url, model-prefix, name, headers,
max-tokens (output ceiling, default 4096) and extra-body
(provider-specific request fields). The key is masked in the run's call
records. A hosted preset with no key and no base-url override gives a
provider whose calls need api-key in their opts.
Example
::oc ::openai-compatible
groq ::oc/configure(::oc/GROQ, "gsk_...")
remote-ollama ::oc/configure(::oc/OLLAMA, null, {base-url: "http://gpu-box.internal:11434/v1"})
routed ::oc/configure(::oc/OPENROUTER, "sk-or-...", {
headers: {"HTTP-Referer": "https://example.com", "X-OpenRouter-Title": "Example"},
extra-body: {provider: {sort: "throughput"}}
})
custom
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Any other OpenAI-compatible server or private gateway (see CUSTOM):
openai-compatible.url, or base-url in opts, and an optional
openai-compatible.api.key. Routing prefix custom/. No URL at all is
an Err, so a key can't end up at a default.
Example
::oc ::openai-compatible
gateway ::oc/custom({
base-url: "https://llm.internal.example.com/v1",
api-key: ::hot::ctx/get("gateway.api.key")
})
::openai-compatible::chat/chat(gateway, "my-model", "Say hi")
openai-compatible.url, openai-compatible.api.key
deepseek
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
DeepSeek with the deepseek.api.key ctx key.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/deepseek(), "deepseek-chat", "Say hi")
// Another tenant's key, for one call
::oc/deepseek({api-key: ::hot::ctx/get("tenant.deepseek.key")})
deepseek.api.key
fireworks
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Fireworks AI with the fireworks.api.key ctx key.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/fireworks(), "accounts/fireworks/models/llama-v3p3-70b-instruct", "Say hi")
// Another tenant's key, for one call
::oc/fireworks({api-key: ::hot::ctx/get("tenant.fireworks.key")})
fireworks.api.key
groq
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Groq with the groq.api.key ctx key.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/groq(), "llama-3.3-70b-versatile", "Say hi")
// Another tenant's key, for one call
::oc/groq({api-key: ::hot::ctx/get("tenant.groq.key")})
groq.api.key
lm-studio
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
LM Studio server at lm-studio.base.url (default
http://localhost:1234/v1). Keyless.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/lm-studio(), "qwen/qwen3-8b", "Say hi")
lm-studio.base.url
mistral
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Mistral with the mistral.api.key ctx key.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/mistral(), "mistral-small-latest", "Say hi")
// Another tenant's key, for one call
::oc/mistral({api-key: ::hot::ctx/get("tenant.mistral.key")})
mistral.api.key
ollama
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Local Ollama. ollama.base.url overrides the default
http://localhost:11434/v1 (e.g. https://ollama.com/v1 for Ollama's
hosted API, with ollama.api.key). Keyless by default.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/ollama(), "llama3.2", "Say hi")
// A remote server, for one call
::oc/ollama({base-url: "http://gpu-box.internal:11434/v1"})
ollama.base.url, ollama.api.key
openrouter
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
OpenRouter with the openrouter.api.key ctx key. Optional
openrouter.app.url and openrouter.app.title are sent as the
HTTP-Referer and X-OpenRouter-Title attribution headers.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/openrouter(), "anthropic/claude-sonnet-4.5", "Say hi")
// Another tenant's key, for one call
::oc/openrouter({api-key: ::hot::ctx/get("tenant.openrouter.key")})
openrouter.api.key, openrouter.app.url, openrouter.app.title
openrouter-headers
fn (app-url: Str?, app-title: Str?): Map
OpenRouter app-attribution headers. Unset values are omitted.
Example
::openai-compatible/openrouter-headers("https://example.com", "Example")
// => {"HTTP-Referer": "https://example.com", "X-OpenRouter-Title": "Example"}
perplexity
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Perplexity Sonar with the perplexity.api.key ctx key. No tool calling.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/perplexity(), "sonar", "Say hi")
// Another tenant's key, for one call
::oc/perplexity({api-key: ::hot::ctx/get("tenant.perplexity.key")})
perplexity.api.key
provider
fn (p: ::openai::compatible/CompatibleProvider): ::ai::chat/ProviderRegistration
Build an ::ai::chat/ProviderRegistration from a configured provider,
via ::openai::compatible/provider. Models starting with the preset's
prefix route to it; the prefix is stripped before the request.
Example
registry ::ai::chat/with-providers([::openai-compatible/provider(::openai-compatible/ollama())])
resolve
fn (preset: Preset, opts: Map): ::openai::compatible/CompatibleProvider
A provider for preset under one call's opts: opts over the preset's
ctx variables over its defaults (see resolve-from). With an api-key in
opts, the ctx key is not read. Nothing is written to ctx, and a key from
opts is masked in the run's call records.
Example
tenant ::openai-compatible/resolve(::openai-compatible/GROQ, {api-key: "gsk_tenant"})
remote ::openai-compatible/resolve(::openai-compatible/OLLAMA, {base-url: "http://gpu-box.internal:11434/v1"})
resolve-from
fn (preset: Preset, opts: Map, ctx-values: Map): ::openai::compatible/CompatibleProvider
The resolver for named presets, pure: a provider for preset from opts
first, then ctx-values ({key, base-url}, the values of the preset's ctx
variables), then defaults. An Err when api-key in opts is blank (never
a fallback to ctx), when a hosted preset has a base-url in opts but no
api-key (the ctx key is never sent to a per-call URL), when that
base-url is not a plain http(s) URL, or when the preset has no URL at
all. On a server that needs no key, a per-call base-url sends none.
Exposed for testing; resolve feeds it the context.
Example
::openai-compatible/resolve-from(::openai-compatible/GROQ, {api-key: "k"}, {}).endpoint.api-key // => "k"
together
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
Together AI with the together.api.key ctx key.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/together(), "meta-llama/Llama-3.3-70B-Instruct-Turbo", "Say hi")
// Another tenant's key, for one call
::oc/together({api-key: ::hot::ctx/get("tenant.together.key")})
together.api.key
vllm
fn (): ::openai::compatible/CompatibleProvider
fn (opts: Map): ::openai::compatible/CompatibleProvider
vLLM server at vllm.base.url (default http://localhost:8000/v1).
vllm.api.key only when the server runs with --api-key.
Example
::oc ::openai-compatible
::openai-compatible::chat/chat(::oc/vllm(), "Qwen/Qwen3-8B", "Say hi")
// A remote server, for one call
::oc/vllm({base-url: "http://gpu-box.internal:8000/v1"})
vllm.base.url, vllm.api.key
Types
Preset
Preset type {
name: Str,
base-url: Str,
model-prefix: Str,
key-ctx: Str?,
key-env: Str?,
max-tokens-param: Str,
stream-usage: Bool,
capabilities: Vec<Str>,
docs-url: Str,
key-required: Bool?,
base-url-ctx: Str?
}
Static description of an OpenAI-compatible provider.
name: display name.base-url: default OpenAI-compatible base URL.model-prefix: routing prefix for::ai::chatregistries.key-ctx: ctx variable the named preset function reads the key from (null for keyless servers).key-required: true when the service needs a key. Calls without one are an Err namingkey-ctx, and a per-call URL needs its own key.base-url-ctx: ctx variable that overridesbase-url(null for none).key-env: the provider's conventional env var, for your ctx file.max-tokens-param: body field for the output ceiling (max_tokensormax_completion_tokens).stream-usage: whether to sendstream_options.include_usage.capabilities: advertised on the registration.docs-url: the provider's OpenAI-compatibility docs.