zai

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package zai resolves Z.AI (Zhipu GLM) API base URLs for General (pay-as-you-go) and Coding Plan subscriptions, with full support for both OpenAI-compatible and Anthropic-compatible endpoints, plus International vs China regions.

This mirrors the structure of catalog/xiaomi/ for proper plan + region + dual-protocol separation. Official docs document separate "International" and "China" options for both General and Coding Plan.

Index

Constants

View Source
const (
	GeneralInternationalOpenAIBase = "https://api.z.ai/api/paas/v4"
	CodingInternationalOpenAIBase  = "https://api.z.ai/api/coding/paas/v4"

	GeneralChinaOpenAIBase = "https://open.bigmodel.cn/api/paas/v4"
	CodingChinaOpenAIBase  = "https://open.bigmodel.cn/api/coding/paas/v4"
)

OpenAI-compatible bases (primary for /models and chat/completions).

View Source
const (
	InternationalAnthropicBase = "https://api.z.ai/api/anthropic"
	ChinaAnthropicBase         = "https://open.bigmodel.cn/api/anthropic"
)

Anthropic-compatible bases.

View Source
const (
	ProviderGeneral = "zai_payg"
	ProviderCoding  = "zai_coding"
)

Provider IDs.

Variables

This section is empty.

Functions

func AppendKeyMismatchHint

func AppendKeyMismatchHint(err error, providerID, secret string) error

func KeyMismatchHint

func KeyMismatchHint(plan Plan, secret string) string

KeyMismatchHint (kept for future key prefix detection).

func ResolveAnthropicBase

func ResolveAnthropicBase(region Region) string

ResolveAnthropicBase returns the Anthropic-compat base for the region.

func ResolveOpenAIBase

func ResolveOpenAIBase(plan Plan, region Region, override string) (string, error)

ResolveOpenAIBase returns the correct OpenAI-compat base for the plan + region. override wins (ZAI_BASE_URL / ZAI_CODING_BASE_URL).

Types

type Plan

type Plan string

Plan identifies the billing product.

const (
	PlanGeneral Plan = "general"
	PlanCoding  Plan = "coding"
)

func PlanForProvider

func PlanForProvider(providerID string) (Plan, bool)

PlanForProvider maps gateway ID to plan.

type Region

type Region string

Region identifies International (api.z.ai) vs China (bigmodel.cn family).

const (
	RegionInternational Region = "international"
	RegionChina         Region = "cn"
)

func NormalizeRegion

func NormalizeRegion(region string) (Region, error)

NormalizeRegion accepts common names for the two regions.

Jump to

Keyboard shortcuts

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