zai

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package zai provides a Z.ai GLM API provider implementation for Iris.

Index

Constants

View Source
const (
	// GLM-5 series (latest)
	ModelGLM52      core.ModelID = "glm-5.2"
	ModelGLM51      core.ModelID = "glm-5.1"
	ModelGLM5       core.ModelID = "glm-5"
	ModelGLM5Turbo  core.ModelID = "glm-5-turbo"
	ModelGLM5VTurbo core.ModelID = "glm-5v-turbo"

	// GLM-4.7 series
	ModelGLM47       core.ModelID = "glm-4.7"
	ModelGLM47Flash  core.ModelID = "glm-4.7-flash"
	ModelGLM47FlashX core.ModelID = "glm-4.7-flashx"

	// GLM-4.6 series
	ModelGLM46        core.ModelID = "glm-4.6"
	ModelGLM46V       core.ModelID = "glm-4.6v"
	ModelGLM46VFlash  core.ModelID = "glm-4.6v-flash"
	ModelGLM46VFlashX core.ModelID = "glm-4.6v-flashx"

	// GLM-4.5 series
	ModelGLM45      core.ModelID = "glm-4.5"
	ModelGLM45V     core.ModelID = "glm-4.5v"
	ModelGLM45X     core.ModelID = "glm-4.5-x"
	ModelGLM45Air   core.ModelID = "glm-4.5-air"
	ModelGLM45AirX  core.ModelID = "glm-4.5-airx"
	ModelGLM45Flash core.ModelID = "glm-4.5-flash"

	// GLM Specialized
	ModelGLMForCoding core.ModelID = "glm-for-coding"

	// GLM-4 32B
	ModelGLM4_32B core.ModelID = "glm-4-32b-0414-128k"
)

Model constants for Z.ai GLM models.

View Source
const DefaultAPIKeyEnvVar = "ZAI_API_KEY"

DefaultAPIKeyEnvVar is the environment variable name for the Z.ai API key.

View Source
const DefaultBaseURL = "https://api.z.ai/api/coding/paas/v4"

DefaultBaseURL is the default base URL for the Z.ai API (coding endpoint).

Variables

View Source
var ErrAPIKeyNotFound = errors.New("zai: ZAI_API_KEY environment variable not set")

ErrAPIKeyNotFound is returned when the API key environment variable is not set.

View Source
var ErrToolArgsInvalidJSON = errors.New("tool args invalid json")

ErrToolArgsInvalidJSON is returned when tool call arguments contain invalid JSON.

Functions

func GetModelInfo

func GetModelInfo(id core.ModelID) *core.ModelInfo

GetModelInfo returns a copy of the ModelInfo for a given model ID, or nil if not found. The returned pointer references a fresh copy whose fields (including the Capabilities slice) do not alias the package's static catalog, so mutating it cannot affect subsequent GetModelInfo or Models calls.

Types

type Config

type Config struct {
	// APIKey is the API key for authentication.
	// Stored as Secret to prevent accidental logging.
	APIKey core.Secret

	// BaseURL is the base URL for the API. Defaults to DefaultBaseURL.
	BaseURL string

	// HTTPClient is the HTTP client to use for requests.
	HTTPClient *http.Client

	// Headers are additional headers to include in requests.
	Headers http.Header

	// Timeout sets the timeout for this provider's direct (non-chat)
	// operations — embeddings, files, images, batch, and vector stores.
	// Chat and streaming honor core.WithTimeout and context deadlines.
	Timeout time.Duration
}

Config holds the configuration for the Z.ai provider.

type Option

type Option func(*Config)

Option is a functional option for configuring the Z.ai provider.

func WithAPIKey added in v0.17.0

func WithAPIKey(key string) Option

WithAPIKey sets the API key, overriding any value passed to New.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets the base URL for the API.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithHeader added in v1.0.0

func WithHeader(key, value string) Option

WithHeader adds an extra header to include in requests.

func WithHeaders

func WithHeaders(headers http.Header) Option

WithHeaders sets additional headers to include in requests.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for this provider's direct (non-chat) operations — embeddings, files, images, batch, and vector stores. Chat and streaming honor core.WithTimeout and context deadlines.

type Zai

type Zai struct {
	// contains filtered or unexported fields
}

Zai is an LLM provider implementation for the Z.ai GLM API. Zai is safe for concurrent use.

func New

func New(apiKey string, opts ...Option) *Zai

New creates a new Z.ai provider with the given API key and options.

func NewFromEnv added in v0.10.0

func NewFromEnv(opts ...Option) (*Zai, error)

NewFromEnv creates a new Z.ai provider using the ZAI_API_KEY environment variable. This is a convenience factory for quick setup:

provider, err := zai.NewFromEnv()
if err != nil {
    log.Fatal(err)
}
client := core.NewClient(provider)

func (*Zai) Chat

func (p *Zai) Chat(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)

Chat sends a non-streaming chat request.

func (*Zai) ID

func (p *Zai) ID() string

ID returns the provider identifier.

func (*Zai) Models

func (p *Zai) Models() []core.ModelInfo

Models returns the list of available models.

func (*Zai) StreamChat

func (p *Zai) StreamChat(ctx context.Context, req *core.ChatRequest) (*core.ChatStream, error)

StreamChat sends a streaming chat request.

func (*Zai) Supports

func (p *Zai) Supports(feature core.Feature) bool

Supports reports whether the provider supports the given feature.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL