import { ProviderV3, LanguageModelV3, EmbeddingModelV3, ImageModelV3, SpeechModelV3, SharedV3ProviderOptions } from '@ai-sdk/provider'; import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils'; import { FetchFunction } from '@ai-sdk/provider-utils'; type ZhipuChatModelId = "glm-5" | "glm-4.7" | "glm-4.7-flash" | "glm-4.7-flashx" | "glm-4.6" | "glm-4.5" | "glm-4.5-air" | "glm-4.5-x" | "glm-4.5-airx" | "glm-4.5-flash" | "glm-4-plus" | "glm-4-air-250414" | "glm-4-air" | "glm-4-airx" | "glm-4-long" | "glm-4-flash" | "glm-4-flash-250414" | "glm-4-flashx" | "glm-4-32b-0414-128k" | "glm-4v-plus-0111" | "glm-4v-plus" | "glm-4v" | "glm-4v-flash" | "glm-4.6v" | "glm-4.6v-flash" | "glm-4.6v-flashx" | "glm-4.5v" | "glm-z1-air" | "glm-z1-airx" | "glm-z1-flash" | "glm-4.1v-thinking-flash" | "glm-4.1v-thinking-flashx" | (string & {}); /** * Thinking mode configuration for GLM-4.5+ models. * Controls chain-of-thought deep reasoning capabilities. * * @see https://docs.z.ai/guides/capabilities/thinking * @see https://docs.z.ai/guides/capabilities/thinking-mode */ interface ZhipuThinkingConfig { /** * Enable or disable thinking mode. * - `"enabled"` (default for GLM-5, GLM-4.7): Model uses deep reasoning before responding. * GLM-4.6 and GLM-4.5 will automatically determine if thinking is needed. * - `"disabled"`: Standard response without explicit reasoning. */ type: "enabled" | "disabled"; /** * Whether to clear thinking content from previous turns (Preserved Thinking). * * - `true` (default): Previous reasoning is not retained in context. * - `false`: Reasoning content from previous assistant turns is preserved, * improving continuity and increasing cache hit rates in multi-turn conversations. * * Only applicable when `type` is `"enabled"`. * * @default true * @see https://docs.z.ai/guides/capabilities/thinking-mode */ clearThinking?: boolean; } /** * Zhipu-specific provider options passed via `providerOptions`. * These are sent directly to the Zhipu API as body parameters. * * Since this SDK is exclusively for Zhipu AI, you can pass options directly * using the {@link zhipuOptions} helper (no nesting required): * * @example * ```ts * import { zhipu, zhipuOptions } from "zhipu-ai-sdk-provider"; * * const result = await generateText({ * model: zhipu("glm-4.7"), * prompt: "Explain quantum computing", * providerOptions: zhipuOptions({ * temperature: 0.7, * top_p: 0.9, * max_tokens: 4096, * thinking: { type: "enabled", clear_thinking: false }, * }), * }); * ``` * * @see https://docs.z.ai/guides/overview/concept-param */ interface ZhipuProviderOptions { /** * Controls the randomness of the model's output. * - Lower values (e.g., 0.2): More deterministic and conservative output. * - Higher values (e.g., 0.8): More random and diverse output. * * It is recommended to use only one of `temperature` and `top_p`. */ temperature?: number; /** * Controls diversity through nucleus sampling. * Samples from the smallest set of tokens whose cumulative probability exceeds this threshold. * - Lower values (e.g., 0.2): More deterministic output. * - Higher values (e.g., 0.9): More diverse output. * * It is recommended to use only one of `temperature` and `top_p`. */ top_p?: number; /** * Maximum number of tokens to generate in a single call. * This limits the length of generated content, not including input. * * Default and maximum values vary by model: * - GLM-5/4.7/4.6: default 65536, max 131072 * - GLM-4.5 series: default 65536, max 98304 * - GLM-4.6v/4.5v: default 16384, max 32768/16384 * - GLM-4-32B: default 16384, max 16384 * * @see https://docs.z.ai/guides/overview/concept-param#max_tokens */ max_tokens?: number; /** * Whether to sample the output to increase diversity. * - `true` (default): Performs random sampling based on token probability distribution. * - `false`: Uses greedy strategy, always selecting the highest probability token. * * When `false`, `temperature` and `top_p` will not take effect. */ do_sample?: boolean; /** * Thinking mode configuration for GLM-4.5+ models. * Controls chain-of-thought deep reasoning. * * @example * ```json * { "type": "enabled", "clear_thinking": false } * ``` * * @see https://docs.z.ai/guides/capabilities/thinking */ thinking?: { /** * - `"enabled"`: Enable chain-of-thought reasoning (default for GLM-5, GLM-4.7). * - `"disabled"`: Disable reasoning for faster responses. */ type: "enabled" | "disabled"; /** * Whether to clear thinking content from previous turns. * Set to `false` to enable Preserved Thinking (retains reasoning across turns). * @default true */ clear_thinking?: boolean; }; /** * Stop sequences. When the model generates one of these strings, it will stop. * Zhipu API supports at most 1 stop sequence. */ stop?: string[]; /** * The unique ID of the end user. Helps the platform with abuse detection. * Length: 6–128 characters. */ user_id?: string; /** * The unique ID of the request. Must be unique per call. * The platform generates one by default if not provided. */ request_id?: string; /** * Specifies the response format of the model output. * * - `{ type: "text" }` — plain text mode (default). * - `{ type: "json_object" }` — JSON mode. The model returns valid JSON. * When using JSON mode, clearly request JSON output in your prompt. * * This is also set automatically when using `generateObject` / `streamObject` * from the AI SDK (`responseFormat: { type: "json" }` is mapped to `json_object`). * * @see https://docs.z.ai/guides/capabilities/struct-output */ response_format?: { type: "text" | "json_object"; }; /** * Enable streaming tool calls for GLM-4.6 models. * When enabled, tool calls are streamed incrementally. */ tool_stream?: boolean; /** * Additional key-value pairs to pass through to the API body. * Use this for any new or undocumented parameters. */ [key: string]: unknown; } interface ZhipuChatSettings { /** * The unique ID of the end user. Helps the platform with abuse detection. * Length: 6–128 characters. */ userId?: string; /** * The unique ID of the request, passed by the user side, must be unique. * The platform will generate one by default if not provided. */ requestId?: string; /** * Whether to sample the output to increase diversity. * When `false`, temperature and top_p will not take effect. */ doSample?: boolean; /** * Enable thinking/reasoning mode for GLM-4.5+ models. * When enabled, the model will perform deep reasoning before responding, * which improves performance on complex tasks like coding and multi-step reasoning. * * @see https://docs.z.ai/guides/capabilities/thinking */ thinking?: ZhipuThinkingConfig; } type ZhipuImageModelId = "cogview-3-flash" | "cogview-4" | "cogview-4-250304" | (string & {}); interface ZhipuImageProviderOptions { /** * The unique ID of the end user, helps the platform intervene in illegal activities, generate illegal or improper information, or other abuse by the end user. * ID length requirement: at least 6 characters, up to 128 characters. */ userId?: string; /** * Override the quality setting for the image generation, defaults to "standard". * Choices are "standard" and "hd". Adjustable for "cogview-4-250304" only. */ quality?: "standard" | "hd"; } type ZhipuEmbeddingModelId = "embedding-2" | "embedding-3" | (string & {}); interface ZhipuEmbeddingSettings { /** * Override the embedding dimension, defaults to 2048. * 256, 512, 1024 or 2048 are recommended for embedding-3. */ dimensions?: number; } /** * Zhipu TTS model IDs. * @see https://docs.bigmodel.cn/cn/guide/models/sound-and-video/glm-tts */ type ZhipuSpeechModelId = "glm-tts" | (string & {}); interface ZhipuSpeechSettings { /** * Volume control (0.1 - 2.0). * @default 1.0 */ volume?: number; } declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema, { searchResult: Array<{ title: string; content: string; link: string; media?: string; icon?: string; refer?: string; }>; }, { searchEngine?: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark"; searchIntent?: boolean; count?: number; searchDomainFilter?: string; searchRecencyFilter?: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit"; contentSize?: "medium" | "high"; }>; /** * Creates a Zhipu web_search provider tool for use with GLM models. * * Zhipu's web_search is a provider-executed tool — the model performs * the search server-side and returns results inline. * * @example * ```ts * import { generateText } from "ai"; * import { zhipu } from "zhipu-ai-sdk-provider"; * * const { text } = await generateText({ * model: zhipu("glm-4.7"), * tools: { * web_search: zhipu.tools.webSearch({ searchEngine: "search_pro" }), * }, * prompt: "What happened in the news today?", * }); * ``` * * @see https://docs.bigmodel.cn/api-reference/工具-api/网络搜索 */ declare const webSearch: (args?: Parameters[0]) => _ai_sdk_provider_utils.Tool, { searchResult: Array<{ title: string; content: string; link: string; media?: string; icon?: string; refer?: string; }>; }>; interface ZhipuProvider extends ProviderV3 { (modelId: ZhipuChatModelId, settings?: ZhipuChatSettings): LanguageModelV3; /** Creates a model for text generation. */ languageModel(modelId: ZhipuChatModelId, settings?: ZhipuChatSettings): LanguageModelV3; /** Creates a model for text generation. */ chat(modelId: ZhipuChatModelId, settings?: ZhipuChatSettings): LanguageModelV3; /** Creates a model for text embedding. */ embeddingModel: (modelId: ZhipuEmbeddingModelId, settings?: ZhipuEmbeddingSettings) => EmbeddingModelV3; /** Creates a model for text embedding. @deprecated Use `embeddingModel` instead. */ textEmbeddingModel?: (modelId: ZhipuEmbeddingModelId, settings?: ZhipuEmbeddingSettings) => EmbeddingModelV3; /** Creates a model for image generation. */ imageModel(modelId: ZhipuImageModelId): ImageModelV3; /** Creates a model for image generation. @deprecated Use `imageModel` instead. */ image(modelId: ZhipuImageModelId): ImageModelV3; /** Creates a model for text-to-speech. */ speechModel(modelId: ZhipuSpeechModelId, settings?: ZhipuSpeechSettings): SpeechModelV3; /** Provider-defined tools for Zhipu AI capabilities. */ readonly tools: { /** * Web search tool — the model performs server-side web search. * @see https://docs.bigmodel.cn/api-reference/工具-api/网络搜索 */ webSearch: typeof webSearch; }; } interface ZhipuProviderSettings { /** Use a different URL prefix for API calls, e.g. to use proxy servers. The default prefix is `https://open.bigmodel.cn/api/paas/v4`. */ baseURL?: string; /** API key that is being send using the `Authorization` header. It defaults to the `ZHIPU_API_KEY` environment variable. */ apiKey?: string; /** Custom headers to include in the requests. */ headers?: Record; /** Custom fetch implementation. You can use it as a middleware to intercept requests, or to provide a custom fetch implementation for e.g. testing. */ fetch?: FetchFunction; } /** Create a Zhipu AI provider instance. */ declare function createZhipu(options?: ZhipuProviderSettings): ZhipuProvider; /** Default Zhipu provider instance. */ declare const zhipu: ZhipuProvider; /** * Type helper for Zhipu chat model `providerOptions`. * Pass your options directly — no nesting required. * * @example * ```ts * import { zhipu, zhipuOptions } from "zhipu-ai-sdk-provider"; * * const result = await generateText({ * model: zhipu("glm-4.7"), * prompt: "Hello", * providerOptions: zhipuOptions({ * temperature: 0.7, * thinking: { type: "enabled" }, * }), * }); * ``` */ declare function zhipuOptions(options: ZhipuProviderOptions): SharedV3ProviderOptions; /** * Type helper for Zhipu image model `providerOptions`. * * @example * ```ts * import { zhipu, zhipuImageOptions } from "zhipu-ai-sdk-provider"; * * const { image } = await generateImage({ * model: zhipu.imageModel("cogview-4-250304"), * prompt: "A landscape", * providerOptions: zhipuImageOptions({ quality: "hd" }), * }); * ``` */ declare function zhipuImageOptions(options: ZhipuImageProviderOptions): SharedV3ProviderOptions; export { type ZhipuChatModelId, type ZhipuChatSettings, type ZhipuEmbeddingModelId, type ZhipuImageModelId, type ZhipuImageProviderOptions, type ZhipuProvider, type ZhipuProviderOptions, type ZhipuProviderSettings, type ZhipuSpeechModelId, type ZhipuSpeechSettings, type ZhipuThinkingConfig, createZhipu, webSearch, zhipu, zhipuImageOptions, zhipuOptions };