Skip to main content

Z.AI Provider

Z.AI provides GLM chat models over an OpenAI-compatible API. It only supports language models — EmbeddingModel, ImageModel, SpeechModel, TranscriptionModel, and RerankingModel all return errors.

Setup​

Installation​

import (
"github.com/digitallysavvy/go-ai/pkg/ai"
"github.com/digitallysavvy/go-ai/pkg/providers/zai"
)

Configuration​

provider := zai.New(zai.Config{
APIKey: os.Getenv("ZAI_API_KEY"),
})

model, err := provider.LanguageModel(zai.ModelGLM53)

zai.Config also accepts BaseURL (default https://api.z.ai/api/paas/v4) and Headers.

Get API Key​

export ZAI_API_KEY=...

Available Models​

Model IDGo constant
glm-5.3zai.ModelGLM53
glm-5.2zai.ModelGLM52
glm-5.1zai.ModelGLM51
glm-5-turbozai.ModelGLM5Turbo
glm-5zai.ModelGLM5
glm-4.7zai.ModelGLM47
glm-4.7-flashzai.ModelGLM47Flash
glm-4.7-flashxzai.ModelGLM47FlashX
glm-4.6zai.ModelGLM46
glm-4.5zai.ModelGLM45
glm-4.5-airzai.ModelGLM45Air

See pkg/providers/zai/model_ids.go for the full catalog, including dated/legacy variants.

ChatModel is an alias for LanguageModel.

Basic Usage​

result, err := ai.GenerateText(ctx, ai.GenerateTextOptions{
Model: model,
Prompt: "Explain the GLM model family in one paragraph",
})

Provider Options​

Z.AI-specific options are passed under the "zai" ProviderOptions key, resolved through the same OpenAI-compatible option resolver used by the other OpenAI-compatible providers in this SDK (see OpenAI-compatible providers).

Workflow Serialization​

Z.AI language models can cross a workflow boundary with providerutils.SerializeModel / DeserializeModel. See Provider Serialization for the mechanism.

See Also​