Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

azure-models.ts

782 lines25.4 KB

1/**
2 * Azure OpenAI catalog facts from two Microsoft Learn articles, read as
3 * their markdown twins (`Accept: text/markdown`), plus the chat request
4 * body in Azure's v1 OpenAPI document.
5 *
6 * The models article has one `Model ID` table per family under a `## `
7 * heading; the heading and the table's columns give the activity, and the
8 * row gives the token limits and a capability list. The reasoning article
9 * has a feature matrix with one column per model; where a model has a
10 * column there, its ✅ / - cells win over the capability list.
11 *
12 * Accepted `reasoning_effort` values are the feature table's options, cut
13 * down by the "works only with" clauses and footnote 7. A model the matrix
14 * marks as supporting reasoning effort and whose rules do not name gets
15 * `low`, `medium`, and `high`.
16 */
17import type { Activity } from '#/db/schema.ts'
18​
19import { MODALITIES_SOURCE_SILENT } from './fact-sources.ts'
20import { markdownTableRows, tokenCount } from './model-facts.ts'
21import type { ChatRequestMap, EffortLevelMap } from './request-map.ts'
22import type {
23 FactSource,
24 ModelFactSources,
25 ModelInfo,
26 ModelReasoning,
27} from './types.ts'
28​
29export const AZURE_MODELS_URL =
30 'https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure'
31export const AZURE_REASONING_URL =
32 'https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/reasoning'
33​
34/** `## ` headings whose `Model ID` tables are not chat models. */
35const SECTION_ACTIVITY: Array<[RegExp, Activity]> = [
36 [/^Embeddings/i, 'embeddings'],
37 [/^Image generation/i, 'image'],
38 [/^Video generation/i, 'video'],
39 [/^Audio/i, 'audio'],
41​
42/** Tables that repeat ids from the family sections with no model facts. */
43const SKIPPED_SECTION = /^(Fine-tuning|Assistants|Model retirement)/i
44​
45export interface AzureModelRow {
46 rawId: string
47 /**
48 * False for an id the article names only in running text. Such a row
49 * carries no facts, and the caller lists it only when the price list
50 * meters it: `o3-deep-research` is served, `gpt-5.6` is a family name.
51 */
52 tabulated: boolean
53 /** `YYYY-MM-DD` of the row's model version, when the row dates it. */
54 version: string | null
55 retired: boolean
56 activity: Activity | null
57 contextWindow: number | null
58 maxOutput: number | null
59 modalities: { input: Array<string>; output: Array<string> } | null
60 capabilities: Array<string>
61 chatCompletions: boolean
62 responses: boolean
63 /**
64 * The models article says this id uses a fixed reasoning level and
65 * rejects `reasoning_effort`.
66 */
67 fixedReasoningEffort: boolean
68 /** The models article says `reasoning_effort` `none` is not supported. */
69 noneExcluded: boolean
71​
72/** One model's column in the reasoning article's feature matrix. */
73export interface AzureFeatureColumn {
74 capabilities: Array<string>
75 modalities: { input: Array<string>; output: Array<string> } | null
76 chatCompletions: boolean | null
77 responses: boolean | null
78 /** The reasoning-effort cell is ✅. */
79 effort: boolean
80 /** The row label says the accepted values include `none`. */
81 effortIncludesNone: boolean
82 /** Null when that matrix has no Developer Messages row. */
83 developerMessages: boolean | null
84 /** Null when that matrix has no `max_completion_tokens` row. */
85 maxCompletionTokens: boolean | null
87​
88/** Link targets hold words like `reasoning` that are not statements. */
89function plain(cell: string): string {
90 return cell.replace(/\]\([^)]*\)/g, ']')
92​
93function descriptionModalities(text: string): AzureModelRow['modalities'] {
94 const output = /text output|text only|text out\b|input\/output/i.test(text)
95 ? ['text']
96 : []
97 if (
98 /text and image (?:processing|input)|input\*\*: text\/image|image \(input\)/i.test(
99 text,
100 )
101 ) {
102 return { input: ['text', 'image'], output }
103 }
104 if (/text in\/text out only|text-only processing/i.test(text)) {
105 return { input: ['text'], output }
106 }
107 return null
109​
110function descriptionCapabilities(text: string): Array<string> {
111 const caps: Array<string> = []
112 if (/\bfunctions?\b|\btools\b/i.test(text)) caps.push('tools')
113 if (/\breasoning\b/i.test(text)) caps.push('reasoning')
114 if (/structured outputs/i.test(text)) {
115 caps.push('structured_outputs', 'response_format')
116 }
117 return caps
119​
120/**
121 * The `Context Window` cell: `400,000Input: 272,000Output: 128,000` is
122 * 400,000. A cell that lists a limit per deployment type gives the
123 * `standard deployments` one, the tier prices are read for. Any other
124 * mix of limits is not guessed at.
125 */
126export function azureContextWindow(cell: string): number | null {
127 const limits = [
128 ...(cell.split(/Input:/i)[0] ?? '').matchAll(
129 /([\d,]*\d)\s*(?:\(([^)]*)\))?/g,
130 ),
131 ]
132 const only = limits.length === 1 ? limits[0] : undefined
133 if (only && only[2] === undefined) return tokenCount(only[1])
134 const standard = limits.filter((limit) =>
135 /^standard deployments$/i.test(limit[2]?.trim() ?? ''),
136 )
137 return standard.length === 1 ? tokenCount(standard[0]?.[1]) : null
139​
140/** Newest non-retired row wins; a model with only retired rows keeps one. */
141function better(next: AzureModelRow, current: AzureModelRow): boolean {
142 if (next.retired !== current.retired) return !next.retired
143 return (next.version ?? '') > (current.version ?? '')
145​
146/**
147 * Every model the Azure OpenAI pivot tabulates, by id, then the ids it names
148 * only in running text.
149 */
150export function parseAzureModels(markdown: string): Map<string, AzureModelRow> {
151 // Learn serves the twin with CRLF line ends in places.
152 const text = markdown.replace(/\r/g, '')
153 const start = text.indexOf('::: zone pivot="azure-openai"')
154 const end = text.indexOf('::: zone-end', start)
155 const zone = start < 0 ? '' : text.slice(start, end < 0 ? undefined : end)
156​
157 const out = new Map<string, AzureModelRow>()
158 for (const section of zone.split(/\n## /).slice(1)) {
159 const heading = section.slice(0, section.indexOf('\n')).trim()
160 if (SKIPPED_SECTION.test(heading)) continue
161 const sectionActivity = SECTION_ACTIVITY.find(([pattern]) =>
162 pattern.test(heading),
163 )?.[1]
164 const listedChat = /listed models support the Chat Completions API/i.test(
165 section,
166 )
167 const responseVersions = listedResponses(section)
168​
169 let columns: Array<string> | null = null
170 for (const cells of markdownTableRows(section)) {
171 if (cells[0] === 'Model ID') {
172 columns = cells.map((cell) => cell.toLowerCase())
173 continue
174 }
175 if (!columns) continue
176 const cell = (name: string): string | undefined => {
177 const index = columns?.indexOf(name) ?? -1
178 return index < 0 ? undefined : cells[index]
179 }
180 const window = cell('context window')
181 const request = cell('max request (tokens)')
182 // Without a token-limit column the family is not a chat family.
183 const activity =
184 sectionActivity ?? (window != null || request != null ? 'chat' : null)
185 const input = request?.match(/Input:\s*([\d,]+)/)?.[1]
186 const description = plain(cell('description') ?? '')
187​
188 const idCell = cells[0] ?? ''
189 const retired = /\*\*Retired/.test(idCell)
190 const trailing = idCell.replace(/`[^`]+`|\^\d+\^|\([^)]*\)/g, ' ')
191 const described = descriptionModalities(description)
192 const vision = /\bwith vision\b/i.test(trailing)
193 ? { input: ['text', 'image'], output: [] }
194 : null
195 for (const match of idCell.matchAll(
196 /`([^`]+)`(?:\^\d+\^)?\s*(?:\(([^)]*)\))?/g,
197 )) {
198 const rawId = match[1]?.trim()
199 if (!rawId) continue
200 const version = match[2]?.match(/\d{4}-\d{2}-\d{2}/)?.[0] ?? null
201 const row: AzureModelRow = {
202 rawId,
203 tabulated: true,
204 version,
205 retired,
206 activity,
207 contextWindow:
208 window != null
209 ? azureContextWindow(window)
210 : tokenCount(
211 input ?? (/^[\d,]+$/.test(request ?? '') ? request : ''),
212 ),
213 maxOutput: tokenCount(
214 cell('max output tokens') ??
215 request?.match(/Output:\s*([\d,]+)/)?.[1],
216 ),
217 modalities: described ?? vision,
218 capabilities: descriptionCapabilities(description),
219 chatCompletions:
220 listedChat || /chat completions api/i.test(description),
221 responses:
222 (responseVersions.get(rawId)?.has(version ?? '') ?? false) ||
223 /responses api/i.test(description),
224 fixedReasoningEffort: false,
225 noneExcluded: false,
226 }
227 const current = out.get(rawId)
228 if (!current || better(row, current)) out.set(rawId, row)
229 }
230 }
231 }
232 if (out.size === 0) return out
233​
234 for (const match of zone.matchAll(
235 /`([^`]+)` uses a fixed, nonzero reasoning level[\s\S]{0,320}?`reasoning_effort`/g,
236 )) {
237 const namedRow = out.get(match[1] ?? '')
238 if (namedRow) namedRow.fixedReasoningEffort = true
239 }
240 for (const match of zone.matchAll(
241 /Reasoning effort `none` is not supported with `([^`]+)`/g,
242 )) {
243 const namedRow = out.get(match[1] ?? '')
244 if (namedRow) namedRow.noneExcluded = true
245 }
246​
247 const prose = zone
248 .split('\n')
249 .filter((line) => !line.startsWith('|'))
250 .join('\n')
251 for (const match of prose.matchAll(/`([a-z][a-z0-9.-]*)`/g)) {
252 const rawId = match[1]
253 if (!rawId || out.has(rawId)) continue
254 out.set(rawId, {
255 rawId,
256 tabulated: false,
257 version: null,
258 retired: false,
259 activity: null,
260 contextWindow: null,
261 maxOutput: null,
262 modalities: null,
263 capabilities: [],
264 chatCompletions: false,
265 responses: false,
266 fixedReasoningEffort: false,
267 noneExcluded: false,
268 })
269 }
270 return out
272​
273/**
274 * Versions the GPT-4 section names as also serving the Responses API.
275 * Empty when that sentence is absent.
276 */
277function listedResponses(section: string): Map<string, Set<string>> {
278 const out = new Map<string, Set<string>>()
279 const clause =
280 /GPT-4o versions ([\s\S]*?), and GPT-4o-mini version `(\d{4}-\d{2}-\d{2})`/.exec(
281 section,
282 )
283 const dates = clause?.[1]
284 if (dates) {
285 out.set(
286 'gpt-4o',
287 new Set(
288 [...dates.matchAll(/`(\d{4}-\d{2}-\d{2})`/g)]
289 .map((match) => match[1])
290 .filter((date): date is string => date !== undefined),
291 ),
292 )
293 }
294 const mini = clause?.[2]
295 if (mini) out.set('gpt-4o-mini', new Set([mini]))
296 return out
298​
299const MATRIX_CAPABILITIES: Array<[RegExp, Array<string>]> = [
300 [/^functions\/tools/i, ['tools']],
301 [/^structured outputs/i, ['structured_outputs', 'response_format']],
303​
304function modalityWords(cell: string): Array<string> {
305 return ['text', 'image'].filter((word) => cell.toLowerCase().includes(word))
307​
308/** The `Feature` matrices of the reasoning article, by model id. */
309export function parseAzureFeatureMatrix(
310 markdown: string,
311): Map<string, AzureFeatureColumn> {
312 const out = new Map<string, AzureFeatureColumn>()
313 let ids: Array<string | null> = []
314 for (const cells of markdownTableRows(markdown.replace(/\r/g, ''))) {
315 const label = plain(cells[0] ?? '')
316 .replace(/[*[\]`]|\^[^^]*\^/g, '')
317 .trim()
318 if (label === 'Feature') {
319 // `**gpt-5.4**,**2026-03-05**` → `gpt-5.4`. The plain
320 // `Feature | Description` table has no model columns.
321 ids = cells.map((cell, index) =>
322 index === 0 || !cell.startsWith('**')
323 ? null
324 : (cell.replace(/\*/g, '').split(',')[0]?.trim() ?? null),
325 )
326 for (const id of ids) {
327 if (!id || out.has(id)) continue
328 out.set(id, {
329 capabilities: [],
330 modalities: null,
331 chatCompletions: null,
332 responses: null,
333 effort: false,
334 effortIncludesNone: false,
335 developerMessages: null,
336 maxCompletionTokens: null,
337 })
338 }
339 continue
340 }
341 for (const [index, id] of ids.entries()) {
342 const column = id ? out.get(id) : undefined
343 const cell = cells[index]
344 if (!column || cell == null) continue
345 const yes = cell.startsWith('✅')
346 const caps = MATRIX_CAPABILITIES.find(([pattern]) => pattern.test(label))
347 if (/^reasoning effort/i.test(label)) {
348 if (yes) {
349 column.capabilities.push('reasoning')
350 column.effort = true
351 if (/including none/i.test(label)) column.effortIncludesNone = true
352 }
353 } else if (caps && yes) column.capabilities.push(...caps[1])
354 else if (/^developer messages/i.test(label)) {
355 column.developerMessages = yes
356 } else if (/^max_completion_tokens/i.test(label)) {
357 column.maxCompletionTokens = yes
358 } else if (/^image input/i.test(label)) {
359 column.modalities = {
360 input: yes ? ['text', 'image'] : ['text'],
361 output: column.modalities?.output ?? [],
362 }
363 } else if (/^input modalities/i.test(label)) {
364 column.modalities = {
365 input: modalityWords(cell),
366 output: column.modalities?.output ?? [],
367 }
368 } else if (/^output modalities/i.test(label)) {
369 column.modalities = {
370 input: column.modalities?.input ?? [],
371 output: modalityWords(cell),
372 }
373 } else if (/^chat completions api/i.test(label)) {
374 column.chatCompletions = yes
375 } else if (/^responses api/i.test(label)) {
376 column.responses = yes
377 }
378 }
379 }
380 return out
382​
383function docsSource(sourceUrl: string, sourceHash: string) {
384 return (path: string): FactSource => ({
385 derivation: 'docs-derived',
386 sourceUrl,
387 sourceHash,
388 path,
389 })
391​
392const EFFORT_ORDER = [
393 'none',
394 'minimal',
395 'low',
396 'medium',
397 'high',
398 'xhigh',
399 'max',
400] as const
401​
402/** Constraints the reasoning article states once for every matrix column. */
403export interface AzureEffortRules {
404 maxFamilies: Array<string>
405 /** `max` is stated for the Responses API. */
406 maxNeedsResponses: boolean
407 xhighFamilies: Array<string>
408 /** `minimal` is limited to the original GPT-5 ids, minus `minimalExcluded`. */
409 minimalOriginalGpt5: true
410 minimalExcluded: Array<string>
411 /** Footnote 7, plus a matrix label that says "including none". */
412 noneFamilies: Array<string>
413 /** An id the article says supports only one level. */
414 onlySupports: Array<{ id: string; level: string }>
416​
417function articleClause(text: string, label: string, pattern: RegExp): string {
418 const match = pattern.exec(text)
419 const clause = match?.[1]
420 if (!clause) {
421 throw new Error(`azure reasoning article: ${label} did not parse`)
422 }
423 return clause
425​
426function familyTokens(clause: string): Array<string> {
427 const tokens: Array<string> = []
428 for (const match of clause.matchAll(/`([^`]+)`|GPT-(\d[\d.]*)/g)) {
429 const token = (match[1] ?? `gpt-${match[2] ?? ''}`).toLowerCase()
430 if (token.startsWith('gpt-')) tokens.push(token)
431 }
432 return tokens
434​
435function requireTokens(clause: string, label: string): Array<string> {
436 const tokens = familyTokens(clause)
437 if (tokens.length === 0) {
438 throw new Error(`azure reasoning article: ${label} names no model`)
439 }
440 return tokens
442​
443/**
444 * The reasoning article's effort options and the clauses that restrict
445 * them. Throws when a clause the catalog depends on is missing, so a
446 * reshaped page cannot be read as "every model accepts every option".
447 */
448export function parseAzureEffortRules(markdown: string): AzureEffortRules {
449 const text = markdown.replace(/\r/g, '').replace(/\\([_*])/g, '$1')
450 articleClause(
451 text,
452 'effort options',
453 /\*\*Options \(model-dependent\)\*\*:\s*(`none`,\s*`minimal`,\s*`low`,\s*`medium`,\s*`high`,\s*`xhigh`,\s*`max`)/,
454 )
455 const maxClause = articleClause(
456 text,
457 'max clause',
458 /`max` works only with (.+?)\. `xhigh`/,
459 )
460 if (!/Responses API/i.test(maxClause)) {
461 throw new Error(
462 'azure reasoning article: max clause does not name the Responses API',
463 )
464 }
465 const xhighClause = articleClause(
466 text,
467 'xhigh clause',
468 /`xhigh` works only with (.+?)\. `minimal`/,
469 )
470 if (
471 !/`minimal` works only with the original GPT-5 reasoning models/.test(
472 text,
473 ) ||
474 !/`minimal` doesn['’]t work with `gpt-5\.1` or greater/.test(text)
475 ) {
476 throw new Error('azure reasoning article: minimal clause did not parse')
477 }
478 const noneClause = articleClause(
479 text,
480 'none footnote',
481 /\^7\^((?:`[^`]+`(?:,\s*|,\s*and\s+|\s+and\s+)?)*)\s*support `'None'`/,
482 )
483 const minimalExcluded = [
484 ...text.matchAll(
485 /`([^`]+)` also does not support `reasoning_effort``minimal`/g,
486 ),
487 ]
488 .map((match) => match[1])
489 .filter((id): id is string => id !== undefined)
490 if (minimalExcluded.length === 0) {
491 throw new Error('azure reasoning article: minimal exclusion did not parse')
492 }
493 const onlySupports = [
494 ...text.matchAll(/`([^`]+)` only supports `reasoning_effort``([^`]+)`/g),
495 ].map((match) => ({ id: match[1] ?? '', level: match[2] ?? '' }))
496 if (
497 onlySupports.length === 0 ||
498 onlySupports.some(
499 (item) =>
500 item.id === '' ||
501 !(EFFORT_ORDER as ReadonlyArray<string>).includes(item.level),
502 )
503 ) {
504 throw new Error(
505 'azure reasoning article: only-supports clause did not parse',
506 )
507 }
508 return {
509 maxFamilies: requireTokens(maxClause, 'max clause'),
510 maxNeedsResponses: true,
511 xhighFamilies: requireTokens(xhighClause, 'xhigh clause'),
512 minimalOriginalGpt5: true,
513 minimalExcluded,
514 noneFamilies: requireTokens(noneClause, 'none footnote'),
515 onlySupports,
516 }
518​
519function familyHits(
520 tokens: Array<string>,
521 id: string,
522 columnIds: ReadonlySet<string>,
523): boolean {
524 return tokens.some((token) => {
525 if (token === id) return true
526 // A token that is itself a matrix column (`gpt-5.4`) does not cover
527 // `gpt-5.4-mini`. A family token (`gpt-5.6`, `gpt-6`) does.
528 if (columnIds.has(token)) return false
529 return id.startsWith(`${token}-`) || id.startsWith(`${token}.`)
530 })
532​
533/** `gpt-5`, `gpt-5-mini`, `gpt-5-nano`: not a dotted release such as 5.1. */
534function originalGpt5(id: string): boolean {
535 return id === 'gpt-5' || (/^gpt-5-[a-z]/.test(id) && !id.includes('.'))
537​
538function levelMap(efforts: Array<string>): EffortLevelMap {
539 const has = (level: string) => efforts.includes(level)
540 return {
541 off: has('none') ? 'none' : null,
542 minimal: has('minimal') ? 'minimal' : null,
543 low: has('low') ? 'low' : null,
544 medium: has('medium') ? 'medium' : null,
545 high: has('high') ? 'high' : null,
546 xhigh: has('xhigh') ? 'xhigh' : null,
547 max: has('max') ? 'max' : null,
548 }
550​
551function effortReasoning(
552 row: AzureModelRow,
553 column: AzureFeatureColumn,
554 rules: AzureEffortRules,
555 columnIds: ReadonlySet<string>,
556): ModelReasoning {
557 const id = row.rawId
558 const only = rules.onlySupports.find((item) => item.id === id)
559 let efforts: Array<string>
560 let mandatory: boolean | null
561 if (only) {
562 efforts = [only.level]
563 mandatory = true
564 } else {
565 const picked = new Set<string>(['low', 'medium', 'high'])
566 if (
567 column.effortIncludesNone ||
568 familyHits(rules.noneFamilies, id, columnIds)
569 ) {
570 picked.add('none')
571 }
572 if (originalGpt5(id) && !rules.minimalExcluded.includes(id)) {
573 picked.add('minimal')
574 }
575 if (familyHits(rules.xhighFamilies, id, columnIds)) picked.add('xhigh')
576 const responses = column.responses ?? row.responses
577 if (
578 familyHits(rules.maxFamilies, id, columnIds) &&
579 (!rules.maxNeedsResponses || responses)
580 ) {
581 picked.add('max')
582 }
583 if (row.noneExcluded) picked.delete('none')
584 efforts = EFFORT_ORDER.filter((level) => picked.has(level))
585 if (efforts.includes('none')) mandatory = false
586 else if (row.noneExcluded) mandatory = true
587 else mandatory = null
588 }
589 if (efforts.length === 0) {
590 throw new Error(`azure: ${id} effort list parsed empty`)
591 }
592 return { mode: 'effort', mandatory, efforts }
594​
595function azureRequestMap(
596 row: AzureModelRow,
597 column: AzureFeatureColumn | undefined,
598 reasoning: ModelReasoning | undefined,
599 chatMaxTokens: 'max_completion_tokens' | null,
600): ChatRequestMap | null {
601 const efforts = reasoning?.efforts ?? []
602 const chat = column?.chatCompletions ?? row.chatCompletions
603 let maxTokensField: ChatRequestMap['maxTokensField'] = null
604 if (chat && column?.maxCompletionTokens !== false) {
605 if (column?.maxCompletionTokens === true || chatMaxTokens !== null) {
606 maxTokensField = 'max_completion_tokens'
607 }
608 }
609 const developerRole =
610 column?.developerMessages === true
611 ? true
612 : column?.developerMessages === false
613 ? false
614 : null
615 const reasoningEffort = reasoning
616 ? true
617 : row.fixedReasoningEffort
618 ? false
619 : null
620 const onLevel = efforts.includes('high') ? 'high' : efforts.at(-1)
621 const thinking =
622 reasoning && onLevel
623 ? {
624 on: { reasoning_effort: onLevel },
625 off: efforts.includes('none') ? { reasoning_effort: 'none' } : null,
626 levels: levelMap(efforts),
627 }
628 : null
629 if (
630 thinking === null &&
631 maxTokensField === null &&
632 developerRole === null &&
633 reasoningEffort === null
634 ) {
635 return null
636 }
637 return {
638 thinking,
639 maxTokensField,
640 developerRole,
641 replayReasoningContent: null,
642 store: null,
643 strictTools: null,
644 sessionAffinity: null,
645 cacheControl: null,
646 toolStream: null,
647 reasoningEffort,
648 }
650​
651function isRecord(value: unknown): value is Record<string, unknown> {
652 return typeof value === 'object' && value !== null && !Array.isArray(value)
654​
655/** First object under `node` whose properties include the chat token fields. */
656function findChatBody(node: unknown): Record<string, unknown> | null {
657 if (!isRecord(node)) return null
658 const props = node.properties
659 if (
660 isRecord(props) &&
661 'max_completion_tokens' in props &&
662 'max_tokens' in props &&
663 'messages' in props
664 ) {
665 return props
666 }
667 for (const value of Object.values(node)) {
668 const found = findChatBody(value)
669 if (found) return found
670 }
671 return null
673​
674/**
675 * The chat completions body deprecates `max_tokens` in favor of
676 * `max_completion_tokens`. Throws when that statement is absent.
677 */
678export function azureChatMaxTokensField(
679 spec: unknown,
680): 'max_completion_tokens' {
681 const paths = isRecord(spec) ? spec.paths : undefined
682 const chat = isRecord(paths) ? paths['/chat/completions'] : undefined
683 const props = findChatBody(chat)
684 const maxTokens = props ? props.max_tokens : undefined
685 const description = isRecord(maxTokens) ? maxTokens.description : undefined
686 if (
687 typeof description === 'string' &&
688 /deprecated in favor of `max_completion_tokens`/i.test(description)
689 ) {
690 return 'max_completion_tokens'
691 }
692 throw new Error(
693 'azure spec: chat body does not deprecate max_tokens in favor of max_completion_tokens',
694 )
696​
697/**
698 * One catalog row. Where the model has a matrix column, it wins over the
699 * models article for capabilities, stated modalities, and the API served.
700 * `facts` carries the effort rules and the chat spec's max-token field;
701 * without it, reasoning and the request map stay unset.
702 */
703export function azureModelInfo(
704 row: AzureModelRow,
705 column: AzureFeatureColumn | undefined,
706 hashes: { models: string; reasoning: string },
707 facts?: {
708 rules: AzureEffortRules
709 columnIds: ReadonlySet<string>
710 chatMaxTokens: 'max_completion_tokens' | null
711 },
712): ModelInfo {
713 const models = docsSource(AZURE_MODELS_URL, hashes.models)
714 const matrix = docsSource(AZURE_REASONING_URL, hashes.reasoning)
715 const chat = row.activity === 'chat'
716​
717 const capabilities = chat
718 ? [...new Set([...(column?.capabilities ?? []), ...row.capabilities])]
719 : []
720 // Each side from whichever source states it: the GPT-5 matrix has an
721 // image-input row and no output row.
722 const fromMatrix = (column?.modalities?.input.length ?? 0) > 0
723 const input = fromMatrix ? column?.modalities?.input : row.modalities?.input
724 const output = column?.modalities?.output.length
725 ? column.modalities.output
726 : (row.modalities?.output ?? [])
727 const modalities = input ? { input, output } : null
728 const chatCompletions = column?.chatCompletions ?? row.chatCompletions
729 const responses = column?.responses ?? row.responses
730​
731 const factSources: ModelFactSources = {}
732 if (row.contextWindow != null) {
733 factSources.contextWindow = models('contextWindow')
734 }
735 if (row.maxOutput != null) factSources.maxOutput = models('maxOutput')
736 if (modalities) {
737 factSources.modalities = (fromMatrix ? matrix : models)('modalities')
738 } else if (chat) {
739 factSources.modalities = models(MODALITIES_SOURCE_SILENT)
740 }
741 if (capabilities.length > 0) {
742 factSources.capabilities = Object.fromEntries(
743 capabilities.map((flag) => [
744 flag,
745 (column?.capabilities.includes(flag) ? matrix : models)(
746 `capabilities.${flag}`,
747 ),
748 ]),
749 )
750 }
751​
752 const reasoning =
753 facts && column?.effort && !row.fixedReasoningEffort
754 ? effortReasoning(row, column, facts.rules, facts.columnIds)
755 : undefined
756 if (reasoning) factSources.reasoning = matrix('reasoning_effort')
757 const requestMap = facts
758 ? azureRequestMap(row, column, reasoning, facts.chatMaxTokens)
759 : undefined
760​
761 return {
762 rawId: row.rawId,
763 activity: row.activity,
764 contextWindow: row.contextWindow,
765 maxOutput: row.maxOutput,
766 modalities,
767 capabilities: capabilities.length > 0 ? capabilities : null,
768 // A chat model that serves only the Responses API binds to that route.
769 schemaEndpointId: !chat
770 ? null
771 : chatCompletions
772 ? 'chat/completions'
773 : responses
774 ? 'responses'
775 : null,
776 deprecated: row.retired,
777 pricing: null,
778 ...(reasoning ? { reasoning } : {}),
779 ...(requestMap ? { requestMap } : {}),
780 factSources,
781 }