Open History to see the last commit
1import type { ModelReasoning } from '@tanstack/ai'
2import type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'
3import type {
4 AiModels,
5 BaseAiAutomaticSpeechRecognition,
6 BaseAiTextEmbeddings,
7 BaseAiTextGeneration,
8 BaseAiTextToImage,
9 BaseAiTextToSpeech,
10} from '@cloudflare/workers-types'
11
12// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and
13// the provider value to send for each. Each model points at one of them.
14const EFFORT_LOW_HIGH_MAX = {
15 levels: { low: 'low', high: 'high', max: 'max' },
16 budget: false,
17} as const
18const EFFORT_LOW_TO_HIGH = {
19 levels: { low: 'low', medium: 'medium', high: 'high' },
20 budget: false,
21} as const
22const EFFORT_NONE_HIGH = {
23 levels: { off: 'none', high: 'high' },
24 budget: false,
25} as const
26const EFFORT_NONE_HIGH_MAX = {
27 levels: { off: 'none', high: 'high', max: 'max' },
28 budget: false,
29} as const
30const EFFORT_NONE_LOW_HIGH_MAX = {
31 levels: { off: 'none', low: 'low', high: 'high', max: 'max' },
32 budget: false,
33} as const
34const EFFORT_NONE_LOW_MEDIUM_XHIGH = {
35 levels: { off: 'none', low: 'low', medium: 'medium', xhigh: 'xhigh' },
36 budget: false,
37} as const
38const EFFORT_NONE_LOW_TO_HIGH = {
39 levels: { off: 'none', low: 'low', medium: 'medium', high: 'high' },
40 budget: false,
41} as const
42const EFFORT_OFF_HIGH = {
43 levels: { off: 'off', high: 'high' },
44 budget: false,
45} as const
46
47/** Model ids from the Workers AI catalog whose task shape matches `TTask`. */
48type ModelsFor<TTask> = {
49 [K in keyof AiModels]: AiModels[K] extends TTask ? K : never
50}[keyof AiModels]
51
52/**
53 * Chat model id. Catalog ids get autocomplete; any other id works too,
54 * including third-party `provider/model` ids routed through AI Gateway
55 * (for example `openai/gpt-5.5`).
56 */
57export type CloudflareTextModel =
58 | ModelsFor<BaseAiTextGeneration>
59 | (string & {})
60
61export type CloudflareEmbeddingModel =
62 | ModelsFor<BaseAiTextEmbeddings>
63 | (string & {})
64
65export type CloudflareImageModel = ModelsFor<BaseAiTextToImage> | (string & {})
66
67export type CloudflareTTSModel =
68 | ModelsFor<BaseAiTextToSpeech>
69 | '@cf/deepgram/aura-1'
70 | '@cf/deepgram/aura-2-en'
71 | '@cf/deepgram/aura-2-es'
72 | (string & {})
73
74export type CloudflareTranscriptionModel =
75 | ModelsFor<BaseAiAutomaticSpeechRecognition>
76 | '@cf/openai/whisper-large-v3-turbo'
77 | '@cf/deepgram/nova-3'
78 | (string & {})
79
80/**
81 * Evaluate model id. TypeSafe Jev on Workers AI is `typesafe/jev`.
82 * Any other id works too.
83 */
84export type CloudflareEvaluateModel = 'typesafe/jev' | (string & {})
85
86// Reasoning
87//
88// Each model's data for `chat({ reasoning })`: the levels it has, with the
89// provider value for each, and whether it takes a thinking token budget. The
90// data comes from models.dev. The generator that writes it comes with the model
91// catalog later. Until then, edit these entries by hand.
92
93const CLOUDFLARE_REASONING = {
94 '@cf/google/gemma-4-26b-a4b-it': EFFORT_NONE_HIGH,
95 '@cf/deepseek-ai/deepseek-v4-flash-0731': EFFORT_NONE_LOW_HIGH_MAX,
96 '@cf/deepseek-ai/deepseek-v4-pro-0813': EFFORT_NONE_LOW_HIGH_MAX,
97 '@cf/moonshotai/kimi-k2.6': EFFORT_NONE_HIGH,
98 '@cf/zai-org/glm-5.3-flash': EFFORT_LOW_HIGH_MAX,
99 '@cf/zai-org/glm-4.7-flash': EFFORT_OFF_HIGH,
100 '@cf/zai-org/glm-5.2': EFFORT_NONE_HIGH_MAX,
101 '@cf/zai-org/glm-5.3': EFFORT_LOW_HIGH_MAX,
102 '@cf/nvidia/nemotron-3-120b-a12b': EFFORT_NONE_LOW_TO_HIGH,
103 '@cf/qwen/qwen3.8-27b': EFFORT_NONE_LOW_MEDIUM_XHIGH,
104 '@cf/openai/gpt-oss-20b': EFFORT_LOW_TO_HIGH,
105 '@cf/openai/gpt-oss-120b': EFFORT_LOW_TO_HIGH,
106} satisfies Record<string, ModelReasoning>
107
108/**
109 * Each model's reasoning levels, and whether it takes a token budget, for
110 * `chat({ reasoning })`. A model that is not here does not reason.
111 */
112export type CloudflareModelReasoningByName = {
113 [K in keyof typeof CLOUDFLARE_REASONING]: ModelReasoningCapability<
114 (typeof CLOUDFLARE_REASONING)[K]
115 >
116}
117
118/**
119 * Runtime map from model id to its reasoning data, for the text adapter. An
120 * unknown id gives `undefined`: the adapter sends no reasoning field.
121 */
122export const CLOUDFLARE_MODEL_REASONING: Readonly<
123 Record<string, ModelReasoning>
124> = CLOUDFLARE_REASONING