Skip to content

feat(llm): add native OpenAI-compatible support for Z.ai and ZhipuAI (#8782) - #8783

Open
DewellNaa wants to merge 2 commits into
crewAIInc:mainfrom
DewellNaa:feat/support-glm-5.3-flash-and-zai-v2
Open

DewellNaa wants to merge 2 commits into
crewAIInc:mainfrom
DewellNaa:feat/support-glm-5.3-flash-and-zai-v2

Conversation

@DewellNaa

@DewellNaa DewellNaa commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #8782

Description

This PR adds first-class native OpenAI-compatible provider support for Z.ai and ZhipuAI (zai, zhipuai, zhipu), enabling modern GLM models (such as glm-5.3-flash, glm-5.3, glm-5v-turbo, glm-4-flash, etc.) to be used natively and reliably in CrewAI agents.

Addresses #8782.

Changes

  1. Provider Registry (crewai.llms.providers.openai_compatible):
    • Registered zai, zhipuai, and zhipu in OPENAI_COMPATIBLE_PROVIDERS with their official OpenAI-compatible endpoints (https://api.z.ai/api/paas/v4 and https://open.bigmodel.cn/api/paas/v4).
    • Added fallback_api_key_envs to ProviderConfig so OpenAICompatibleCompletion can automatically fall back across ZAI_API_KEY, BIGMODEL_API_KEY, and ZHIPUAI_API_KEY.
  2. LLM Routing (crewai.llm):
    • Added zai, zhipuai, zhipu, and bigmodel to SUPPORTED_NATIVE_PROVIDERS, PROVIDER_ALIASES, and openai_compatible_providers.
    • Added automatic provider inference for bare glm-* model strings (e.g., LLM(model="glm-5.3-flash")).
  3. Tests:
    • Added 8 comprehensive test cases in test_openai_compatible.py validating configuration, multi-key fallback chains, and LLM factory instantiation.
    • All 71 tests in test_openai_compatible.py pass with zero lint errors (ruff check / ruff format clean).

Note

Low Risk
Additive LLM provider and routing changes with tests; no changes to auth or core agent execution paths beyond new provider selection.

Overview
Adds native OpenAI-compatible routing for Z.ai / ZhipuAI GLM models so agents can use zai, zhipuai, zhipu, and bigmodel without relying on LiteLLM.

Provider wiring: New entries in the OpenAI-compatible registry point at https://api.z.ai/api/paas/v4 and https://open.bigmodel.cn/api/paas/v4, with env vars ZAI_API_KEY, ZHIPUAI_API_KEY, and BIGMODEL_API_KEY. ProviderConfig gains fallback_api_key_envs, and key resolution tries those alternates when the primary env var is missing (handy across Z.ai vs BigModel naming).

LLM factory: The new prefixes are registered in native provider lists and aliases; bare models starting with glm- or glm_ infer zai. Factory and integration tests cover config, key fallback, prefixed models, and explicit provider=.

Reviewed by Cursor Bugbot for commit 11856a9. Bugbot is set up for automated code reviews on this repo. Configure here.

- Add 'zai', 'zhipuai', and 'zhipu' to OPENAI_COMPATIBLE_PROVIDERS with standard paas endpoints
- Support environment key fallbacks across ZAI_API_KEY, BIGMODEL_API_KEY, and ZHIPUAI_API_KEY
- Add 'zai', 'zhipuai', and 'zhipu' to SUPPORTED_NATIVE_PROVIDERS and PROVIDER_ALIASES in LLM
- Automatically infer 'zai' provider for bare 'glm-*' model identifiers
- Add 8 comprehensive unit tests covering provider configs, env fallbacks, and LLM factory routing
@strix-security

strix-security Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 1 commit after the last Strix review (efd03a8). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

✅ No open security findings.

PR summary: This PR registers Z.ai and ZhipuAI as native OpenAI-compatible providers (registry entries, provider aliases, and inference of the `zai` provider from bare `glm-*` model names), and adds a `fallback_api_key_envs` mechanism so an API key can be resolved from related Zhipu-family environment variables. It also adds tests covering the new configurations and key fallback chains.

Review summary

Reviewed the provider registry additions, the alias/native-provider routing entries, the glm-* bare-model inference, the new environment-variable key fallback loop, and the accompanying tests, tracing each path through the routing logic in crewai/llm.py and the key/base-URL resolution in openai_compatible/completion.py. The change is purely additive: endpoints are fixed HTTPS vendor hosts, the fallback variable names are static per provider, explicit api_key/base_url/provider arguments still take precedence, and no new logging, serialization, or error path exposes the resolved credential. Three suspicions raised during analysis — silent rerouting of bare glm-* models away from an OPENAI_BASE_URL gateway, cross-host reuse of Zhipu-family API keys, and bigmodel falling through to the LiteLLM path — were each independently validated and rejected as behavioural or correctness concerns with no attacker-reachable impact. No security vulnerabilities were introduced by this PR.

Ruled out (3)
  • Does the new bare `glm-*` inference silently reroute prompts to api.z.ai, bypassing an operator's configured OpenAI-compatible gateway?
    The reroute is the documented and tested intent of the change, the model string is developer-authored configuration with no external input path, and because `api_key_required=True` and `OPENAI_API_KEY` is never consulted on the `zai` route, gateway-only deployments fail with `MissingAPIKeyError` in…
  • Does the new `fallback_api_key_envs` chain send an API key to a host other than the one that issued it, disclosing a credential to a third party?
    Both endpoints belong to the same vendor (Zhipu AI / Z.ai), the fallback tuples and provider-to-host mapping are static constants that no input can influence, keys are region-scoped and rejected by the other platform (fail closed), and the key reaches only the pre-existing SDK client-parameter sink.
  • Does `provider="bigmodel"` silently falling through to LiteLLM expose anything the native path would not?
    The provider name comes from operator configuration, the LiteLLM fallback attaches no auto-resolved Zhipu credential and errors out on the bare unknown model, so the inconsistency is purely functional.

Review 1 on this PR · efd03a8 · requested Oct 29 16:55 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit efd03a8. Configure here.

Comment thread lib/crewai/src/crewai/llm.py Resolved
Add 'bigmodel' to SUPPORTED_NATIVE_PROVIDERS and OPENAI_COMPATIBLE_PROVIDERS with standard paas endpoint and key fallbacks, ensuring provider='bigmodel' routes to native OpenAICompatibleCompletion instead of falling back to LiteLLM. Add unit tests verifying factory and explicit provider routing.

This branch has not been deployed

No deployments
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.

Native OpenAI-compatible provider support for Z.ai and ZhipuAI (GLM-5.3/GLM-5.3-Flash)

1 participant