Omni.Providers.Zai (Omni v1.3.0)

Copy Markdown View Source

Provider for the Z.ai API, using the Omni.Dialects.OpenAICompletions dialect.

Not loaded by default — must be explicitly enabled. Either add it to your provider list in application config:

config :omni, :providers, [:anthropic, :openai, :google, :zai]

Or load it at runtime:

Omni.Provider.load([:zai])

Reads the API key from the ZAI_API_KEY environment variable — no further configuration is needed if the variable is set.

Configuration

Override the default API key or base URL via application config:

config :omni, Omni.Providers.Zai,
  api_key: {:system, "MY_ZAI_KEY"}

Any key from the provider's config/0 can be overridden: :api_key, :base_url. See Omni.Provider for details.

Endpoint version

Z.ai serves the OpenAI Completions wire format under /v4/ rather than the conventional /v1/. build_url/2 rewrites the dialect's path so callers don't need to think about it.

Reasoning

Z.ai's GLM models all support reasoning, but they don't accept the standard reasoning_effort parameter. Instead, reasoning is toggled via a thinking object: %{"type" => "enabled"} or %{"type" => "disabled"}. This provider translates the standard :thinking option:

  • thinking: falsethinking: %{"type" => "disabled"}
  • Any other level (:low, :medium, :high, :xhigh, :max) → thinking: %{"type" => "enabled"}

Effort levels are flattened to on/off because Z.ai exposes no granularity — reasoning is either on or it isn't. Reasoning content streams back as reasoning_content, which the Completions dialect already parses into thinking blocks.

Structured output

Z.ai doesn't support response_format: {type: "json_schema"}. When the :output option is set, this provider rewrites the request to use {type: "json_object"} and appends the JSON Schema to the system prompt.