# ReqLLM Z.AI
Z.AI provider plugin for [ReqLLM](https://github.com/agentjido/req_llm). Provides OpenAI-compatible access to Z.AI GLM models.
## Installation
Add `req_llm_zai` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:req_llm, "~> 1.6"},
{:req_llm_zai, "~> 0.1.0"}
]
end
```
## Configuration
Set your Z.AI API key:
```bash
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
```elixir
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
```elixir
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
```elixir
{:ok, response} = ReqLLM.generate_text("zai:glm-4.5", context,
provider_options: [thinking: %{type: "enabled"}]
)
```
### Disable Thinking Mode
```elixir
{:ok, response} = ReqLLM.generate_text("zai:glm-4.5-flash", context,
provider_options: [thinking: %{type: "disabled"}]
)
```
### Streaming
```elixir
{: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:
```elixir
config :req_llm,
thinking_timeout: 300_000, # 5 minutes for thinking mode
receive_timeout: 120_000 # 2 minutes default
```
## License
Apache-2.0