zaicoding

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package zaicoding implements Z.ai Coding's Chat Completions dialect.

Index

Constants

View Source
const (
	// Name identifies this provider-specific driver.
	Name = "zai-coding"

	// DefaultBaseURL is Z.ai Coding's OpenAI-compatible endpoint.
	DefaultBaseURL = "https://api.z.ai/api/coding/paas/v4"
)

Variables

View Source
var (
	// ErrUnsupportedParameter marks a Z.ai Coding control that the selected
	// model cannot accept.
	ErrUnsupportedParameter = errors.New("unsupported Z.ai Coding parameter")

	// ErrSensitiveContent is Z.ai's refusal of input or output it classifies
	// as unsafe (business code 1301). Retrying the same request returns the
	// same refusal.
	ErrSensitiveContent = errors.New("sensitive content refused by Z.ai Coding")
)

Functions

func KnownModels

func KnownModels() []elelem.Model

KnownModels returns the models the Z.ai Coding Plan serves.

func LookupModel

func LookupModel(id string) elelem.Model

LookupModel returns known model metadata and leaves unknown IDs unchanged. GLM 5.3 Flash X and the retired IDs the Coding Plan routes to GLM 5.3 or GLM 5.3 Flash get the metadata of the model that serves them.

Types

type Driver

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

Driver translates Elelem requests to Z.ai Coding's OpenAI-shaped API.

func NewDriver

func NewDriver(opts ...DriverOption) *Driver

NewDriver constructs a Z.ai Coding driver. It never reads OPENAI_* environment settings because those settings can belong to another upstream.

func (*Driver) Capabilities

func (d *Driver) Capabilities(model elelem.Model) elelem.Capabilities

Capabilities reports the selected Z.ai Coding model's validated controls.

func (*Driver) Complete

func (d *Driver) Complete(
	ctx context.Context,
	req elelem.DriverRequest,
	onDelta func(elelem.Delta) error,
) (elelem.Usage, error)

Complete issues one non-streaming Z.ai Coding chat completion.

func (*Driver) ListModels

func (d *Driver) ListModels(ctx context.Context) ([]string, error)

ListModels returns model IDs exposed by the configured endpoint.

func (*Driver) Stream

func (d *Driver) Stream(
	ctx context.Context,
	req elelem.DriverRequest,
	onDelta func(elelem.Delta) error,
) (elelem.Usage, error)

Stream issues one streaming Z.ai Coding chat completion. When the request carries tools it asks for tool_stream, so tool-call arguments arrive in fragments instead of in one piece at the end of the call.

func (*Driver) TokenCounter

func (d *Driver) TokenCounter() elelem.TokenCounter

TokenCounter returns the transport's token counter.

type DriverOption

type DriverOption func(*driverConfig)

DriverOption configures a Z.ai Coding driver.

func WithAPIKey

func WithAPIKey(apiKey string) DriverOption

WithAPIKey supplies the bearer token used by Z.ai Coding.

func WithBaseURL

func WithBaseURL(baseURL string) DriverOption

WithBaseURL overrides Z.ai Coding's endpoint.

func WithHTTPClient

func WithHTTPClient(client *http.Client) DriverOption

WithHTTPClient supplies the HTTP client used by the underlying SDK.

func WithSDKOptions

func WithSDKOptions(opts ...option.RequestOption) DriverOption

WithSDKOptions appends official OpenAI SDK options for this driver only.

Jump to

Keyboard shortcuts

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