Skip to content

pydantic_ai.models.zai

Setup

For details on how to set up authentication with this model, see model configuration for Z.AI.

Z.AI (Zhipu AI) model implementation using OpenAI-compatible API.

ZaiModelSettings

Bases: ModelSettings

Settings used for a Z.AI model request.

ALL FIELDS MUST BE zai_ PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.

Attributes

zai_clear_thinking

Whether to clear historical thinking content from prior turns.

Defaults to False (preserved thinking) on thinking-capable models, retaining reasoning content from prior assistant responses for improved multi-turn coherence and consistency with other providers. Set to True to clear it instead.

Only affects cross-turn historical thinking blocks; it does not change whether the model generates thinking in the current turn (controlled by the unified thinking setting).

When using preserved thinking, you must return the complete, unmodified reasoning_content back to the API. All consecutive reasoning_content blocks must exactly match the original sequence.

See the Z.AI docs for more details.

Type: bool

ZaiModel

Bases: OpenAIChatModel

A model that uses Z.AI’s OpenAI-compatible API.

Z.AI (Zhipu AI) provides GLM models with support for thinking/reasoning mode and preserved thinking across turns.

Apart from __init__, all methods are private or match those of the base class.

Methods

__init__
def __init__(
    model_name: ZaiModelName,
    *,
    provider: Literal['zai'] | Provider[AsyncOpenAI] = 'zai',
    profile: ModelProfileSpec | None = None,
    settings: ZaiModelSettings | None = None,
)

Initialize a Z.AI model.

Parameters

model_name : ZaiModelName

The name of the Z.AI model to use.

provider : Literal[‘zai’] | Provider[AsyncOpenAI] Default: 'zai'

The provider to use. Defaults to ‘zai’.

profile : ModelProfileSpec | None Default: None

The model profile to use. Defaults to a profile based on the model name.

settings : ZaiModelSettings | None Default: None

Model-specific settings that will be used as defaults for this model.

ZaiModelName

Possible Z.AI model names.

Since Z.AI supports a variety of models and the list changes frequently, we explicitly list known models but allow any name in the type hints.

See https://docs.z.ai/ for an up to date list of models.

Default: str | LatestZaiModelNames