Skip to content

Conversation

@lazasaurus-ai
Copy link

@lazasaurus-ai lazasaurus-ai commented Jan 29, 2026

Implements suppo# Add Z AI Provider

This PR adds support for Z AI's GLM models to ellmer.

Features

  • New chat_zai() function for Z AI GLM models
  • New models_zai() function to list available models
  • Supports both International and China/BigModel base URLs (tested):
    • International Coding API (default): https://api.z.ai/api/coding/paas/v4
    • International Regular API: https://api.z.ai/api/paas/v4 – For usage-based plans
    • China/BigModel Coding API: https://open.bigmodel.cn/api/coding/paas/v4
    • China/BigModel Regular API: https://open.bigmodel.cn/api/paas/v4
  • Reasoning content extraction from message.reasoning_content
  • Reasoning token tracking from completion_tokens_details.reasoning_tokens

Models Supported

  • glm-4.7 (default)
  • glm-4.6
  • glm-4.5
  • glm-4.5-Air

Implementation Details

  • Inherits from ProviderOpenAICompatible for OpenAI-compatible API
  • Overrides value_tokens() to extract reasoning tokens
  • Overrides value_turn() to handle reasoning content
  • Comprehensive documentation explaining both API endpoints

Testing

  • Tested with both coding and regular API endpoints
  • All functionality working correctly
  • Unit tests added in tests/testthat/test-provider-zai.R

Documentation

  • Added comprehensive documentation in R/provider-zai.R and man/chat_zai.Rd
  • Examples showing usage of both endpoints
  • Updated NEWS.md and README.md

Example

> devtools::load_all()
ℹ Loading ellmer
> # List available models
> models <- models_zai(base_url = "https://api.z.ai/api/coding/paas/v4")
> print(models)
           id created_at owned_by cached_input input output
4     glm-4.7 2025-12-21     z-ai           NA    NA     NA
3     glm-4.6 2025-10-01     z-ai           NA    NA     NA
1     glm-4.5 2025-07-27     z-ai           NA    NA     NA
2 glm-4.5-air 2025-07-27     z-ai           NA    NA     NA
> 
> # Create a chat client (explicit model + endpoint)
> chat <- chat_zai(
+   model = "glm-4.7",
+   base_url = "https://api.z.ai/api/coding/paas/v4"
+ )
> chat$chat("Hi who are you?")
I'm GLM, a large language model developed by Z.ai. I'm designed to understand 
and generate human language through training on diverse text data, which helps 
me assist with various linguistic tasks like answering questions, providing 
explanations, and engaging in conversations. 

I don't store your personal data and I'm not connected to the internet in 
real-time, though I can access some information I was trained on.

How can I help you today?

@lazasaurus-ai lazasaurus-ai force-pushed the feature/add-zai-provider branch from 2046afc to 4204762 Compare January 30, 2026 01:40
@lazasaurus-ai
Copy link
Author

I guarded the chat_zai() examples so they only execute when ZAI_API_KEY is set (i.e., they’re skipped in CI where the key isn’t configured). This avoids R CMD check failures from running a live API example without credentials. If you’d prefer a different approach (e.g., a recorded vcr cassette or removing the runnable example), I’m happy to adjust.

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