From a822a73d1a85f8fbeacfdd506d38a5b2bd1f0fec Mon Sep 17 00:00:00 2001 From: Kastan Day Date: Fri, 18 Sep 2026 17:36:56 -0700 Subject: [PATCH] fix(types): describe Workers AI model reasoning controls --- types/defines/ai.d.ts | 58 +++++++----- .../experimental/index.d.ts | 88 ++++++++++++++----- .../generated-snapshot/experimental/index.ts | 88 ++++++++++++++----- types/generated-snapshot/index.d.ts | 88 ++++++++++++++----- types/generated-snapshot/index.ts | 88 ++++++++++++++----- types/test/types/ai-reasoning.ts | 67 ++++++++++++++ 6 files changed, 367 insertions(+), 110 deletions(-) create mode 100644 types/test/types/ai-reasoning.ts diff --git a/types/defines/ai.d.ts b/types/defines/ai.d.ts index 21ea87b5575..320458e6ab7 100644 --- a/types/defines/ai.d.ts +++ b/types/defines/ai.d.ts @@ -521,14 +521,17 @@ export type WebSearchOptions = { search_context_size?: "low" | "medium" | "high"; user_location?: WebSearchUserLocation; }; -export type ChatTemplateKwargs = { - /** Whether to enable reasoning, enabled by default. */ - enable_thinking?: boolean; +export type ChatTemplateKwargs = { + /** Whether to enable reasoning. Support and defaults depend on the model. */ + enable_thinking?: ThinkingEnabled; /** If false, preserves reasoning context between turns. */ clear_thinking?: boolean; }; /** Shared optional properties used by both Prompt and Messages input branches. */ -export type ChatCompletionsCommonOptions = { +export type ChatCompletionsCommonOptions< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { model?: string; audio?: AudioParams; frequency_penalty?: number | null; @@ -543,8 +546,8 @@ export type ChatCompletionsCommonOptions = { parallel_tool_calls?: boolean; prediction?: PredictionContent; presence_penalty?: number | null; - reasoning_effort?: "low" | "medium" | "high" | null; - chat_template_kwargs?: ChatTemplateKwargs; + reasoning_effort?: Effort | null; + chat_template_kwargs?: ChatTemplateKwargs; response_format?: ResponseFormat; seed?: number | null; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; @@ -633,9 +636,12 @@ export type ChatCompletionChoice = { logprobs: ChatCompletionLogprobs | null; }; -export type ChatCompletionsMessagesInput = { +export type ChatCompletionsMessagesInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { messages: Array; -} & ChatCompletionsCommonOptions; +} & ChatCompletionsCommonOptions; export type ChatCompletionsOutput = { id: string; @@ -658,7 +664,7 @@ export type ChatCompletionsOutput = { * It does not include types for WebSearch, CodeInterpreter, FileInputs, MCP, CustomTools. * We plan to add those incrementally as model + platform capabilities evolve. */ -export type ResponsesInput = { +export type ResponsesInput = { background?: boolean | null; conversation?: string | ResponseConversationParam | null; include?: Array | null; @@ -668,7 +674,7 @@ export type ResponsesInput = { parallel_tool_calls?: boolean | null; previous_response_id?: string | null; prompt_cache_key?: string; - reasoning?: Reasoning | null; + reasoning?: Reasoning | null; safety_identifier?: string; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; stream?: boolean | null; @@ -729,8 +735,8 @@ export type ResponsePrompt = { } | null; version?: string | null; }; -export type Reasoning = { - effort?: ReasoningEffort | null; +export type Reasoning = { + effort?: Effort | null; generate_summary?: "auto" | "concise" | "detailed" | null; summary?: "auto" | "concise" | "detailed" | null; }; @@ -4730,11 +4736,11 @@ export declare abstract class Base_Ai_Cf_Pipecat_Ai_Smart_Turn_V2 { postProcessedOutputs: Ai_Cf_Pipecat_Ai_Smart_Turn_V2_Output; } export declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_120B { - inputs: XOR; + inputs: XOR, ChatCompletionsInput<"low" | "medium" | "high", true>>; postProcessedOutputs: XOR; } export declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_20B { - inputs: XOR; + inputs: XOR, ChatCompletionsInput<"low" | "medium" | "high", true>>; postProcessedOutputs: XOR; } export interface Ai_Cf_Leonardo_Phoenix_1_0_Input { @@ -5824,7 +5830,7 @@ export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_5 { postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_6 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput<"high" | "none" | "low" | "medium" | "max", boolean>; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { @@ -5832,15 +5838,15 @@ export declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Google_Gemma_4_26B_A4B_IT { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput<"high" | "none" | "minimal" | "low" | "medium" | "max" | "auto", boolean>; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_7_Code { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput<"high" | "none" | "low" | "medium" | "max", true>; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_2 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput<"max" | "high" | "none" | "low" | "medium" | "xhigh" | "minimal", boolean>; postProcessedOutputs: ChatCompletionsOutput; } export interface Ai_Cf_Moondream_Moondream3_1_9B_A2B_Input { @@ -5977,19 +5983,23 @@ export declare abstract class Base_Ai_Cf_Moondream_Moondream3_1_9B_A2B { postProcessedOutputs: Ai_Cf_Moondream_Moondream3_1_9B_A2B_Output; } export declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput<"max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", boolean>; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput<"max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", boolean>; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Qwen_Qwen3_8_27B { inputs: ChatCompletionsInput; postProcessedOutputs: ChatCompletionsOutput; } +export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3 { + inputs: ChatCompletionsInput<"max" | "high" | "low" | "none" | "medium", true>; + postProcessedOutputs: ChatCompletionsOutput; +} export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3_Flash { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput<"max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", true>; postProcessedOutputs: ChatCompletionsOutput; } @@ -6091,6 +6101,7 @@ export interface AiModels { "@cf/deepseek-ai/deepseek-v4-flash-0731": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731; "@cf/deepseek-ai/deepseek-v4-pro-0813": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813; "@cf/qwen/qwen3.8-27b": Base_Ai_Cf_Qwen_Qwen3_8_27B; + "@cf/zai-org/glm-5.3": Base_Ai_Cf_Zai_Org_Glm_5_3; "@cf/zai-org/glm-5.3-flash": Base_Ai_Cf_Zai_Org_Glm_5_3_Flash; } export type AiOptions = { @@ -6146,7 +6157,10 @@ export type AiModelsSearchObject = { }; export type ChatCompletionsBase = ChatCompletionsMessagesInput; -export type ChatCompletionsInput = ChatCompletionsMessagesInput; +export type ChatCompletionsInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = ChatCompletionsMessagesInput; export interface InferenceUpstreamError extends Error {} export interface AiInternalError extends Error {} diff --git a/types/generated-snapshot/experimental/index.d.ts b/types/generated-snapshot/experimental/index.d.ts index 2d13a470932..1d152d8cef7 100755 --- a/types/generated-snapshot/experimental/index.d.ts +++ b/types/generated-snapshot/experimental/index.d.ts @@ -6483,14 +6483,17 @@ type WebSearchOptions = { search_context_size?: "low" | "medium" | "high"; user_location?: WebSearchUserLocation; }; -type ChatTemplateKwargs = { - /** Whether to enable reasoning, enabled by default. */ - enable_thinking?: boolean; +type ChatTemplateKwargs = { + /** Whether to enable reasoning. Support and defaults depend on the model. */ + enable_thinking?: ThinkingEnabled; /** If false, preserves reasoning context between turns. */ clear_thinking?: boolean; }; /** Shared optional properties used by both Prompt and Messages input branches. */ -type ChatCompletionsCommonOptions = { +type ChatCompletionsCommonOptions< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { model?: string; audio?: AudioParams; frequency_penalty?: number | null; @@ -6505,8 +6508,8 @@ type ChatCompletionsCommonOptions = { parallel_tool_calls?: boolean; prediction?: PredictionContent; presence_penalty?: number | null; - reasoning_effort?: "low" | "medium" | "high" | null; - chat_template_kwargs?: ChatTemplateKwargs; + reasoning_effort?: Effort | null; + chat_template_kwargs?: ChatTemplateKwargs; response_format?: ResponseFormat; seed?: number | null; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; @@ -6595,9 +6598,12 @@ type ChatCompletionChoice = { "stop" | "length" | "tool_calls" | "content_filter" | "function_call"; logprobs: ChatCompletionLogprobs | null; }; -type ChatCompletionsMessagesInput = { +type ChatCompletionsMessagesInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { messages: Array; -} & ChatCompletionsCommonOptions; +} & ChatCompletionsCommonOptions; type ChatCompletionsOutput = { id: string; object: string; @@ -6618,7 +6624,7 @@ type ChatCompletionsOutput = { * It does not include types for WebSearch, CodeInterpreter, FileInputs, MCP, CustomTools. * We plan to add those incrementally as model + platform capabilities evolve. */ -type ResponsesInput = { +type ResponsesInput = { background?: boolean | null; conversation?: string | ResponseConversationParam | null; include?: Array | null; @@ -6628,7 +6634,7 @@ type ResponsesInput = { parallel_tool_calls?: boolean | null; previous_response_id?: string | null; prompt_cache_key?: string; - reasoning?: Reasoning | null; + reasoning?: Reasoning | null; safety_identifier?: string; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; stream?: boolean | null; @@ -6689,8 +6695,8 @@ type ResponsePrompt = { } | null; version?: string | null; }; -type Reasoning = { - effort?: ReasoningEffort | null; +type Reasoning = { + effort?: Effort | null; generate_summary?: "auto" | "concise" | "detailed" | null; summary?: "auto" | "concise" | "detailed" | null; }; @@ -10713,11 +10719,17 @@ declare abstract class Base_Ai_Cf_Pipecat_Ai_Smart_Turn_V2 { postProcessedOutputs: Ai_Cf_Pipecat_Ai_Smart_Turn_V2_Output; } declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_120B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_20B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } interface Ai_Cf_Leonardo_Phoenix_1_0_Input { @@ -11808,7 +11820,10 @@ declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_5 { postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_6 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { @@ -11816,15 +11831,24 @@ declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Google_Gemma_4_26B_A4B_IT { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "minimal" | "low" | "medium" | "max" | "auto", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_7_Code { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + true + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_2 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "none" | "low" | "medium" | "xhigh" | "minimal", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } interface Ai_Cf_Moondream_Moondream3_1_9B_A2B_Input { @@ -11961,19 +11985,35 @@ declare abstract class Base_Ai_Cf_Moondream_Moondream3_1_9B_A2B { postProcessedOutputs: Ai_Cf_Moondream_Moondream3_1_9B_A2B_Output; } declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Qwen_Qwen3_8_27B { inputs: ChatCompletionsInput; postProcessedOutputs: ChatCompletionsOutput; } +declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3 { + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "medium", + true + >; + postProcessedOutputs: ChatCompletionsOutput; +} declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3_Flash { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + true + >; postProcessedOutputs: ChatCompletionsOutput; } interface AiModels { @@ -12074,6 +12114,7 @@ interface AiModels { "@cf/deepseek-ai/deepseek-v4-flash-0731": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731; "@cf/deepseek-ai/deepseek-v4-pro-0813": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813; "@cf/qwen/qwen3.8-27b": Base_Ai_Cf_Qwen_Qwen3_8_27B; + "@cf/zai-org/glm-5.3": Base_Ai_Cf_Zai_Org_Glm_5_3; "@cf/zai-org/glm-5.3-flash": Base_Ai_Cf_Zai_Org_Glm_5_3_Flash; } type AiOptions = { @@ -12128,7 +12169,10 @@ type AiModelsSearchObject = { }[]; }; type ChatCompletionsBase = ChatCompletionsMessagesInput; -type ChatCompletionsInput = ChatCompletionsMessagesInput; +type ChatCompletionsInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = ChatCompletionsMessagesInput; interface InferenceUpstreamError extends Error {} interface AiInternalError extends Error {} type AiModelListType = Record; diff --git a/types/generated-snapshot/experimental/index.ts b/types/generated-snapshot/experimental/index.ts index 402342e9c94..48865ef80c7 100755 --- a/types/generated-snapshot/experimental/index.ts +++ b/types/generated-snapshot/experimental/index.ts @@ -6494,14 +6494,17 @@ export type WebSearchOptions = { search_context_size?: "low" | "medium" | "high"; user_location?: WebSearchUserLocation; }; -export type ChatTemplateKwargs = { - /** Whether to enable reasoning, enabled by default. */ - enable_thinking?: boolean; +export type ChatTemplateKwargs = { + /** Whether to enable reasoning. Support and defaults depend on the model. */ + enable_thinking?: ThinkingEnabled; /** If false, preserves reasoning context between turns. */ clear_thinking?: boolean; }; /** Shared optional properties used by both Prompt and Messages input branches. */ -export type ChatCompletionsCommonOptions = { +export type ChatCompletionsCommonOptions< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { model?: string; audio?: AudioParams; frequency_penalty?: number | null; @@ -6516,8 +6519,8 @@ export type ChatCompletionsCommonOptions = { parallel_tool_calls?: boolean; prediction?: PredictionContent; presence_penalty?: number | null; - reasoning_effort?: "low" | "medium" | "high" | null; - chat_template_kwargs?: ChatTemplateKwargs; + reasoning_effort?: Effort | null; + chat_template_kwargs?: ChatTemplateKwargs; response_format?: ResponseFormat; seed?: number | null; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; @@ -6606,9 +6609,12 @@ export type ChatCompletionChoice = { "stop" | "length" | "tool_calls" | "content_filter" | "function_call"; logprobs: ChatCompletionLogprobs | null; }; -export type ChatCompletionsMessagesInput = { +export type ChatCompletionsMessagesInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { messages: Array; -} & ChatCompletionsCommonOptions; +} & ChatCompletionsCommonOptions; export type ChatCompletionsOutput = { id: string; object: string; @@ -6629,7 +6635,7 @@ export type ChatCompletionsOutput = { * It does not include types for WebSearch, CodeInterpreter, FileInputs, MCP, CustomTools. * We plan to add those incrementally as model + platform capabilities evolve. */ -export type ResponsesInput = { +export type ResponsesInput = { background?: boolean | null; conversation?: string | ResponseConversationParam | null; include?: Array | null; @@ -6639,7 +6645,7 @@ export type ResponsesInput = { parallel_tool_calls?: boolean | null; previous_response_id?: string | null; prompt_cache_key?: string; - reasoning?: Reasoning | null; + reasoning?: Reasoning | null; safety_identifier?: string; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; stream?: boolean | null; @@ -6700,8 +6706,8 @@ export type ResponsePrompt = { } | null; version?: string | null; }; -export type Reasoning = { - effort?: ReasoningEffort | null; +export type Reasoning = { + effort?: Effort | null; generate_summary?: "auto" | "concise" | "detailed" | null; summary?: "auto" | "concise" | "detailed" | null; }; @@ -10725,11 +10731,17 @@ export declare abstract class Base_Ai_Cf_Pipecat_Ai_Smart_Turn_V2 { postProcessedOutputs: Ai_Cf_Pipecat_Ai_Smart_Turn_V2_Output; } export declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_120B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } export declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_20B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } export interface Ai_Cf_Leonardo_Phoenix_1_0_Input { @@ -11820,7 +11832,10 @@ export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_5 { postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_6 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { @@ -11828,15 +11843,24 @@ export declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Google_Gemma_4_26B_A4B_IT { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "minimal" | "low" | "medium" | "max" | "auto", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_7_Code { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + true + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_2 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "none" | "low" | "medium" | "xhigh" | "minimal", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export interface Ai_Cf_Moondream_Moondream3_1_9B_A2B_Input { @@ -11973,19 +11997,35 @@ export declare abstract class Base_Ai_Cf_Moondream_Moondream3_1_9B_A2B { postProcessedOutputs: Ai_Cf_Moondream_Moondream3_1_9B_A2B_Output; } export declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Qwen_Qwen3_8_27B { inputs: ChatCompletionsInput; postProcessedOutputs: ChatCompletionsOutput; } +export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3 { + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "medium", + true + >; + postProcessedOutputs: ChatCompletionsOutput; +} export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3_Flash { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + true + >; postProcessedOutputs: ChatCompletionsOutput; } export interface AiModels { @@ -12086,6 +12126,7 @@ export interface AiModels { "@cf/deepseek-ai/deepseek-v4-flash-0731": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731; "@cf/deepseek-ai/deepseek-v4-pro-0813": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813; "@cf/qwen/qwen3.8-27b": Base_Ai_Cf_Qwen_Qwen3_8_27B; + "@cf/zai-org/glm-5.3": Base_Ai_Cf_Zai_Org_Glm_5_3; "@cf/zai-org/glm-5.3-flash": Base_Ai_Cf_Zai_Org_Glm_5_3_Flash; } export type AiOptions = { @@ -12140,7 +12181,10 @@ export type AiModelsSearchObject = { }[]; }; export type ChatCompletionsBase = ChatCompletionsMessagesInput; -export type ChatCompletionsInput = ChatCompletionsMessagesInput; +export type ChatCompletionsInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = ChatCompletionsMessagesInput; export interface InferenceUpstreamError extends Error {} export interface AiInternalError extends Error {} export type AiModelListType = Record; diff --git a/types/generated-snapshot/index.d.ts b/types/generated-snapshot/index.d.ts index ec0b5782110..b361d03c31b 100755 --- a/types/generated-snapshot/index.d.ts +++ b/types/generated-snapshot/index.d.ts @@ -6200,14 +6200,17 @@ type WebSearchOptions = { search_context_size?: "low" | "medium" | "high"; user_location?: WebSearchUserLocation; }; -type ChatTemplateKwargs = { - /** Whether to enable reasoning, enabled by default. */ - enable_thinking?: boolean; +type ChatTemplateKwargs = { + /** Whether to enable reasoning. Support and defaults depend on the model. */ + enable_thinking?: ThinkingEnabled; /** If false, preserves reasoning context between turns. */ clear_thinking?: boolean; }; /** Shared optional properties used by both Prompt and Messages input branches. */ -type ChatCompletionsCommonOptions = { +type ChatCompletionsCommonOptions< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { model?: string; audio?: AudioParams; frequency_penalty?: number | null; @@ -6222,8 +6225,8 @@ type ChatCompletionsCommonOptions = { parallel_tool_calls?: boolean; prediction?: PredictionContent; presence_penalty?: number | null; - reasoning_effort?: "low" | "medium" | "high" | null; - chat_template_kwargs?: ChatTemplateKwargs; + reasoning_effort?: Effort | null; + chat_template_kwargs?: ChatTemplateKwargs; response_format?: ResponseFormat; seed?: number | null; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; @@ -6312,9 +6315,12 @@ type ChatCompletionChoice = { "stop" | "length" | "tool_calls" | "content_filter" | "function_call"; logprobs: ChatCompletionLogprobs | null; }; -type ChatCompletionsMessagesInput = { +type ChatCompletionsMessagesInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { messages: Array; -} & ChatCompletionsCommonOptions; +} & ChatCompletionsCommonOptions; type ChatCompletionsOutput = { id: string; object: string; @@ -6335,7 +6341,7 @@ type ChatCompletionsOutput = { * It does not include types for WebSearch, CodeInterpreter, FileInputs, MCP, CustomTools. * We plan to add those incrementally as model + platform capabilities evolve. */ -type ResponsesInput = { +type ResponsesInput = { background?: boolean | null; conversation?: string | ResponseConversationParam | null; include?: Array | null; @@ -6345,7 +6351,7 @@ type ResponsesInput = { parallel_tool_calls?: boolean | null; previous_response_id?: string | null; prompt_cache_key?: string; - reasoning?: Reasoning | null; + reasoning?: Reasoning | null; safety_identifier?: string; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; stream?: boolean | null; @@ -6406,8 +6412,8 @@ type ResponsePrompt = { } | null; version?: string | null; }; -type Reasoning = { - effort?: ReasoningEffort | null; +type Reasoning = { + effort?: Effort | null; generate_summary?: "auto" | "concise" | "detailed" | null; summary?: "auto" | "concise" | "detailed" | null; }; @@ -10430,11 +10436,17 @@ declare abstract class Base_Ai_Cf_Pipecat_Ai_Smart_Turn_V2 { postProcessedOutputs: Ai_Cf_Pipecat_Ai_Smart_Turn_V2_Output; } declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_120B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_20B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } interface Ai_Cf_Leonardo_Phoenix_1_0_Input { @@ -11525,7 +11537,10 @@ declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_5 { postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_6 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { @@ -11533,15 +11548,24 @@ declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Google_Gemma_4_26B_A4B_IT { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "minimal" | "low" | "medium" | "max" | "auto", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_7_Code { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + true + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_2 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "none" | "low" | "medium" | "xhigh" | "minimal", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } interface Ai_Cf_Moondream_Moondream3_1_9B_A2B_Input { @@ -11678,19 +11702,35 @@ declare abstract class Base_Ai_Cf_Moondream_Moondream3_1_9B_A2B { postProcessedOutputs: Ai_Cf_Moondream_Moondream3_1_9B_A2B_Output; } declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } declare abstract class Base_Ai_Cf_Qwen_Qwen3_8_27B { inputs: ChatCompletionsInput; postProcessedOutputs: ChatCompletionsOutput; } +declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3 { + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "medium", + true + >; + postProcessedOutputs: ChatCompletionsOutput; +} declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3_Flash { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + true + >; postProcessedOutputs: ChatCompletionsOutput; } interface AiModels { @@ -11791,6 +11831,7 @@ interface AiModels { "@cf/deepseek-ai/deepseek-v4-flash-0731": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731; "@cf/deepseek-ai/deepseek-v4-pro-0813": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813; "@cf/qwen/qwen3.8-27b": Base_Ai_Cf_Qwen_Qwen3_8_27B; + "@cf/zai-org/glm-5.3": Base_Ai_Cf_Zai_Org_Glm_5_3; "@cf/zai-org/glm-5.3-flash": Base_Ai_Cf_Zai_Org_Glm_5_3_Flash; } type AiOptions = { @@ -11845,7 +11886,10 @@ type AiModelsSearchObject = { }[]; }; type ChatCompletionsBase = ChatCompletionsMessagesInput; -type ChatCompletionsInput = ChatCompletionsMessagesInput; +type ChatCompletionsInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = ChatCompletionsMessagesInput; interface InferenceUpstreamError extends Error {} interface AiInternalError extends Error {} type AiModelListType = Record; diff --git a/types/generated-snapshot/index.ts b/types/generated-snapshot/index.ts index 4b0698eef97..2920cb1fe64 100755 --- a/types/generated-snapshot/index.ts +++ b/types/generated-snapshot/index.ts @@ -6211,14 +6211,17 @@ export type WebSearchOptions = { search_context_size?: "low" | "medium" | "high"; user_location?: WebSearchUserLocation; }; -export type ChatTemplateKwargs = { - /** Whether to enable reasoning, enabled by default. */ - enable_thinking?: boolean; +export type ChatTemplateKwargs = { + /** Whether to enable reasoning. Support and defaults depend on the model. */ + enable_thinking?: ThinkingEnabled; /** If false, preserves reasoning context between turns. */ clear_thinking?: boolean; }; /** Shared optional properties used by both Prompt and Messages input branches. */ -export type ChatCompletionsCommonOptions = { +export type ChatCompletionsCommonOptions< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { model?: string; audio?: AudioParams; frequency_penalty?: number | null; @@ -6233,8 +6236,8 @@ export type ChatCompletionsCommonOptions = { parallel_tool_calls?: boolean; prediction?: PredictionContent; presence_penalty?: number | null; - reasoning_effort?: "low" | "medium" | "high" | null; - chat_template_kwargs?: ChatTemplateKwargs; + reasoning_effort?: Effort | null; + chat_template_kwargs?: ChatTemplateKwargs; response_format?: ResponseFormat; seed?: number | null; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; @@ -6323,9 +6326,12 @@ export type ChatCompletionChoice = { "stop" | "length" | "tool_calls" | "content_filter" | "function_call"; logprobs: ChatCompletionLogprobs | null; }; -export type ChatCompletionsMessagesInput = { +export type ChatCompletionsMessagesInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = { messages: Array; -} & ChatCompletionsCommonOptions; +} & ChatCompletionsCommonOptions; export type ChatCompletionsOutput = { id: string; object: string; @@ -6346,7 +6352,7 @@ export type ChatCompletionsOutput = { * It does not include types for WebSearch, CodeInterpreter, FileInputs, MCP, CustomTools. * We plan to add those incrementally as model + platform capabilities evolve. */ -export type ResponsesInput = { +export type ResponsesInput = { background?: boolean | null; conversation?: string | ResponseConversationParam | null; include?: Array | null; @@ -6356,7 +6362,7 @@ export type ResponsesInput = { parallel_tool_calls?: boolean | null; previous_response_id?: string | null; prompt_cache_key?: string; - reasoning?: Reasoning | null; + reasoning?: Reasoning | null; safety_identifier?: string; service_tier?: "auto" | "default" | "flex" | "scale" | "priority" | null; stream?: boolean | null; @@ -6417,8 +6423,8 @@ export type ResponsePrompt = { } | null; version?: string | null; }; -export type Reasoning = { - effort?: ReasoningEffort | null; +export type Reasoning = { + effort?: Effort | null; generate_summary?: "auto" | "concise" | "detailed" | null; summary?: "auto" | "concise" | "detailed" | null; }; @@ -10442,11 +10448,17 @@ export declare abstract class Base_Ai_Cf_Pipecat_Ai_Smart_Turn_V2 { postProcessedOutputs: Ai_Cf_Pipecat_Ai_Smart_Turn_V2_Output; } export declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_120B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } export declare abstract class Base_Ai_Cf_Openai_Gpt_Oss_20B { - inputs: XOR; + inputs: XOR< + ResponsesInput<"low" | "medium" | "high">, + ChatCompletionsInput<"low" | "medium" | "high", true> + >; postProcessedOutputs: XOR; } export interface Ai_Cf_Leonardo_Phoenix_1_0_Input { @@ -11537,7 +11549,10 @@ export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_5 { postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_6 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { @@ -11545,15 +11560,24 @@ export declare abstract class Base_Ai_Cf_Nvidia_Nemotron_3_120B_A12B { postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Google_Gemma_4_26B_A4B_IT { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "minimal" | "low" | "medium" | "max" | "auto", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Moonshotai_Kimi_K2_7_Code { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "high" | "none" | "low" | "medium" | "max", + true + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_2 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "none" | "low" | "medium" | "xhigh" | "minimal", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export interface Ai_Cf_Moondream_Moondream3_1_9B_A2B_Input { @@ -11690,19 +11714,35 @@ export declare abstract class Base_Ai_Cf_Moondream_Moondream3_1_9B_A2B { postProcessedOutputs: Ai_Cf_Moondream_Moondream3_1_9B_A2B_Output; } export declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813 { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + boolean + >; postProcessedOutputs: ChatCompletionsOutput; } export declare abstract class Base_Ai_Cf_Qwen_Qwen3_8_27B { inputs: ChatCompletionsInput; postProcessedOutputs: ChatCompletionsOutput; } +export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3 { + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "medium", + true + >; + postProcessedOutputs: ChatCompletionsOutput; +} export declare abstract class Base_Ai_Cf_Zai_Org_Glm_5_3_Flash { - inputs: ChatCompletionsInput; + inputs: ChatCompletionsInput< + "max" | "high" | "low" | "none" | "minimal" | "medium" | "xhigh", + true + >; postProcessedOutputs: ChatCompletionsOutput; } export interface AiModels { @@ -11803,6 +11843,7 @@ export interface AiModels { "@cf/deepseek-ai/deepseek-v4-flash-0731": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Flash_0731; "@cf/deepseek-ai/deepseek-v4-pro-0813": Base_Ai_Cf_Deepseek_Ai_Deepseek_V4_Pro_0813; "@cf/qwen/qwen3.8-27b": Base_Ai_Cf_Qwen_Qwen3_8_27B; + "@cf/zai-org/glm-5.3": Base_Ai_Cf_Zai_Org_Glm_5_3; "@cf/zai-org/glm-5.3-flash": Base_Ai_Cf_Zai_Org_Glm_5_3_Flash; } export type AiOptions = { @@ -11857,7 +11898,10 @@ export type AiModelsSearchObject = { }[]; }; export type ChatCompletionsBase = ChatCompletionsMessagesInput; -export type ChatCompletionsInput = ChatCompletionsMessagesInput; +export type ChatCompletionsInput< + Effort extends string = "low" | "medium" | "high", + ThinkingEnabled extends boolean = boolean, +> = ChatCompletionsMessagesInput; export interface InferenceUpstreamError extends Error {} export interface AiInternalError extends Error {} export type AiModelListType = Record; diff --git a/types/test/types/ai-reasoning.ts b/types/test/types/ai-reasoning.ts new file mode 100644 index 00000000000..36c2d0179f6 --- /dev/null +++ b/types/test/types/ai-reasoning.ts @@ -0,0 +1,67 @@ +// Copyright (c) 2026 Cloudflare, Inc. +// Licensed under the Apache 2.0 license found in the LICENSE file or at: +// https://opensource.org/licenses/Apache-2.0 + +declare const ai: Ai; +const messages = [{ role: 'user' as const, content: 'Hello' }]; + +// Canonical controls and compatibility aliases remain accepted. +void ai.run('@cf/google/gemma-4-26b-a4b-it', { + messages, + reasoning_effort: 'none', +}); +void ai.run('@cf/google/gemma-4-26b-a4b-it', { + messages, + reasoning_effort: 'auto', +}); +void ai.run('@cf/moonshotai/kimi-k2.6', { + messages, + reasoning_effort: 'medium', +}); +void ai.run('@cf/zai-org/glm-5.3', { messages, reasoning_effort: 'max' }); +void ai.run('@cf/zai-org/glm-5.3-flash', { messages, reasoning_effort: 'max' }); +void ai.run('@cf/deepseek-ai/deepseek-v4-pro-0813', { + messages, + reasoning_effort: 'low', +}); +void ai.run('@cf/zai-org/glm-4.7-flash', { + messages, + chat_template_kwargs: { enable_thinking: false }, +}); + +void ai.run('@cf/openai/gpt-oss-20b', { + input: 'Hello', + reasoning: { effort: 'medium' }, +}); +void ai.run('@cf/openai/gpt-oss-120b', { messages, reasoning_effort: 'high' }); +// A legacy alias is an accepted input even when it does not disable reasoning. +void ai.run('@cf/moonshotai/kimi-k2.7-code', { + messages, + reasoning_effort: 'none', +}); + +// @ts-expect-error: an unsupported effort must not reach the gateway fallback overload +void ai.run('@cf/google/gemma-4-26b-a4b-it', { + messages, + reasoning_effort: 'turbo', +}); +// @ts-expect-error: GPT-OSS reasoning is mandatory +void ai.run('@cf/openai/gpt-oss-20b', { + input: 'Hello', + reasoning: { effort: 'none' }, +}); +// @ts-expect-error: mandatory reasoning cannot be disabled with enable_thinking +void ai.run('@cf/moonshotai/kimi-k2.7-code', { + messages, + chat_template_kwargs: { enable_thinking: false }, +}); + +// Unrelated options remain available on both input formats. +void ai.run('@cf/google/gemma-4-26b-a4b-it', { + messages, + service_tier: 'priority', +}); +void ai.run('@cf/openai/gpt-oss-20b', { + input: 'Hello', + service_tier: 'priority', +});