Skip to content

Z.AI provider for ReqLLM - OpenAI-compatible GLM models

License

Notifications You must be signed in to change notification settings

Nickcom4/req_llm_zai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReqLLM Z.AI

Z.AI provider plugin for ReqLLM. Provides OpenAI-compatible access to Z.AI GLM models.

Installation

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"}
  ]
end

Configuration

Set your Z.AI API key:

export ZAI_API_KEY=your-api-key

Or in your .env file (if using dotenvy):

ZAI_API_KEY=your-api-key

Providers

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.

Usage

Standard Chat

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))

Code Generation

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)

With Thinking Mode

{:ok, response} = ReqLLM.generate_text("zai:glm-4.5", context,
  provider_options: [thinking: %{type: "enabled"}]
)

Disable Thinking Mode

{:ok, response} = ReqLLM.generate_text("zai:glm-4.5-flash", context,
  provider_options: [thinking: %{type: "disabled"}]
)

Streaming

{:ok, stream_response} = ReqLLM.stream("zai:glm-4.5", context)

stream_response.tokens
|> Stream.each(&IO.write/1)
|> Stream.run()

Supported Models

  • 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

Timeout Configuration

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 default

License

Apache-2.0

About

Z.AI provider for ReqLLM - OpenAI-compatible GLM models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages