Open History to see the last commit
1import { afterEach, describe, expect, it } from 'vitest'
2
3import { AZURE_MODELS_URL, AZURE_REASONING_URL } from '../azure-models.ts'
4import { AZURE_PRICES_URL, AZURE_PRICING_PAGE_URL } from '../azure-pricing.ts'
5import { AZURE_SPEC_URL, provider } from './azure.ts'
6
7/** Excerpts of the two Learn articles' markdown twins (2026-10-06). */
8const MODELS = `::: zone pivot="azure-openai"
9
10## O-Series models
11
12| Model ID | Description | Max request (tokens) | Training data (up to) |
13| --- | --- | --- | --- |
14\`o3-deep-research\` is only available with Foundry Agent Service. The \`o9\` family is not a model.
15
16| \`o3\` (2025-04-16) | - Chat Completions API. - Structured outputs. - Text and image processing. - Functions, tools, and parallel tool calling. | Input: 200,000 Output: 100,000 | May 31, 2024 |
17
18## Image generation models
19
20| Model ID | Max request (characters) |
21| --- | --- |
22| \`gpt-image-2\` | 4,000 |
23
24::: zone-end
25`
26
27const REASONING = [
28 '| **Feature** | **o3**,**2025-04-16** |',
29 '| --- | --- |',
30 '| **Reasoning effort** | ✅ |',
31 '| Chat Completions API | ✅ |',
32 '',
33 "`max` works only with GPT-6 or GPT-5.6 models and the Responses API. `xhigh` works only with GPT-6, GPT-5.6, GPT-5.5, GPT-5.4, and `gpt-5.1-codex-max` models. `minimal` works only with the original GPT-5 reasoning models. `minimal` doesn't work with `gpt-5.1` or greater. **Options (model-dependent)**: `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`",
34 '^5^`gpt-5-pro` only supports `reasoning_effort``high`, this is the default value even when not explicitly passed to the model.',
35 "^7^`gpt-5.6`, `gpt-5.5`, `gpt-5.4`, `gpt-5.2`, `gpt-5.1`, `gpt-5.1-codex`, `gpt-5.1-codex-max`, and `gpt-5.1-codex-mini` support `'None'` as a value for the `reasoning_effort` parameter.",
36 '^\\*^`gpt-5-codex` also does not support `reasoning_effort``minimal`.',
37].join('\n')
38
39const CHAT_SPEC = {
40 openapi: '3.2.0',
41 paths: {
42 '/chat/completions': {
43 post: {
44 requestBody: {
45 content: {
46 'application/json': {
47 schema: {
48 properties: {
49 messages: { type: 'array' },
50 max_completion_tokens: { type: 'integer' },
51 max_tokens: {
52 description:
53 'This value is now deprecated in favor of `max_completion_tokens`, and is not compatible with o1 series models.',
54 },
55 },
56 },
57 },
58 },
59 },
60 },
61 },
62 },
63}
64
65const PAGE_TWO = 'https://prices.azure.com/api/retail/prices?page=2'
66const PRICES: Record<string, unknown> = {
67 [AZURE_PRICES_URL]: {
68 Items: [
69 { skuName: 'o3 0416 Inp glbl', unitOfMeasure: '1K', retailPrice: 0.002 },
70 ],
71 NextPageLink: PAGE_TWO,
72 },
73 [PAGE_TWO]: {
74 Items: [
75 { skuName: 'o3 0416 Outp glbl', unitOfMeasure: '1K', retailPrice: 0.008 },
76 {
77 skuName: 'o3-deep research 0626-inp-glbl',
78 unitOfMeasure: '1M',
79 retailPrice: 10,
80 },
81 ],
82 NextPageLink: null,
83 },
84}
85const PRICING_PAGE =
86 '<td>GPT-5.4 (<272k context length)</td><td>GPT-5.4 (>272k context length)</td>'
87
88const originalFetch = globalThis.fetch
89
90afterEach(() => {
91 globalThis.fetch = originalFetch
92})
93
94function stubFetch(
95 models: string,
96 urls: Array<string> = [],
97 pricingPage = PRICING_PAGE,
98 reasoning = REASONING,
99 prices: Record<string, unknown> | 'throttle-page-2' = PRICES,
100) {
101 globalThis.fetch = ((input: string, init?: RequestInit) => {
102 const url = String(input)
103 urls.push(url)
104 if (url === AZURE_MODELS_URL || url === AZURE_REASONING_URL) {
105 expect(new Headers(init?.headers).get('Accept')).toBe('text/markdown')
106 return Promise.resolve(
107 new Response(url === AZURE_MODELS_URL ? models : reasoning),
108 )
109 }
110 if (prices === 'throttle-page-2' && url === PAGE_TWO) {
111 return Promise.resolve(
112 new Response('Too many requests at this point. Please retry later.', {
113 status: 429,
114 statusText: 'Too Many Requests',
115 }),
116 )
117 }
118 const priceDoc = prices === 'throttle-page-2' ? PRICES : prices
119 if (url in priceDoc) return Promise.resolve(Response.json(priceDoc[url]))
120 if (url === AZURE_PRICING_PAGE_URL) {
121 return Promise.resolve(new Response(pricingPage))
122 }
123 if (url === AZURE_SPEC_URL) {
124 return Promise.resolve(Response.json(CHAT_SPEC))
125 }
126 return Promise.reject(new Error(`unexpected fetch: ${url}`))
127 }) as typeof fetch
128}
129
130describe('azure', () => {
131 it('lists the tabulated models with facts, price, and sources', async () => {
132 stubFetch(MODELS)
133 const { models, docsFailures } = await provider.listModels({})
134
135 expect(models.map((model) => [model.rawId, model.activity])).toEqual([
136 ['o3', 'chat'],
137 ['gpt-image-2', 'image'],
138 // Named in prose and metered: kept, with no facts. `o9` is dropped.
139 ['o3-deep-research', null],
140 ])
141 const o3 = models[0]
142 expect(o3).toMatchObject({
143 contextWindow: 200_000,
144 maxOutput: 100_000,
145 modalities: { input: ['text', 'image'], output: null },
146 capabilities: [
147 'reasoning',
148 'tools',
149 'structured_outputs',
150 'response_format',
151 ],
152 schemaEndpointId: 'chat/completions',
153 reasoning: {
154 mode: 'effort',
155 mandatory: null,
156 efforts: ['low', 'medium', 'high'],
157 },
158 requestMap: {
159 thinking: {
160 on: { reasoning_effort: 'high' },
161 off: null,
162 },
163 maxTokensField: 'max_completion_tokens',
164 reasoningEffort: true,
165 },
166 pricing: {
167 tables: { rate: { base: { input_tokens: 2e-6, output_tokens: 8e-6 } } },
168 },
169 })
170 expect(o3?.factSources?.pricing?.sourceUrl).toBe(AZURE_PRICES_URL)
171 expect(o3?.factSources?.maxOutput?.sourceUrl).toBe(AZURE_MODELS_URL)
172 expect(models[1]?.pricing).toBeNull()
173 expect(docsFailures).toEqual({ failed: 0, skipped: 0, first: [] })
174 })
175
176 it('keeps the poll when a later retail prices page is throttled', async () => {
177 stubFetch(MODELS, [], PRICING_PAGE, REASONING, 'throttle-page-2')
178 const { models, docsFailures } = await provider.listModels({})
179
180 expect(models.map((model) => model.rawId)).toEqual(['o3', 'gpt-image-2'])
181 expect(models[0]).toMatchObject({
182 contextWindow: 200_000,
183 reasoning: {
184 mode: 'effort',
185 mandatory: null,
186 efforts: ['low', 'medium', 'high'],
187 },
188 absent: { pricing: 'unavailable' },
189 })
190 expect(models[0]?.pricing).toBeNull()
191 expect(docsFailures).toMatchObject({ failed: 1, skipped: 0 })
192 expect(docsFailures?.first).toHaveLength(1)
193 expect(docsFailures?.first[0]?.source).toBe(AZURE_PRICES_URL)
194 expect(docsFailures?.first[0]?.error).toContain(
195 `${PAGE_TWO} → 429 Too Many Requests`,
196 )
197 })
198
199 it('reports a docs failure when the pricing page labels no threshold', async () => {
200 stubFetch(MODELS, [], '<td>GPT-5.4 Global</td>')
201 const { models, docsFailures } = await provider.listModels({})
202
203 expect(models.map((model) => model.rawId)).toEqual(['o3', 'gpt-image-2'])
204 expect(models[0]?.absent).toEqual({ pricing: 'unavailable' })
205 expect(docsFailures?.first[0]?.error).toContain(
206 'labels no context-length threshold',
207 )
208 })
209
210 it('throws when the reasoning article states no effort rules', async () => {
211 stubFetch(
212 MODELS,
213 [],
214 PRICING_PAGE,
215 '| **Feature** | **o3** |\n| --- |\n| **Reasoning effort** | ✅ |\n',
216 )
217 await expect(provider.listModels({})).rejects.toThrow(
218 'effort options did not parse',
219 )
220 })
221
222 it('throws when the models article tabulates nothing', async () => {
223 stubFetch('::: zone pivot="azure-openai"\n\nNo tables.\n')
224 await expect(provider.listModels({})).rejects.toThrow('parsed 0 model rows')
225 })
226
227 it("fetches Azure's own v1 spec and classifies its chat routes", async () => {
228 const urls: Array<string> = []
229 stubFetch(MODELS, urls)
230 const spec = await provider.fetchSpec({})
231
232 expect(urls).toEqual([AZURE_SPEC_URL])
233 expect(spec.sources[0]?.url).toBe(AZURE_SPEC_URL)
234 expect(spec.specRevision).toBe(spec.sources[0]?.hash)
235 expect(provider.classify('/responses', {})).toBe('chat')
236 expect(provider.classify('/fine_tuning/jobs', {})).toBeNull()
237 })
238})