Skip to content

Add Z.AI (Zhipu AI) GLM provider#109

Merged
priyanshujain merged 14 commits intomasterfrom
glm-integration
Mar 20, 2026
Merged

Add Z.AI (Zhipu AI) GLM provider#109
priyanshujain merged 14 commits intomasterfrom
glm-integration

Conversation

@priyanshujain
Copy link
Copy Markdown
Collaborator

@priyanshujain priyanshujain commented Mar 20, 2026

Summary

  • Adds Z.AI as a standalone LLM provider with OpenAI-compatible API format
  • Uses glm-4.5-flash (free, generous rate limits) as default model — not glm-4.7-flash which has aggressive rate limiting (~3 requests then locked out for minutes)
  • Models are discovered dynamically via Z.AI's /models endpoint and cached, not hardcoded
  • Handles Z.AI's reasoning_content field — when content is empty, reasoning text is surfaced instead
  • Includes Z.AI profile, settings UI entry, context windows for all GLM models, and CLI registration

Key decisions

  • glm-4.5-flash over glm-4.7-flash: Both are free, but glm-4.5-flash handles 20+ rapid sequential calls without rate limiting, while glm-4.7-flash locks out after ~3 calls. Verified via burst testing against real API.
  • Standalone provider (not wrapping OpenAI): Z.AI uses /v4/ prefix (not /v1/), has a different error format (code/message vs type/message), returns reasoning_content alongside content, and this gives us full control for Z.AI-specific behavior.
  • No hardcoded model list in setup wizard: Models are fetched from the API and cached, consistent with the existing model discovery system.

Files changed

File Change
provider/zai/zai.go Provider implementation (Chat, StreamChat, SSE, reasoning_content, factory)
provider/zai/zai_test.go 9 unit tests + integration test with real API
provider/registry.go ZAI_API_KEY env var
provider/context_window.go GLM-4.5 (128K), GLM-4.7/5 (200K)
provider/context_window_test.go GLM context window tests
provider/models.go listModelsZAI — fetches and filters GLM models
config/profiles.go Z.AI profile (default=glm-4.5-flash, complex=glm-4.7)
settings/registry.go Z.AI in settings UI
internal/cli/*.go Provider import registration

Test plan

  • go build ./... compiles cleanly
  • go test ./provider/zai/... — 9 unit tests pass (mock server)
  • go test ./provider/... — all 7 provider packages pass
  • Integration test with real ZAI_API_KEYglm-4.5-flash returns correct response
  • Burst test: 20 sequential calls to glm-4.5-flash — 20/20 succeeded
  • reasoning_content fallback verified — empty content with reasoning returns text
  • Z.AI error code format (code: "1302") correctly parsed
  • Merged with latest master — no conflicts

Standalone provider implementation with OpenAI-compatible request/response
format. Supports Chat, StreamChat, SSE parsing, and tool calling.
Uses Z.AI's /v4/ API prefix and handles their error format (code/message).
Unit tests with mock HTTP server for text response, tool use, error
handling, streaming text, streaming tool calls, and request format
validation. Integration test against real API using glm-4.5-flash.
GLM-4.5 family at 128K, GLM-4.7/5 family at 200K.
Fetches models from Z.AI API and filters for GLM models.
Uses glm-4.5-flash (free, generous rate limits) for default/fast/nano
and glm-4.7 (paid) for complex tier.
Z.AI models return reasoning in a separate `reasoning_content` field.
When `content` is empty, fall back to `reasoning_content` for both
non-streaming and streaming responses.
Verifies the provider correctly parses Z.AI's error format which uses
`code` (e.g. "1302") instead of OpenAI's `type` field.
@priyanshujain priyanshujain merged commit a94bae9 into master Mar 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant