Z.AI provider plugin for ReqLLM. Provides OpenAI-compatible access to Z.AI GLM models.
Add req_llm_zai to your list of dependencies in mix.exs:
def deps do
[
{:req_llm, "~> 1.6"},
{:req_llm_zai, "~> 0.1.0"}
]
endSet your Z.AI API key:
export ZAI_API_KEY=your-api-keyOr in your .env file (if using dotenvy):
ZAI_API_KEY=your-api-key
This package includes three providers:
| Provider | ID | Endpoint | Use Case |
|---|---|---|---|
ReqLLM.Providers.Zai |
:zai |
/api/paas/v4 |
General chat and reasoning |
ReqLLM.Providers.ZaiCoder |
:zai_coder |
/api/coding/paas/v4 |
Code generation |
ReqLLM.Providers.ZaiCodingPlan |
:zai_coding_plan |
/api/coding/paas/v4 |
Alias for coding endpoint |
All providers are automatically registered when the application starts.
context = ReqLLM.Context.new([
ReqLLM.Context.user("Explain pattern matching in Elixir")
])
{:ok, response} = ReqLLM.generate_text("zai:glm-4.5", context)
IO.puts(ReqLLM.Response.text(response))context = ReqLLM.Context.new([
ReqLLM.Context.user("Write a GenServer that manages a shopping cart")
])
{:ok, response} = ReqLLM.generate_text("zai_coder:glm-4.5", context){:ok, response} = ReqLLM.generate_text("zai:glm-4.5", context,
provider_options: [thinking: %{type: "enabled"}]
){:ok, response} = ReqLLM.generate_text("zai:glm-4.5-flash", context,
provider_options: [thinking: %{type: "disabled"}]
){:ok, stream_response} = ReqLLM.stream("zai:glm-4.5", context)
stream_response.tokens
|> Stream.each(&IO.write/1)
|> Stream.run()- glm-4.5 - Advanced reasoning model with 131K context
- glm-4.5-air - Lighter variant with same capabilities
- glm-4.5-flash - Free tier model with fast inference
- glm-4.5v - Vision model supporting text, image, and video inputs
- glm-4.6 - Latest model with 204K context and improved reasoning
- glm-4.7 - Latest model with 204K context
Thinking mode automatically extends timeouts to 300 seconds. Configure via:
config :req_llm,
thinking_timeout: 300_000, # 5 minutes for thinking mode
receive_timeout: 120_000 # 2 minutes defaultApache-2.0